本文整理汇总了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;
}
}
);
}
}
示例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;
}
示例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();
}
示例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);
}
示例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");
}
示例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());
}
示例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);
}
示例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();
}
}
示例9: getZookeeperClient
import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public CuratorZookeeperClient getZookeeperClient() {
return curator.getZookeeperClient();
}
示例10: GtidSync
import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
public GtidSync(String zkPath, CuratorZookeeperClient curatorZookeeperClient) {
this.curatorZookeeperClient = curatorZookeeperClient;
this.zkPath = zkPath;
loadGtidSet();
}
示例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();
}
示例12: getZooClient
import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
public CuratorZookeeperClient getZooClient() {
return zooClient;
}
示例13: getZookeeperClient
import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public CuratorZookeeperClient getZookeeperClient() {
throw new UnsupportedOperationException("Not implemented in MockCurator");
}
示例14: getZookeeperClient
import org.apache.curator.CuratorZookeeperClient; //导入依赖的package包/类
@Override
public CuratorZookeeperClient getZookeeperClient()
{
return client.getZookeeperClient();
}
示例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());
}