本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}