Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private Stat pathInForeground(string path, byte[] data)
        {
            TimeTrace trace      = client.getZookeeperClient().startTracer("SetDataBuilderImpl-Foreground");
            Stat      resultStat = RetryLoop.callWithRetry
                                   (
                client.getZookeeperClient(),
                CallableUtils.FromFunc(() =>
            {
                Task <Stat> task = client.getZooKeeper().setDataAsync(path, data, version);
                task.Wait();
                return(task.Result);
            })
                                   );

            trace.commit();
            return(resultStat);
        }
Exemplo n.º 3
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);
        }