本文整理汇总了Java中org.apache.curator.framework.recipes.barriers.DistributedBarrier类的典型用法代码示例。如果您正苦于以下问题:Java DistributedBarrier类的具体用法?Java DistributedBarrier怎么用?Java DistributedBarrier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DistributedBarrier类属于org.apache.curator.framework.recipes.barriers包,在下文中一共展示了DistributedBarrier类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.curator.framework.recipes.barriers.DistributedBarrier; //导入依赖的package包/类
private void init() throws Exception {
CuratorFramework curatorFramework = CuratorFrameworkFactory
.builder()
.connectString("localhost:2181")
.connectionTimeoutMs(3000)
.sessionTimeoutMs(5000)
.retryPolicy(new RetryNTimes(3, 2000))
.namespace("distBarrier")
.build();
curatorFramework.start();
distributedBarrier = new DistributedBarrier(curatorFramework, "/barrier");
// try {
// Stat stat = curatorFramework.checkExists().forPath("/double");
// if (stat != null)
// curatorFramework.delete().deletingChildrenIfNeeded().forPath("/double");
// else
// curatorFramework.create().creatingParentsIfNeeded()
// .withMode(CreateMode.PERSISTENT).forPath("/double");
// } catch (Exception e) {
// throw new RuntimeException("Cannot create path '/double' !!", e);
// }
distributedDoubleBarrier = new DistributedDoubleBarrier(curatorFramework, "/double", 3);
}
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:25,代码来源:CuratorDistributedBarrier.java
示例2: main
import org.apache.curator.framework.recipes.barriers.DistributedBarrier; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
try (TestingServer server = new TestingServer()) {
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
client.start();
ExecutorService service = Executors.newFixedThreadPool(QTY);
DistributedBarrier controlBarrier = new DistributedBarrier(client, PATH);
controlBarrier.setBarrier();
for (int i = 0; i < QTY; ++i) {
final DistributedBarrier barrier = new DistributedBarrier(client, PATH);
final int index = i;
Callable<Void> task = new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep((long) (3 * Math.random()));
System.out.println("Client #" + index + " waits on Barrier");
barrier.waitOnBarrier();
System.out.println("Client #" + index + " begins");
return null;
}
};
service.submit(task);
}
Thread.sleep(10000);
System.out.println("all Barrier instances should wait the condition");
controlBarrier.removeBarrier();
service.shutdown();
service.awaitTermination(10, TimeUnit.MINUTES);
}
}
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:40,代码来源:DistributedDoubleBarrierExample.java
示例3: init
import org.apache.curator.framework.recipes.barriers.DistributedBarrier; //导入依赖的package包/类
/**
*
* @throws Exception
*/
private void init(GlobalConfig conf) throws Exception{
this.conf = conf;
zkClient = ZKUtils.newClient();
loopBarrier = new DistributedDoubleBarrier(zkClient,
Constants.Algorithm.ZK_ALGO_CHROOT + "/" + conf.getAlgorithmName() + Constants.Algorithm.ZK_WAITING_PATH,
conf.getWorkers().size());
startBarrier = new DistributedBarrier(zkClient, Constants.Algorithm.ZK_ALGO_CHROOT + "/" + conf.getAlgorithmName() + "/start");
finishBarrier = new DistributedBarrier(zkClient, Constants.Algorithm.ZK_ALGO_CHROOT + "/" + conf.getAlgorithmName() + "/finish");
local = new MModelLocal();
shardId = conf.getShardId();
loops = conf.getAlgorithmConf().getInteger(Constants.Algorithm.LOOPS);
useSyncModel = JSONUtil.getConf(conf.getAlgorithmConf(), Constants.Algorithm.OPEN_MODEL_SERVER, false);
AlgoDeployConf deployConf = conf.getDeployConf();
//data server and client can be separated from a worker-node.
//
if (deployConf.isReduceServer()){
reduceServer = new ReduceServer(conf.getWorkerName(), conf.getWorkers().size(), conf.getAlgorithmName());
}
if (deployConf.isStartingGun()){
startingGun = new StartingGun2(conf.getAlgorithmName(), conf.getReduceServers().size(), conf.getWorkers().size());
}
modelServer = new MModelServer(conf.getWorkerName(), conf.getAlgorithmName(), local);
modelClient = new MModelClient(conf.getWorkers(), shardId, local);
reducerClient = new FloatReducerClient(conf.getReduceServers(), shardId);
}
开发者ID:lgnlgn,项目名称:feluca,代码行数:32,代码来源:LoopingBase.java
示例4: create
import org.apache.curator.framework.recipes.barriers.DistributedBarrier; //导入依赖的package包/类
public DistributedBarrier create(final String barrierPath) {
return new DistributedBarrier(framework, checkNotNull(barrierPath));
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:4,代码来源:DistributedBarrierFactory.java
注:本文中的org.apache.curator.framework.recipes.barriers.DistributedBarrier类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论