Beispiel #1
0
        public void performBackgroundOperation(OperationAndData <PathAndBytes> operationAndData)
        {
            try
            {
                TimeTrace   trace   = client.getZookeeperClient().startTracer("SetDataBuilderImpl-Background");
                object      taskCtx = backgrounding.getContext();
                Task <Stat> task    = client.getZooKeeper().setDataAsync
                                      (
                    operationAndData.getData().getPath(),
                    operationAndData.getData().getData(),
                    version //,
//                     new AsyncCallback.StatCallback()
//                     {
//                         public void processResult(int rc, String path, Object ctx, Stat stat)
//                         {
//                             trace.commit();
//                             ICuratorEvent @event = new CuratorEventImpl(client, CuratorEventType.SET_DATA, rc, path, null, ctx, stat, null, null, null, null);
//                             client.processBackgroundOperation(operationAndData, @event);
//                         };
//                    },
//                    backgrounding.getContext()
                                      );
                task.ContinueWith(statTask =>
                {
                    trace.commit();
                    int errorCode = 0;
                    if (statTask.IsFaulted)
                    {
                        if (!(statTask.Exception.InnerException is KeeperException))
                        {
                            throw new Exception($"{nameof(SetDataBuilderImpl)}." +
                                                $"{nameof(performBackgroundOperation)} operation failed " +
                                                $"with unexpected exception of type " +
                                                $"{statTask.Exception.InnerException.GetType().FullName}." +
                                                $"Expected type {nameof(KeeperException)}");
                        }
                        KeeperException keeperException
                                  = (KeeperException)statTask.Exception.InnerException;
                        errorCode = (int)keeperException.getCode();
                    }
                    ICuratorEvent @event = new CuratorEventImpl(client,
                                                                CuratorEventType.SET_DATA,
                                                                errorCode,
                                                                operationAndData.getData().getPath(),
                                                                null,
                                                                taskCtx,
                                                                statTask.Result,
                                                                null,
                                                                null,
                                                                null,
                                                                null);
                    client.processBackgroundOperation(operationAndData, @event);
                });
            }
            catch (Exception e)
            {
                backgrounding.checkError(e);
            }
        }
 public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace    = client.getZookeeperClient().startTracer("GetChildrenBuilderImpl-Background");
         var       callback = new AsyncCallback.Children2Callback()
         {
Beispiel #3
0
        public ICollection <CuratorTransactionResult> commit()
        {
            CheckAlreadyCommited();
            isCommitted = true;

            AtomicBoolean   firstTime  = new AtomicBoolean(true);
            List <OpResult> resultList = RetryLoop.callWithRetry
                                         (
                client.getZookeeperClient(),
                CallableUtils.FromFunc(() => doOperation(firstTime)));

            if (resultList.Count != transaction.metadataSize())
            {
                throw new InvalidOperationException(String.Format("Result size ({0}) doesn't match input size ({1})",
                                                                  resultList.Count,
                                                                  transaction.metadataSize()));
            }

            var builder = new ReadOnlyCollectionBuilder <CuratorTransactionResult>();

            for (int i = 0; i < resultList.Count; ++i)
            {
                OpResult opResult = resultList[i];
                CuratorMultiTransactionRecord.TypeAndPath metadata = transaction.getMetadata(i);
                CuratorTransactionResult curatorResult             = makeCuratorResult(opResult, metadata);
                builder.Add(curatorResult);
            }

            return(builder.ToReadOnlyCollection());
        }
Beispiel #4
0
        internal String fixForNamespace(String path, bool isSequential)
        {
            if (ensurePathNeeded.get())
            {
                try
                {
                    CuratorZookeeperClient zookeeperClient = client.getZookeeperClient();
                    RetryLoop.callWithRetry
                    (
                        zookeeperClient,
                        CallableUtils.FromFunc <object>(() =>
                    {
                        ZKPaths.mkdirs(zookeeperClient.getZooKeeper(),
                                       ZKPaths.makePath("/", @namespace),
                                       true,
                                       client.getAclProvider(),
                                       true);
                        return(null);
                    })
                    );
                    ensurePathNeeded.set(false);
                }
                catch (Exception e)
                {
                    ThreadUtils.checkInterrupted(e);
                    client.logError("Ensure path threw exception", e);
                }
            }

            return(ZKPaths.fixForNamespace(@namespace, path, isSequential));
        }
Beispiel #5
0
 public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
         AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
         {
             @Override
        public void performBackgroundOperation(OperationAndData <String> operationAndData)
        {
            TimeTrace trace = client.getZookeeperClient().startTracer("BackgroundSyncImpl");

            client.getZooKeeper().sync
            (
                operationAndData.getData(),
                new AsyncCallback.VoidCallback()
            {
                @Override
Beispiel #7
0
        public void performBackgroundOperation(OperationAndData <String> operationAndData)
        {
            try
            {
                TimeTrace trace        = client.getZookeeperClient().startTracer("SyncBuilderImpl-Background");
                String    path         = operationAndData.getData();
                String    adjustedPath = client.fixForNamespace(path);

                AsyncCallback.VoidCallback voidCallback = new AsyncCallback.VoidCallback()
                {
Beispiel #8
0
 public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("DeleteBuilderImpl-Background");
         client.getZooKeeper().delete
         (
             operationAndData.getData(),
             version,
             new AsyncCallback.VoidCallback()
         {
             @Override
 public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("SetACLBuilderImpl-Background");
         String    path  = operationAndData.getData();
         client.getZooKeeper().setACL
         (
             path,
             acling.getAclList(path),
             version,
             new AsyncCallback.StatCallback()
         {
 public void performBackgroundOperation(OperationAndData <PathAndBytes> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("CreateBuilderImpl-Background");
         client.getZooKeeper().create
         (
             operationAndData.getData().getPath(),
             operationAndData.getData().getData(),
             acling.getAclList(operationAndData.getData().getPath()),
             createMode,
             new AsyncCallback.StringCallback()
         {
             @Override
Beispiel #11
0
        public byte[] forPath(String path)
        {
            String localPath = client.fixForNamespace(path);

            TimeTrace trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Foreground");

            byte[]
            responseData = RetryLoop.callWithRetry
                           (
                client.getZookeeperClient(),
                CallableUtils.FromFunc(() =>
            {
                var dataAsync = client.getZooKeeper().getDataAsync(localPath, false);
                dataAsync.Wait();
                responseStat = dataAsync.Result.Stat;
                return(dataAsync.Result.Data);
            })
                           );
            trace.commit();

            return(decompress
                    ? client.getCompressionProvider().decompress(path, responseData)
                    : responseData);
        }
Beispiel #12
0
 public CuratorZookeeperClient getZookeeperClient()
 {
     return(client.getZookeeperClient());
 }