• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SharedCount类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.curator.framework.recipes.shared.SharedCount的典型用法代码示例。如果您正苦于以下问题:Java SharedCount类的具体用法?Java SharedCount怎么用?Java SharedCount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SharedCount类属于org.apache.curator.framework.recipes.shared包,在下文中一共展示了SharedCount类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: printAll

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public static void printAll(CuratorFramework client, String path,
		String prefix) {
	client.start();
	List<String> children;
	try {
		children = client.getChildren().forPath(path);
		for (String child : children) {
			if (child.startsWith(prefix)) {
				SharedCount c = new SharedCount(client, path + child, 0);
				c.start();
				System.out.println(path + child + "\t" + c.getCount());
				c.close();
			}
		}
		client.close();
	} catch (Exception e) {
		e.printStackTrace();

	}
}
 
开发者ID:mitdbg,项目名称:AdaptDB,代码行数:21,代码来源:CuratorUtils.java


示例2: getIncrementForPrefix

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
@SuppressWarnings("resource")
private int getIncrementForPrefix(String prefix) {
    String path = String.format(COUNTER_PATH, prefix);
    SharedCount sharedCount = new SharedCount(curator.get(), path, 1);
    try {
        sharedCount.start();
        for (int count = sharedCount.getCount(); true; count = sharedCount.getCount()) {
            if (sharedCount.trySetCount(count + 1)) {
                return count;
            }
        }
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    } finally {
        IOUtils.safeClose(sharedCount);
    }
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:18,代码来源:ClusterDataStoreImpl.java


示例3: incrSharedCount

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
private void incrSharedCount(SharedCount sharedCount) throws Exception {
  while (true) {
    // Loop until we successfully increment the counter
    VersionedValue<Integer> versionedValue = sharedCount.getVersionedValue();
    if (sharedCount.trySetCount(versionedValue, versionedValue.getValue() + 1)) {
      break;
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:10,代码来源:ZKDelegationTokenSecretManager.java


示例4: createSharedCount

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
/**
 * Creates a {@link ZooKeeperSharedCount} to store a shared count between multiple instances.
 *
 * @param path to the shared count in ZooKeeper
 * @param seedCount for the shared count
 * @return a shared count
 */
public ZooKeeperSharedCount createSharedCount(String path, int seedCount) {
	return new ZooKeeperSharedCount(
		new SharedCount(
			facade,
			path,
			seedCount));
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:15,代码来源:ZooKeeperUtilityFactory.java


示例5: createAndStartCounter

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public static SharedCount createAndStartCounter(String zkHosts,
		String counterPath) {
	SharedCount c = createCounter(zkHosts, counterPath);
	try {
		c.start();
		return c;
	} catch (Exception e) {
		e.printStackTrace();
		throw new RuntimeException("Failed to start the counter: "
				+ counterPath + "\n" + e.getMessage());
	}
}
 
开发者ID:mitdbg,项目名称:AdaptDB,代码行数:13,代码来源:CuratorUtils.java


示例6: getCounter

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public static int getCounter(CuratorFramework client, String counterPath) {
	SharedCount c = new SharedCount(client, counterPath, 0);
	try {
		c.start();
		int val = c.getCount();
		c.close();
		return val;

	} catch (Exception e) {
		e.printStackTrace();
		throw new RuntimeException("Failed to add the counter: "
				+ counterPath + "\n" + e.getMessage());
	}
}
 
开发者ID:mitdbg,项目名称:AdaptDB,代码行数:15,代码来源:CuratorUtils.java


示例7: addCounter

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public static void addCounter(SharedCount c, int increment) {
	int oldVal = c.getCount();
	try {
		c.setCount(oldVal + increment);
	} catch (Exception e) {
		e.printStackTrace();
		throw new RuntimeException("Failed to increment the counter: " + c);
	}
}
 
开发者ID:mitdbg,项目名称:AdaptDB,代码行数:10,代码来源:CuratorUtils.java


示例8: setCounter

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public static void setCounter(CuratorFramework client, String counterPath,
		int value) {
	SharedCount c = new SharedCount(client, counterPath, 0);
	try {
		c.start();
		c.setCount(value);
		c.close();
	} catch (Exception e) {
		e.printStackTrace();
		throw new RuntimeException("Failed to add the counter: "
				+ counterPath + "\n" + e.getMessage());
	}
}
 
开发者ID:mitdbg,项目名称:AdaptDB,代码行数:14,代码来源:CuratorUtils.java


示例9: ZooKeeperSharedCount

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public ZooKeeperSharedCount(SharedCount sharedCount) {
	this.sharedCount = Preconditions.checkNotNull(sharedCount);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:4,代码来源:ZooKeeperSharedCount.java


示例10: createCounter

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public static SharedCount createCounter(String hosts, String counterPath) {
	CuratorFramework client = createClient(hosts);
	return new SharedCount(client, counterPath, 0);
}
 
开发者ID:mitdbg,项目名称:AdaptDB,代码行数:5,代码来源:CuratorUtils.java


示例11: testThreadedLeaseIncrease

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
@Test
public void testThreadedLeaseIncrease() throws Exception
{
    final Timing timing = new Timing();
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    try
    {
        client.start();

        final SharedCount count = new SharedCount(client, "/foo/count", 1);
        count.start();

        final InterProcessSemaphoreV2 semaphore = new InterProcessSemaphoreV2(client, "/test", count);

        ExecutorService service = Executors.newCachedThreadPool();

        final CountDownLatch latch1 = new CountDownLatch(1);
        final CountDownLatch latch2 = new CountDownLatch(1);
        Future<Object> future1 = service.submit
            (
                new Callable<Object>()
                {
                    @Override
                    public Object call() throws Exception
                    {
                        Lease lease = semaphore.acquire(timing.seconds(), TimeUnit.SECONDS);
                        Assert.assertNotNull(lease);
                        latch1.countDown();
                        lease = semaphore.acquire(timing.forWaiting().seconds(), TimeUnit.SECONDS);
                        Assert.assertNotNull(lease);
                        latch2.countDown();
                        return null;
                    }
                }
            );
        Future<Object> future2 = service.submit
            (
                new Callable<Object>()
                {
                    @Override
                    public Object call() throws Exception
                    {
                        Assert.assertTrue(latch1.await(timing.forWaiting().seconds(), TimeUnit.SECONDS));
                        timing.sleepABit(); // make sure second acquire is waiting
                        Assert.assertTrue(count.trySetCount(2));
                        //Make sure second acquire takes less than full waiting time:
                        timing.sleepABit();
                        Assert.assertTrue(latch2.await(0, TimeUnit.SECONDS));
                        return null;
                    }
                }
            );

        future1.get();
        future2.get();

        count.close();
    }
    finally
    {
        TestCleanState.closeAndTestClean(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:64,代码来源:TestInterProcessSemaphore.java


示例12: main

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
public static void main(String[] args) throws IOException, Exception {
	final Random rand = new Random();
	SharedCounterExample example = new SharedCounterExample();
	try (TestingServer server = new TestingServer()) {
		CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
		client.start();
		
		SharedCount baseCount = new SharedCount(client, PATH, 0);
		baseCount.addListener(example);
		baseCount.start();
		
		List<SharedCount> examples = Lists.newArrayList();
		ExecutorService service = Executors.newFixedThreadPool(QTY);
		for (int i = 0; i < QTY; ++i) {
			final SharedCount count = new SharedCount(client, PATH, 0);
			examples.add(count);
			Callable<Void> task = new Callable<Void>() {
				@Override
				public Void call() throws Exception {
					count.start();
					Thread.sleep(rand.nextInt(10000));
					System.out.println("Increment:" + count.trySetCount(count.getVersionedValue(), count.getCount() + rand.nextInt(10)));
					return null;
				}
			};
			service.submit(task);
		}
		
		
		
		service.shutdown();
		service.awaitTermination(10, TimeUnit.MINUTES);
		
		for (int i = 0; i < QTY; ++i) {
			examples.get(i).close();
		}
		baseCount.close();
	}


}
 
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:42,代码来源:SharedCounterExample.java


示例13: ZooKeeperCheckpointIDCounter

import org.apache.curator.framework.recipes.shared.SharedCount; //导入依赖的package包/类
/**
 * Creates a {@link ZooKeeperCheckpointIDCounter} instance.
 *
 * @param client      Curator ZooKeeper client
 * @param counterPath ZooKeeper path for the counter. It's sufficient to have a path per-job.
 */
public ZooKeeperCheckpointIDCounter(CuratorFramework client, String counterPath) {
	this.client = checkNotNull(client, "Curator client");
	this.counterPath = checkNotNull(counterPath, "Counter path");
	this.sharedCount = new SharedCount(client, counterPath, 1);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:ZooKeeperCheckpointIDCounter.java



注:本文中的org.apache.curator.framework.recipes.shared.SharedCount类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NGramTokenizer类代码示例发布时间:2022-05-22
下一篇:
Java WorldGenBigMushroom类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap