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


Java CuratorZookeeperClient类代码示例

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


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

示例1: ensure

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public synchronized void ensure(final CuratorZookeeperClient client, final String path, final boolean makeLastNode) throws Exception
{
    if ( !isSet )
    {
        RetryLoop.callWithRetry
            (
                client,
                new Callable<Object>()
                {
                    @Override
                    public Object call() throws Exception
                    {
                        ZKPaths.mkdirs(client.getZooKeeper(), path, makeLastNode, aclProvider, asContainers());
                        helper.set(doNothingHelper);
                        isSet = true;
                        return null;
                    }
                }
            );
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:23,代码来源:EnsurePath.java

示例2: callWithRetry

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public <T> T callWithRetry(CuratorZookeeperClient client, Callable<T> proc) throws Exception
{
    client.internalBlockUntilConnectedOrTimedOut();

    T result = null;
    RetryLoop retryLoop = client.newRetryLoop();
    while ( retryLoop.shouldContinue() )
    {
        try
        {
            result = proc.call();
            retryLoop.markComplete();
        }
        catch ( Exception e )
        {
            ThreadUtils.checkInterrupted(e);
            retryLoop.takeException(e);
        }
    }

    return result;
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:StandardConnectionHandlingPolicy.java

示例3: before

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
  testingServer = new TestingServer(true);
  zkClient = new CuratorZookeeperClient(testingServer.getConnectString(), 5000, 5000, null, new RetryOneTime(1000));
  zkClient.start();
  zkClient.blockUntilConnectedOrTimedOut();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:8,代码来源:TestZKClusterClient.java

示例4: testInitialize

import org.apache.curator.CuratorZookeeperClient; //导入依赖的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

示例5: testReadConfig

import org.apache.curator.CuratorZookeeperClient; //导入依赖的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

示例6: createKafkaTopicRepository

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
private KafkaTopicRepository createKafkaTopicRepository() {
    final CuratorZookeeperClient zookeeperClient = mock(CuratorZookeeperClient.class);
    when(zookeeperClient.getCurrentConnectionString()).thenReturn(ZOOKEEPER_URL);

    final CuratorFramework curatorFramework = mock(CuratorFramework.class);
    when(curatorFramework.getZookeeperClient()).thenReturn(zookeeperClient);

    final ZooKeeperHolder zooKeeperHolder = mock(ZooKeeperHolder.class);
    when(zooKeeperHolder.get()).thenReturn(curatorFramework);

    final Consumer<byte[], byte[]> consumer = mock(Consumer.class);
    when(consumer.partitionsFor(any())).thenReturn(new ArrayList<>());

    final KafkaFactory factory = mock(KafkaFactory.class);
    when(factory.getConsumer()).thenReturn(consumer);

    Mockito
            .doReturn(kafkaHelper.createProducer())
            .when(factory)
            .takeProducer();

    return new KafkaTopicRepository(zooKeeperHolder,
            factory,
            nakadiSettings,
            kafkaSettings,
            zookeeperSettings,
            new UUIDGenerator());
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:29,代码来源:KafkaRepositoryAT.java

示例7: fixForNamespace

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
String    fixForNamespace(String path, boolean isSequential)
{
    if ( ensurePathNeeded.get() )
    {
        try
        {
            final CuratorZookeeperClient zookeeperClient = client.getZookeeperClient();
            RetryLoop.callWithRetry
            (
                zookeeperClient,
                new Callable<Object>()
                {
                    @Override
                    public Object call() throws Exception
                    {
                        ZKPaths.mkdirs(zookeeperClient.getZooKeeper(), ZKPaths.makePath("/", namespace), true, client.getAclProvider(), true);
                        return null;
                    }
                }
            );
            ensurePathNeeded.set(false);
        }
        catch ( Exception e )
        {
            ThreadUtils.checkInterrupted(e);
            client.logError("Ensure path threw exception", e);
        }
    }

    return ZKPaths.fixForNamespace(namespace, path, isSequential);
}
 
开发者ID:apache,项目名称:curator,代码行数:32,代码来源:NamespaceImpl.java

示例8: testSimple

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Test
public void     testSimple() throws Exception
{
    Exhibitors                  exhibitors = new Exhibitors(Lists.newArrayList("foo", "bar"), 1000, dummyConnectionStringProvider);
    ExhibitorRestClient         mockRestClient = new ExhibitorRestClient()
    {
        @Override
        public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception
        {
            return "count=1&port=" + server.getPort() + "&server0=localhost";
        }
    };
    ExhibitorEnsembleProvider   provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
    provider.pollForInitialEnsemble();

    Timing                      timing = new Timing();
    CuratorZookeeperClient      client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new ExponentialBackoffRetry(timing.milliseconds(), 3));
    client.start();
    try
    {
        client.blockUntilConnectedOrTimedOut();
        client.getZooKeeper().exists("/", false);
    }
    catch ( Exception e )
    {
        Assert.fail("provider.getConnectionString(): " + provider.getConnectionString() + " server.getPort(): " + server.getPort(), e);
    }
    finally
    {
        client.close();
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:33,代码来源:TestExhibitorEnsembleProvider.java

示例9: getZookeeperClient

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public CuratorZookeeperClient getZookeeperClient() {
    return curator.getZookeeperClient();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:5,代码来源:RedirectorCuratorFramework.java

示例10: GtidSync

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
public GtidSync(String zkPath, CuratorZookeeperClient curatorZookeeperClient) {
	this.curatorZookeeperClient = curatorZookeeperClient;
	this.zkPath = zkPath;
	
	loadGtidSet();
}
 
开发者ID:mrkamel,项目名称:replicaza,代码行数:7,代码来源:GtidSync.java

示例11: createCuratorZookeeperClient

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
public CuratorZookeeperClient createCuratorZookeeperClient() {
	CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("127.0.0.1", new ExponentialBackoffRetry(1000, 3));
	curatorFramework.start();
	
	return curatorFramework.getZookeeperClient();
}
 
开发者ID:mrkamel,项目名称:replicaza,代码行数:7,代码来源:GtidSyncTest.java

示例12: getZooClient

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
public CuratorZookeeperClient getZooClient() {
	return zooClient;
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:4,代码来源:EndpointPublisher.java

示例13: getZookeeperClient

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public CuratorZookeeperClient getZookeeperClient() {
    throw new UnsupportedOperationException("Not implemented in MockCurator");
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:5,代码来源:MockCurator.java

示例14: getZookeeperClient

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public CuratorZookeeperClient getZookeeperClient()
{
    return client.getZookeeperClient();
}
 
开发者ID:apache,项目名称:curator,代码行数:6,代码来源:NamespaceFacade.java

示例15: CuratorFrameworkImpl

import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
public CuratorFrameworkImpl(CuratorFrameworkFactory.Builder builder)
{
    ZookeeperFactory localZookeeperFactory = makeZookeeperFactory(builder.getZookeeperFactory());
    this.client = new CuratorZookeeperClient
        (
            localZookeeperFactory,
            builder.getEnsembleProvider(),
            builder.getSessionTimeoutMs(),
            builder.getConnectionTimeoutMs(),
            new Watcher()
            {
                @Override
                public void process(WatchedEvent watchedEvent)
                {
                    CuratorEvent event = new CuratorEventImpl(CuratorFrameworkImpl.this, CuratorEventType.WATCHED, watchedEvent.getState().getIntValue(), unfixForNamespace(watchedEvent.getPath()), null, null, null, null, null, watchedEvent, null, null);
                    processEvent(event);
                }
            },
            builder.getRetryPolicy(),
            builder.canBeReadOnly(),
            builder.getConnectionHandlingPolicy()
        );

    internalConnectionHandler = new StandardInternalConnectionHandler();
    listeners = new ListenerContainer<CuratorListener>();
    unhandledErrorListeners = new ListenerContainer<UnhandledErrorListener>();
    backgroundOperations = new DelayQueue<OperationAndData<?>>();
    forcedSleepOperations = new LinkedBlockingQueue<>();
    namespace = new NamespaceImpl(this, builder.getNamespace());
    threadFactory = getThreadFactory(builder);
    maxCloseWaitMs = builder.getMaxCloseWaitMs();
    connectionStateManager = new ConnectionStateManager(this, builder.getThreadFactory(), builder.getSessionTimeoutMs(), builder.getConnectionHandlingPolicy().getSimulatedSessionExpirationPercent());
    compressionProvider = builder.getCompressionProvider();
    aclProvider = builder.getAclProvider();
    state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT);
    useContainerParentsIfAvailable = builder.useContainerParentsIfAvailable();
    connectionStateErrorPolicy = Preconditions.checkNotNull(builder.getConnectionStateErrorPolicy(), "errorPolicy cannot be null");
    schemaSet = Preconditions.checkNotNull(builder.getSchemaSet(), "schemaSet cannot be null");
    zk34CompatibilityMode = builder.isZk34CompatibilityMode();

    byte[] builderDefaultData = builder.getDefaultData();
    defaultData = (builderDefaultData != null) ? Arrays.copyOf(builderDefaultData, builderDefaultData.length) : new byte[0];
    authInfos = buildAuths(builder);

    failedDeleteManager = new FailedDeleteManager(this);
    failedRemoveWatcherManager = new FailedRemoveWatchManager(this);
    namespaceFacadeCache = new NamespaceFacadeCache(this);

    ensembleTracker = zk34CompatibilityMode ? null : new EnsembleTracker(this, builder.getEnsembleProvider());
}
 
开发者ID:apache,项目名称:curator,代码行数:51,代码来源:CuratorFrameworkImpl.java


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