Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *
   *  Copyright 2011 Netflix, Inc.
   *
   *     Licensed under the Apache License, Version 2.0 (the "License");
   *     you may not use this file except in compliance with the License.
   *     You may obtain a copy of the License at
   *
   *         http://www.apache.org/licenses/LICENSE-2.0
  *
  *     Unless required by applicable law or agreed to in writing, software
  *     distributed under the License is distributed on an "AS IS" BASIS,
  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *     See the License for the specific language governing permissions and
  *     limitations under the License.
  *
  */
 package com.netflix.curator.framework.imps;
 
 
 {
     private final CuratorFrameworkImpl client;
     private Stat                                      responseStat;
     private Watching watching;
     private Backgrounding backgrounding;
 
     {
         this. = client;
          = null;
          = new Watching();
          = new Backgrounding();
     }
 
     @Override
     public WatchPathable<byte[]> storingStatIn(Stat stat)
     {
         this. = stat;
         return new WatchPathable<byte[]>()
         {
             @Override
             public byte[] forPath(String paththrows Exception
             {
                 return GetDataBuilderImpl.this.forPath(path);
             }
 
             @Override
             public Pathable<byte[]> watched()
             {
                 GetDataBuilderImpl.this.watched();
                 return GetDataBuilderImpl.this;
             }
 
             @Override
             public Pathable<byte[]> usingWatcher(Watcher watcher)
             {
                 GetDataBuilderImpl.this.usingWatcher(watcher);
                 return GetDataBuilderImpl.this;
             }
         };
     }
 
     @Override
     public Pathable<byte[]> inBackground(BackgroundCallback callback)
     {
          = new Backgrounding(callback);
         return this;
     }
 
     @Override
     public Pathable<byte[]> inBackground(BackgroundCallback callbackExecutor executor)
     {
          = new Backgrounding(callbackexecutor);
         return this;
     }
 
     @Override
     public Pathable<byte[]> inBackground()
     {
          = new Backgrounding(true);
         return this;
     }
 
     @Override
    public Pathable<byte[]> inBackground(Object context)
    {
         = new Backgrounding(context);
        return this;
    }
    @Override
    public BackgroundPathable<byte[]> watched()
    {
         = new Watching(true);
        return this;
    }
    @Override
    public BackgroundPathable<byte[]> usingWatcher(Watcher watcher)
    {
         = new Watching(watcher);
        return this;
    }
    @Override
    public void performBackgroundOperation(final OperationAndData<StringoperationAndDatathrows Exception
    {
        final TimeTrace   trace = .getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
        AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
        {
            @Override
            public void processResult(int rcString pathObject ctxbyte[] dataStat stat)
            {
                trace.commit();
                CuratorEvent event = new CuratorEventImpl(.rcpathnullctxstatdatanullnullnull);
                .processBackgroundOperation(operationAndDataevent);
            }
        };
        if ( .isWatched() )
        {
            .getZooKeeper().getData(operationAndData.getData(), truecallback.getContext());
        }
        else
        {
            .getZooKeeper().getData(operationAndData.getData(), .getWatcher(), callback.getContext());
        }
    }
    @Override
    public byte[] forPath(String paththrows Exception
    {
        path = .fixForNamespace(path);
        byte[]      responseData = null;
        if ( .inBackground() )
        {
            .processBackgroundOperation(new OperationAndData<String>(thispath.getCallback(), null), null);
        }
        else
        {
            responseData = pathInForeground(path);
        }
        return responseData;
    }
    private byte[] pathInForeground(final String paththrows Exception
    {
        TimeTrace   trace = .getZookeeperClient().startTracer("GetDataBuilderImpl-Foreground");
        byte[]      responseData = RetryLoop.callWithRetry
        (
            .getZookeeperClient(),
            new Callable<byte[]>()
            {
                @Override
                public byte[] call() throws Exception
                {
                    byte[]      responseData;
                    if ( .isWatched() )
                    {
                        responseData = .getZooKeeper().getData(pathtrue);
                    }
                    else
                    {
                        responseData = .getZooKeeper().getData(path.getWatcher(), );
                    }
                    return responseData;
                }
            }
        );
        trace.commit();
        return responseData;
    }
New to GrepCode? Check out our FAQ X