當前位置: 首頁>>代碼示例>>Java>>正文


Java OperationFuture類代碼示例

本文整理匯總了Java中org.apache.twill.zookeeper.OperationFuture的典型用法代碼示例。如果您正苦於以下問題:Java OperationFuture類的具體用法?Java OperationFuture怎麽用?Java OperationFuture使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OperationFuture類屬於org.apache.twill.zookeeper包,在下文中一共展示了OperationFuture類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<String> create(final String path, @Nullable final byte[] data, final CreateMode createMode,
                                      final boolean createParent, final Iterable<ACL> acl) {
  // No retry for any SEQUENTIAL node, as some algorithms depends on only one sequential node being created.
  if (createMode == CreateMode.PERSISTENT_SEQUENTIAL || createMode == CreateMode.EPHEMERAL_SEQUENTIAL) {
    return super.create(path, data, createMode, createParent, acl);
  }

  final SettableOperationFuture<String> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.create(path, data, createMode, createParent, acl),
                      new OperationFutureCallback<String>(OperationType.CREATE, System.currentTimeMillis(),
                                                          path, result, new Supplier<OperationFuture<String>>() {
                        @Override
                        public OperationFuture<String> get() {
                          return FailureRetryZKClient.super.create(path, data, createMode, createParent, acl);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:20,代碼來源:FailureRetryZKClient.java

示例2: watchNode

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
/**
 * Starts watching for the max. of smaller node.
 */
private void watchNode(final String nodePath, Watcher watcher) {
  OperationFuture<NodeData> watchFuture = zkClient.getData(nodePath, watcher);
  Futures.addCallback(watchFuture, new FutureCallback<NodeData>() {
    @Override
    public void onSuccess(NodeData nodeData) {
      if (state != State.CANCELLED) {
        becomeFollower();
      }
    }

    @Override
    public void onFailure(Throwable t) {
      // On any kind of failure, just rerun the election.
      LOG.debug("Exception while setting watch on node {}. Retry.", nodePath, t);
      runElection();
    }
  }, executor);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:22,代碼來源:LeaderElection.java

示例3: watchNode

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
/**
 * Starts watching for the max. of smaller node.
 */
private void watchNode(final String nodePath, Watcher watcher) {
  OperationFuture<Stat> watchFuture = zkClient.exists(nodePath, watcher);
  Futures.addCallback(watchFuture, new FutureCallback<Stat>() {
    @Override
    public void onSuccess(Stat result) {
      if (state != State.CANCELLED) {
        becomeFollower();
      }
    }

    @Override
    public void onFailure(Throwable t) {
      LOG.warn("Exception while setting watch on node {}. Retry.", nodePath, t);
      runElection();
    }
  }, executor);
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:21,代碼來源:LeaderElection.java

示例4: getData

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<NodeData> getData(String path, Watcher watcher) {
  SettableOperationFuture<NodeData> result = SettableOperationFuture.create(path, eventExecutor);
  getZooKeeper().getData(path, wrapWatcher(watcher), Callbacks.DATA, result);

  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:8,代碼來源:DefaultZKClientService.java

示例5: relayFuture

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
private <V> OperationFuture<V> relayFuture(final OperationFuture<V> from, final SettableOperationFuture<V> to) {
  Futures.addCallback(from, new FutureCallback<V>() {
    @Override
    public void onSuccess(V result) {
      to.set(result);
    }

    @Override
    public void onFailure(Throwable t) {
      to.setException(t);
    }
  });
  return to;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:15,代碼來源:NamespaceZKClient.java

示例6: relayPath

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
private OperationFuture<String> relayPath(final OperationFuture<String> from,
                                          final SettableOperationFuture<String> to) {
  from.addListener(new Runnable() {
    @Override
    public void run() {
      try {
        String relativePath = from.get().substring(namespace.length());
        to.set(relativePath.isEmpty() ? "/" : relativePath);
      } catch (Exception e) {
        to.setException(e.getCause());
      }
    }
  }, Threads.SAME_THREAD_EXECUTOR);
  return to;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:16,代碼來源:NamespaceZKClient.java

示例7: exists

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<Stat> exists(final String path, final Watcher watcher) {
  final SettableOperationFuture<Stat> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.exists(path, watcher),
                      new OperationFutureCallback<Stat>(OperationType.EXISTS, System.currentTimeMillis(),
                                                        path, result, new Supplier<OperationFuture<Stat>>() {
                        @Override
                        public OperationFuture<Stat> get() {
                          return FailureRetryZKClient.super.exists(path, watcher);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:14,代碼來源:FailureRetryZKClient.java

示例8: getChildren

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<NodeChildren> getChildren(final String path, final Watcher watcher) {
  final SettableOperationFuture<NodeChildren> result = SettableOperationFuture.create(path,
                                                                                      Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.getChildren(path, watcher),
                      new OperationFutureCallback<NodeChildren>(OperationType.GET_CHILDREN,
                                                                System.currentTimeMillis(), path, result,
                                                                new Supplier<OperationFuture<NodeChildren>>() {
                        @Override
                        public OperationFuture<NodeChildren> get() {
                          return FailureRetryZKClient.super.getChildren(path, watcher);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:16,代碼來源:FailureRetryZKClient.java

示例9: getData

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<NodeData> getData(final String path, final Watcher watcher) {
  final SettableOperationFuture<NodeData> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.getData(path, watcher),
                      new OperationFutureCallback<NodeData>(OperationType.GET_DATA, System.currentTimeMillis(),
                                                            path, result, new Supplier<OperationFuture<NodeData>>() {
                        @Override
                        public OperationFuture<NodeData> get() {
                          return FailureRetryZKClient.super.getData(path, watcher);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:14,代碼來源:FailureRetryZKClient.java

示例10: setData

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<Stat> setData(final String dataPath, final byte[] data, final int version) {
  final SettableOperationFuture<Stat> result = SettableOperationFuture.create(dataPath, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.setData(dataPath, data, version),
                      new OperationFutureCallback<Stat>(OperationType.SET_DATA, System.currentTimeMillis(),
                                                        dataPath, result, new Supplier<OperationFuture<Stat>>() {
                        @Override
                        public OperationFuture<Stat> get() {
                          return FailureRetryZKClient.super.setData(dataPath, data, version);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:14,代碼來源:FailureRetryZKClient.java

示例11: delete

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<String> delete(final String deletePath, final int version) {
  final SettableOperationFuture<String> result = SettableOperationFuture.create(deletePath,
                                                                                Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.delete(deletePath, version),
                      new OperationFutureCallback<String>(OperationType.DELETE, System.currentTimeMillis(),
                                                          deletePath, result, new Supplier<OperationFuture<String>>
                        () {
                        @Override
                        public OperationFuture<String> get() {
                          return FailureRetryZKClient.super.delete(deletePath, version);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:16,代碼來源:FailureRetryZKClient.java

示例12: getACL

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<ACLData> getACL(final String path) {
  final SettableOperationFuture<ACLData> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.getACL(path),
                      new OperationFutureCallback<ACLData>(OperationType.GET_ACL, System.currentTimeMillis(),
                                                        path, result, new Supplier<OperationFuture<ACLData>>() {
                        @Override
                        public OperationFuture<ACLData> get() {
                          return FailureRetryZKClient.super.getACL(path);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:14,代碼來源:FailureRetryZKClient.java

示例13: setACL

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
@Override
public OperationFuture<Stat> setACL(final String path, final Iterable<ACL> acl, final int version) {
  final SettableOperationFuture<Stat> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.setACL(path, acl, version),
                      new OperationFutureCallback<Stat>(OperationType.SET_ACL, System.currentTimeMillis(),
                                                        path, result, new Supplier<OperationFuture<Stat>>() {
                        @Override
                        public OperationFuture<Stat> get() {
                          return FailureRetryZKClient.super.setACL(path, acl, version);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:14,代碼來源:FailureRetryZKClient.java

示例14: OperationFutureCallback

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
private OperationFutureCallback(OperationType type, long startTime, String path,
                                SettableOperationFuture<V> result, Supplier<OperationFuture<V>> retryAction) {
  this.type = type;
  this.startTime = startTime;
  this.path = path;
  this.result = result;
  this.retryAction = retryAction;
  this.failureCount = new AtomicInteger(0);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:10,代碼來源:FailureRetryZKClient.java

示例15: register

import org.apache.twill.zookeeper.OperationFuture; //導入依賴的package包/類
private void register() {
  state = State.IN_PROGRESS;
  zkNodePath = null;

  // Register for election
  final String path = String.format("%s/%s-", zkFolderPath, guid);
  LOG.debug("Registering for election {} with path {}", zkFolderPath, path);

  OperationFuture<String> createFuture = zkClient.create(path, getNodeData(), CreateMode.EPHEMERAL_SEQUENTIAL, true);
  Futures.addCallback(createFuture, new FutureCallback<String>() {

    @Override
    public void onSuccess(String result) {
      LOG.debug("Created zk node {}", result);
      zkNodePath = result;
      if (state == State.CANCELLED) {
        // If cancel was called after create(), but before callback trigger, delete the node created.
        deleteNode();
      } else {
        runElection();
      }
    }

    @Override
    public void onFailure(Throwable t) {
      LOG.error("Got exception during node creation for folder {}", path, t);
      // The node may created successfully on server and then server crash,
      // which client might receive failure instead.
      // Not checking for cancel here, as we don't know the zkNodePath.
      // Needs to rely on runElection to handle cancel.
      runElection();
    }
  }, executor);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:35,代碼來源:LeaderElection.java


注:本文中的org.apache.twill.zookeeper.OperationFuture類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。