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 Backgrounding backgrounding;
     private Watching watching;
 
     {
         this. = client;
          = new Backgrounding();
          = new Watching();
     }
 
     @Override
     public BackgroundPathable<Statwatched()
     {
          = new Watching(true);
         return this;
     }
 
     @Override
     public BackgroundPathable<StatusingWatcher(Watcher watcher)
     {
          = new Watching(watcher);
         return this;
     }
 
     @Override
     public Pathable<StatinBackground(BackgroundCallback callback)
     {
          = new Backgrounding(callback);
         return this;
     }
 
     @Override
     public Pathable<StatinBackground(BackgroundCallback callbackExecutor executor)
     {
          = new Backgrounding(callbackexecutor);
         return this;
     }
 
     @Override
     public Pathable<StatinBackground()
     {
          = new Backgrounding(true);
         return this;
     }
 
     @Override
     public Pathable<StatinBackground(Object context)
     {
          = new Backgrounding(context);
         return this;
     }
 
     @Override
     public void performBackgroundOperation(final OperationAndData<StringoperationAndDatathrows Exception
     {
         final TimeTrace   trace = .getZookeeperClient().startTracer("ExistsBuilderImpl-Background");
         AsyncCallback.StatCallback callback = new AsyncCallback.StatCallback()
         {
             @Override
             public void processResult(int rcString pathObject ctxStat stat)
             {
                 trace.commit();
                 CuratorEvent event = new CuratorEventImpl(.rcpathnullctxstatnullnullnullnull);
                .processBackgroundOperation(operationAndDataevent);
            }
        };
        if ( .isWatched() )
        {
            .getZooKeeper().exists(operationAndData.getData(), truecallback.getContext());
        }
        else
        {
            .getZooKeeper().exists(operationAndData.getData(), .getWatcher(), callback.getContext());
        }
    }
    @Override
    public Stat forPath(String paththrows Exception
    {
        path = .fixForNamespace(path);
        Stat        returnStat = null;
        if ( .inBackground() )
        {
            .processBackgroundOperation(new OperationAndData<String>(thispath.getCallback(), null), null);
        }
        else
        {
            returnStat = pathInForeground(path);
        }
        return returnStat;
    }
    private Stat pathInForeground(final String paththrows Exception
    {
        TimeTrace   trace = .getZookeeperClient().startTracer("ExistsBuilderImpl-Foreground");
        Stat        returnStat = RetryLoop.callWithRetry
        (
            .getZookeeperClient(),
            new Callable<Stat>()
            {
                @Override
                public Stat call() throws Exception
                {
                    Stat    returnStat;
                    if ( .isWatched()  )
                    {
                        returnStat = .getZooKeeper().exists(pathtrue);
                    }
                    else
                    {
                        returnStat = .getZooKeeper().exists(path.getWatcher());
                    }
                    return returnStat;
                }
            }
        );
        trace.commit();
        return returnStat;
    }
New to GrepCode? Check out our FAQ X