本文整理汇总了Java中org.apache.curator.ensemble.fixed.FixedEnsembleProvider类的典型用法代码示例。如果您正苦于以下问题:Java FixedEnsembleProvider类的具体用法?Java FixedEnsembleProvider怎么用?Java FixedEnsembleProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FixedEnsembleProvider类属于org.apache.curator.ensemble.fixed包,在下文中一共展示了FixedEnsembleProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeCurator
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
private Completable initializeCurator()
{
// Create/start CuratorFramework client
RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(retryBaseTime, retryMaxTime, retryLimit);
EnsembleProvider ensembleProvider = new FixedEnsembleProvider(connectionString);
curator = CuratorFrameworkFactory.builder()
.ensembleProvider(ensembleProvider)
.retryPolicy(retryPolicy)
.namespace(namespace)
.sessionTimeoutMs(sessionTimeout)
.connectionTimeoutMs(connectionTimeout)
.build();
curator.start();
// Create a NodeCache for each config descriptor
// This creates N node caches at a time on the RxJava IO scheduler thread pool.
return Observable.from(configDescriptors)
.flatMap(desc -> buildNodeCache(desc)
.subscribeOn(Schedulers.io())
.map(nc -> this.configNodeCaches.put(desc, nc)), getConcurrentNodeCacheCreations())
.toCompletable();
}
示例2: testFactory
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Test
public void testFactory() throws Exception
{
final ZooKeeper mockZookeeper = Mockito.mock(ZooKeeper.class);
ZookeeperFactory zookeeperFactory = new ZookeeperFactory()
{
@Override
public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception
{
return mockZookeeper;
}
};
CuratorZookeeperClient client = new CuratorZookeeperClient(zookeeperFactory, new FixedEnsembleProvider(server.getConnectString()), 10000, 10000, null, new RetryOneTime(1), false);
client.start();
Assert.assertEquals(client.getZooKeeper(), mockZookeeper);
}
示例3: buildCuratorFramework
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
/**
* Builds a {@link org.apache.curator.framework.CuratorFramework} from the specified {@link java.util.Map<String, ?>}.
*/
private synchronized CuratorFramework buildCuratorFramework(ZookeeperConfig curatorConfig) {
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
.ensembleProvider(new FixedEnsembleProvider(curatorConfig.getZookeeperUrl()))
.connectionTimeoutMs(curatorConfig.getZookeeperConnectionTimeOut())
.sessionTimeoutMs(curatorConfig.getZookeeperSessionTimeout())
.retryPolicy(new RetryNTimes(curatorConfig.getZookeeperRetryMax(), curatorConfig.getZookeeperRetryInterval()));
if (!StringUtils.isNullOrBlank(curatorConfig.getZookeeperPassword())) {
String scheme = "digest";
byte[] auth = ("fabric:" + PasswordEncoder.decode(curatorConfig.getZookeeperPassword())).getBytes();
builder = builder.authorization(scheme, auth).aclProvider(aclProvider.get());
}
CuratorFramework framework = builder.build();
for (ConnectionStateListener listener : connectionStateListeners) {
framework.getConnectionStateListenable().addListener(listener);
}
return framework;
}
示例4: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Injector inj = Guice.createInjector(
Stage.PRODUCTION,
new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("Cultivar.Curator.baseNamespace")).to("dev/test");
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(
new ExponentialBackoffRetry(10, 10));
}
}), NamespaceModuleBuilder.create().newNamespace(null).targetAnnotation(Cultivar.class).build(),
NamespaceModuleBuilder.create().newNamespace("foo").targetAnnotation(Names.named("foo")).build());
manager = inj.getInstance(CultivarStartStopManager.class);
namespacedNullFramework = inj.getInstance(Key.get(CuratorFramework.class, Cultivar.class));
namespacedFooFramework = inj.getInstance(Key.get(CuratorFramework.class, Names.named("foo")));
manager.startAsync().awaitRunning();
}
示例5: supplyBindingInformation
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
/**
* Supply the binding information.
* This implementation returns a fixed ensemble bonded to
* the quorum supplied by {@link #buildConnectionString()}
* @return the binding information
*/
@Override
public BindingInformation supplyBindingInformation() {
BindingInformation binding = new BindingInformation();
String connectString = buildConnectionString();
binding.ensembleProvider = new FixedEnsembleProvider(connectString);
binding.description =
"fixed ZK quorum \"" + connectString + "\"";
return binding;
}
示例6: serviceStart
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
/**
* Startup: start ZK. It is only after this that
* the binding information is valid.
* @throws Exception
*/
@Override
protected void serviceStart() throws Exception {
setupSecurity();
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, dataDir);
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(tickTime);
LOG.info("Starting Local Zookeeper service");
factory = ServerCnxnFactory.createFactory();
factory.configure(getAddress(port), -1);
factory.startup(zkServer);
String connectString = getConnectionString();
LOG.info("In memory ZK started at {}\n", connectString);
if (LOG.isDebugEnabled()) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
zkServer.dumpConf(pw);
pw.flush();
LOG.debug(sw.toString());
}
binding = new BindingInformation();
binding.ensembleProvider = new FixedEnsembleProvider(connectString);
binding.description =
getName() + " reachable at \"" + connectString + "\"";
addDiagnostics(binding.description);
// finally: set the binding information in the config
getConfig().set(KEY_REGISTRY_ZK_QUORUM, connectString);
}
示例7: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
inj = Guice.createInjector(
new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(
new ExponentialBackoffRetry(1000, 3));
}
}),
ServiceDiscoveryModuleBuilder.create().annotation(Curator.class).basePath("/discovery").build(),
ServiceProviderModuleBuilder.create(Void.class).name("service").discovery(Curator.class)
.annotation(Cultivar.class).build());
discovery = inj.getInstance(Key.get(new TypeLiteral<ServiceDiscovery<Void>>() {
}, Curator.class));
service1 = ServiceInstance.<Void> builder().name("service").build();
service2 = ServiceInstance.<Void> builder().name("service").build();
provider = inj.getInstance(Key.get(new TypeLiteral<ServiceProvider<Void>>() {
}, Cultivar.class));
manager = inj.getInstance(CultivarStartStopManager.class);
}
示例8: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
inj = Guice.createInjector(new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(new ExponentialBackoffRetry(1000, 3));
}
}));
}
示例9: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Injector inj = Guice.createInjector(new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(new ExponentialBackoffRetry(1000, 3));
}
}));
manager = inj.getInstance(CultivarStartStopManager.class);
CuratorManagementService managementService = inj.getInstance(Key.get(CuratorManagementService.class,
Curator.class));
managementService.addConnectionListener(new ConnectionStateListener() {
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
if (ConnectionState.CONNECTED.equals(newState)) {
connectionLatch.countDown();
}
}
});
state = inj.getInstance(LastKnownState.class);
manager.startAsync().awaitRunning();
}
示例10: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Injector inj1 = Guice.createInjector(Stage.PRODUCTION, new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(new RetryNTimes(10, 100));
}
}));
Injector inj2 = Guice.createInjector(Stage.PRODUCTION, new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(new RetryNTimes(10, 100));
}
}));
manager1 = inj1.getInstance(CultivarStartStopManager.class);
manager2 = inj2.getInstance(CultivarStartStopManager.class);
manager1.startAsync();
manager2.startAsync();
manager1.awaitRunning();
manager2.awaitRunning();
DistributedBarrierFactory factory1 = inj1.getInstance(DistributedBarrierFactory.class);
DistributedBarrierFactory factory2 = inj2.getInstance(DistributedBarrierFactory.class);
barrierA1 = factory1.create("/test");
barrierA2 = factory2.create("/test");
}
示例11: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
LOG.info("*** SERVERS *** {}", testingCluster.getConnectString());
Injector inj1 = Guice.createInjector(Stage.PRODUCTION, new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(new RetryNTimes(10, 10));
}
}));
Injector inj2 = Guice.createInjector(Stage.PRODUCTION, new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(new RetryNTimes(10, 10));
}
}));
manager1 = inj1.getInstance(CultivarStartStopManager.class);
manager2 = inj2.getInstance(CultivarStartStopManager.class);
manager1.startAsync();
manager2.startAsync();
manager1.awaitRunning();
manager2.awaitRunning();
DistributedDoubleBarrierFactory factory1 = inj1.getInstance(DistributedDoubleBarrierFactory.class);
DistributedDoubleBarrierFactory factory2 = inj2.getInstance(DistributedDoubleBarrierFactory.class);
barrierA1 = factory1.create("/test", 2);
barrierA2 = factory2.create("/test", 2);
}
示例12: get
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Override
public EnsembleProvider get() {
if (exhibitorInstances.isPresent()) {
return exhibitorEnsembleProvider();
}
return new FixedEnsembleProvider(backupConnections.get());
}
示例13: get_ExhibitorNotPresent_ReturnsFixedEnsembleWithConnectionString
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Test
public void get_ExhibitorNotPresent_ReturnsFixedEnsembleWithConnectionString() {
String conn = "localhost:2181";
EnsembleProviderProvider provider = new EnsembleProviderProvider(Optional.<String> absent(), Optional.of(conn));
EnsembleProvider ensembleProvider = provider.get();
assertTrue(ensembleProvider instanceof FixedEnsembleProvider);
assertEquals(conn, ensembleProvider.getConnectionString());
}
示例14: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
inj = Guice.createInjector(
new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(
new ExponentialBackoffRetry(1000, 3));
}
}),
ServiceDiscoveryModuleBuilder.create().annotation(Curator.class).basePath("/discovery").build(),
ServiceProviderModuleBuilder.create(Void.class).name("service").discovery(Curator.class)
.annotation(Cultivar.class).build());
discovery = inj.getInstance(Key.get(new TypeLiteral<ServiceDiscovery<Void>>() {
}, Curator.class));
service1 = ServiceInstance.<Void> builder().name("service").build();
service2 = ServiceInstance.<Void> builder().name("service").build();
provider = inj.getInstance(Key.get(new TypeLiteral<ServiceProvider<Void>>() {
}, Cultivar.class));
manager = inj.getInstance(CultivarStartStopManager.class);
}
示例15: setUp
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
ServiceInstance<ImmutableProperties> service1 = ServiceInstance.<ImmutableProperties>builder().id("randomid").name("service").payload(props)
.build();
Injector inj = Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("Cultivar.Curator.baseNamespace")).to("dev/test");
}
},
new CuratorModule(new AbstractModule() {
@Override
protected void configure() {
bind(EnsembleProvider.class).annotatedWith(Curator.class).toInstance(
new FixedEnsembleProvider(testingCluster.getConnectString()));
bind(RetryPolicy.class).annotatedWith(Curator.class).toInstance(
new ExponentialBackoffRetry(1000, 3));
}
}),
new RegistrationModule(),
ServiceDiscoveryModuleBuilder.create(ImmutableProperties.class).annotation(Curator.class)
.basePath("/discovery").build(), ServiceProviderModuleBuilder.create(ImmutableProperties.class)
.name("service").discovery(Curator.class).annotation(Cultivar.class).build(),
RegistrationServiceModuleBuilder.create(ImmutableProperties.class).discoveryAnnotation(Curator.class)
.targetAnnotation(Curator.class).provider(Providers.of(service1)).build());
provider = inj.getInstance(Key.get(new TypeLiteral<ServiceProvider<ImmutableProperties>>() {
}, Cultivar.class));
manager = inj.getInstance(CultivarStartStopManager.class);
}