当前位置: 首页>>代码示例>>Java>>正文


Java EnsurePath类代码示例

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


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

示例1: sendContainerHeartBeat

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
/**
 * Updates the ZK container node with the container info.
 *
 * @param cinfo current ContainerInfo object.
 */
public void sendContainerHeartBeat(final ContainerInfo cinfo) {
    String containerPath = ZKUtils.getContainerPath(cinfo.getContainerId());
    LOGGER.debug("Container Path:" + containerPath);
    EnsurePath ensurePath = new EnsurePath(containerPath);
    try {
        ensurePath.ensure(curatorClient.getZookeeperClient());

        byte[] searializedCinfo = Utils.serialize(cinfo);

        curatorClient.setData().forPath(containerPath, searializedCinfo);
        LOGGER.debug("Updated container info for: "
                + containerPath);
    } catch (Exception e) {
        LOGGER.error("Could not create ZK node or set heartbeat for the "
                + "container.");
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
开发者ID:usc-cloud,项目名称:floe2,代码行数:25,代码来源:ZKClient.java

示例2: testEnsurePathWithNamespace

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
@Test
public void testEnsurePathWithNamespace() throws Exception
{
    final String namespace = "jz";

    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).namespace(namespace).build();
    client.start();
    try
    {
        EnsurePath ensurePath = new EnsurePath("/pity/the/fool");
        ensurePath.ensure(client.getZookeeperClient());
        Assert.assertNull(client.getZookeeperClient().getZooKeeper().exists("/jz/pity/the/fool", false));

        ensurePath = client.newNamespaceAwareEnsurePath("/pity/the/fool");
        ensurePath.ensure(client.getZookeeperClient());
        Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/jz/pity/the/fool", false));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:TestFramework.java

示例3: testBasic

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
@Test
public void    testBasic() throws Exception
{
    ZooKeeper               client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS);
    CuratorZookeeperClient  curator = mock(CuratorZookeeperClient.class);
    RetryPolicy             retryPolicy = new RetryOneTime(1);
    RetryLoop               retryLoop = new RetryLoop(retryPolicy, null);
    when(curator.getConnectionHandlingPolicy()).thenReturn(new StandardConnectionHandlingPolicy());
    when(curator.getZooKeeper()).thenReturn(client);
    when(curator.getRetryPolicy()).thenReturn(retryPolicy);
    when(curator.newRetryLoop()).thenReturn(retryLoop);

    Stat                    fakeStat = mock(Stat.class);
    when(client.exists(Mockito.<String>any(), anyBoolean())).thenReturn(fakeStat);
    
    EnsurePath      ensurePath = new EnsurePath("/one/two/three");
    ensurePath.ensure(curator);

    verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean());

    ensurePath.ensure(curator);
    verifyNoMoreInteractions(client);
    ensurePath.ensure(curator);
    verifyNoMoreInteractions(client);
}
 
开发者ID:apache,项目名称:curator,代码行数:26,代码来源:TestEnsurePath.java

示例4: setUp

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  zkServer = new TestingServer();
  client = CuratorFrameworkFactory
      .newClient("localhost:" + zkServer.getPort(),
          new ExponentialBackoffRetry(1000, 3));
  client.start();

  EnsurePath ensurePath = new EnsurePath(AGENT_PATH);
  ensurePath.ensure(client.getZookeeperClient());
  doSetUp();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:13,代码来源:TestAbstractZooKeeperConfigurationProvider.java

示例5: initServiceDiscovery

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
private void initServiceDiscovery() {
    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<>(MetaData.class);
    discovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build();
    try {
        discovery.start();
        new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());
    } catch (Exception e) {
        log.error("failed to start discovery for {}", basePath, e);
        throw new RuntimeException("failed to start discovery for " + basePath, e);
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:12,代码来源:HostRegister.java

示例6: validateZKPath

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
private void validateZKPath(String zkPath) throws Exception {
    EnsurePath path = zkClient.newNamespaceAwareEnsurePath(zkPath);
    path.ensure(zkClient.getZookeeperClient());
    Stat stat = zkClient.checkExists().forPath(zkPath);
    Preconditions.checkNotNull(stat);
    LOG.info("Path {} ensured", path.getPath());
}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:8,代码来源:LeaseManager.java

示例7: getServiceDiscovery

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the discovery
 * @throws Exception the exception
 */
protected static ServiceDiscovery<MetaData> getServiceDiscovery(CuratorFramework curatorFramework, String basePath)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build(); // Service Discovery
    serviceDiscovery.start();

    return serviceDiscovery;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:20,代码来源:ServiceUtil.java

示例8: getServiceCacheBuilder

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the ServiceCacheBuilder
 * @throws Exception the exception
 */
protected static ServiceDiscovery<MetaData> getServiceCacheBuilder(CuratorFramework curatorFramework, String basePath)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build(); // Service Discovery
    serviceDiscovery.start();

    return serviceDiscovery;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:20,代码来源:ServiceUtil.java

示例9: getServiceProvider

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the ServiceProvider
 * @throws Exception the exception
 */
protected static ServiceProvider<MetaData> getServiceProvider(CuratorFramework curatorFramework, String basePath, String serviceName)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = getServiceDiscovery(curatorFramework, basePath);
    ServiceProvider<MetaData> serviceProvider = serviceDiscovery.serviceProviderBuilder().serviceName(serviceName).build(); // Service Provider for a particular service
    serviceProvider.start();

    return serviceProvider;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:21,代码来源:ServiceUtil.java

示例10: curatorServiceDiscovery

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
@Bean(initMethod = "start", destroyMethod = "close")
public ServiceDiscovery curatorServiceDiscovery(
   CuratorFramework curatorFramework,
   @Value("${curator.discovery.basePath:/homeadvisor/services}") String basePath) throws Exception
{
   final Class payloadClass = Object.class;
   new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());
   return ServiceDiscoveryBuilder.builder(payloadClass)
      .client(curatorFramework)
      .basePath(basePath)
      .serializer(new JsonInstanceSerializer(payloadClass))
      .build();
}
 
开发者ID:HomeAdvisor,项目名称:Kafdrop,代码行数:14,代码来源:ServiceDiscoveryConfiguration.java

示例11: main

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
/**
 * 测试入口
 */
public static void main(String[] args) throws Exception {
	client.start();
	client.usingNamespace("ensurepath");
	
	EnsurePath ensurePath = new EnsurePath(path);
	ensurePath.ensure(client.getZookeeperClient());

	// 切换工作空间
	EnsurePath ensurePath2 = client.newNamespaceAwareEnsurePath("/sub");
	ensurePath2.ensure(client.getZookeeperClient());
}
 
开发者ID:bdceo,项目名称:bd-codes,代码行数:15,代码来源:CuratorEnsurePathTest.java

示例12: doAdvertise

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
public void doAdvertise(Service<byte[]> service, boolean flag)
{
  try {
    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    ServiceInstance<byte[]> instance = getInstance(service);
    if (flag) {
      discovery.registerService(instance);
    } else {
      discovery.unregisterService(instance);
    }
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:16,代码来源:ZKAssistedDiscovery.java

示例13: testInitialize

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
@Test
public void testInitialize() throws Exception {
    Stat stat = new Stat();
    CuratorFramework curatorFramework = mockFramework();
    GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
    WatchPathable watchPathable = mock(WatchPathable.class);
    SyncBuilder syncBuilder = mock(SyncBuilder.class);
    Pathable pathable = mock(Pathable.class);
    when(curatorFramework.sync()).thenReturn(syncBuilder);
    when(syncBuilder.inBackground(any(BackgroundCallback.class))).thenReturn(pathable);
    when(curatorFramework.getZookeeperClient()).thenReturn(mock(CuratorZookeeperClient.class));
    when(curatorFramework.getData()).thenReturn(getDataBuilder);
    when(curatorFramework.getState()).thenReturn(CuratorFrameworkState.STARTED);
    when(getDataBuilder.storingStatIn(any(Stat.class))).thenReturn(watchPathable);
    when(watchPathable.forPath(anyString())).thenReturn(new byte[0]);
    when(getDataBuilder.forPath(anyString())).thenReturn(null);
    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    EnsurePath ensurePath = mock(EnsurePath.class);
    when(curatorFramework.checkExists()).thenReturn(existsBuilder);
    when(curatorFramework.newNamespaceAwareEnsurePath(anyString())).thenReturn(ensurePath);
    when(ensurePath.excludingLast()).thenReturn(ensurePath);
    when(existsBuilder.forPath("/test/config")).thenReturn(stat);
    when(existsBuilder.usingWatcher(any(CuratorWatcher.class))).thenReturn(existsBuilder);
    when(existsBuilder.inBackground(any(BackgroundCallback.class))).thenReturn(existsBuilder);
    ExampleConfigAdapter exampleConfigAdapter = new ExampleConfigAdapter(curatorFramework);
    assertNotNull(exampleConfigAdapter);
}
 
开发者ID:librato,项目名称:watchconf,代码行数:28,代码来源:DynamicConfigZKAdapterTest.java

示例14: testReadConfig

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
@Test
public void testReadConfig() throws Exception {

    ExampleConfig exampleConfig = new ExampleConfig();
    exampleConfig.name = "ray";
    ObjectMapper objectMapper = new ObjectMapper();

    Stat stat = new Stat();
    CuratorFramework curatorFramework = mockFramework();
    GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
    WatchPathable watchPathable = mock(WatchPathable.class);
    SyncBuilder syncBuilder = mock(SyncBuilder.class);
    Pathable pathable = mock(Pathable.class);
    when(curatorFramework.getZookeeperClient()).thenReturn(mock(CuratorZookeeperClient.class));
    when(curatorFramework.getData()).thenReturn(getDataBuilder);
    when(curatorFramework.getState()).thenReturn(CuratorFrameworkState.STARTED);
    when(curatorFramework.sync()).thenReturn(syncBuilder);
    when(syncBuilder.inBackground(any(BackgroundCallback.class))).thenReturn(pathable);
    when(getDataBuilder.storingStatIn(any(Stat.class))).thenReturn(watchPathable);
    when(watchPathable.forPath(anyString())).thenReturn(objectMapper.writeValueAsBytes(exampleConfig));
    when(getDataBuilder.forPath(anyString())).thenReturn(objectMapper.writeValueAsBytes(exampleConfig));
    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    EnsurePath ensurePath = mock(EnsurePath.class);
    when(curatorFramework.checkExists()).thenReturn(existsBuilder);
    when(curatorFramework.newNamespaceAwareEnsurePath(anyString())).thenReturn(ensurePath);
    when(ensurePath.excludingLast()).thenReturn(ensurePath);
    when(existsBuilder.forPath("/test/config")).thenReturn(stat);
    when(existsBuilder.usingWatcher(any(CuratorWatcher.class))).thenReturn(existsBuilder);
    when(existsBuilder.inBackground(any(BackgroundCallback.class))).thenReturn(existsBuilder);
    ExampleConfigAdapter exampleConfigAdapter = new ExampleConfigAdapter(curatorFramework);
    exampleConfigAdapter.start();
    assertNotNull(exampleConfigAdapter);
    assertTrue(exampleConfigAdapter.get().isPresent());
    assertEquals(exampleConfigAdapter.get().get().name, "ray");
}
 
开发者ID:librato,项目名称:watchconf,代码行数:36,代码来源:DynamicConfigZKAdapterTest.java

示例15: addSubscription

import org.apache.curator.utils.EnsurePath; //导入依赖的package包/类
public void addSubscription(String location, TreeCacheListener listener) throws Exception {
    CuratorFramework client = curator.getCurator();
    EnsurePath ensureMvTestPath = new EnsurePath(location);
    ensureMvTestPath.ensure(client.getZookeeperClient());
    TreeCache cache = new TreeCache(client, location);
    cache.getListenable().addListener(listener);
    cache.start();
    caches.put(location, cache);
    logger.info("Added ZooKeeper subscriber for " + location + " children.");
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:11,代码来源:ZkSubscriptionHandler.java


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