org.apache.curator.ensemble.fixed.FixedEnsembleProvider Java Examples

The following examples show how to use org.apache.curator.ensemble.fixed.FixedEnsembleProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicTests.java    From xian with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: BasicTests.java    From curator with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: ZKUtil.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化一个Curator
 * @param zkConnetcionStrings
 * @return
 */
private static CuratorFramework createCurator(String zkConnetcionStrings) {
    FixedEnsembleProvider ensembleProvider = new FixedEnsembleProvider(zkConnetcionStrings);
    int sessionTimeout = 60000;
    int connectionTimeout = 15000;
    int retryTimes = 5;
    int retryInterval = 1000;
    int retryCeiling = 60000;
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(retryInterval, retryCeiling, retryTimes);
    builder.ensembleProvider(ensembleProvider).connectionTimeoutMs(connectionTimeout).sessionTimeoutMs(sessionTimeout).retryPolicy(retryPolicy);
    CuratorFramework framework = builder.build();
    return framework;
}
 
Example #4
Source File: CuratorService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: MicroZookeeperService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: CuratorService.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: MicroZookeeperService.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source File: ResolvingEnsembleProvider.java    From curator-extensions with Apache License 2.0 5 votes vote down vote up
private static EnsembleProvider defaultDelegate(String connectString) {
    // ZooKeeper 3.4.13 and 3.5.5 are have the fixed HostProvider
    if (Info.MAJOR < 3
            || (Info.MAJOR == 3
                && (Info.MINOR < 4
                    || (Info.MINOR == 4 && Info.MICRO < 13)
                    || (Info.MINOR == 5 && Info.MICRO < 5)
                )
            )
    ) {
        return new FixedEnsembleProvider(connectString);
    } else {
        return new ResolvingEnsembleProviderDelegate(connectString);
    }
}
 
Example #9
Source File: ZookeeperAutoConfigurationTests.java    From spring-cloud-zookeeper with Apache License 2.0 4 votes vote down vote up
@Bean
EnsembleProvider ensembleProvider(TestingServer testingServer) {
	return new FixedEnsembleProvider(testingServer.getConnectString());
}
 
Example #10
Source File: CuratorZookeeperClient.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param connectString list of servers to connect to
 * @param sessionTimeoutMs session timeout
 * @param connectionTimeoutMs connection timeout
 * @param watcher default watcher or null
 * @param retryPolicy the retry policy to use
 */
public CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy)
{
    this(new DefaultZookeeperFactory(), new FixedEnsembleProvider(connectString), sessionTimeoutMs, connectionTimeoutMs, watcher, retryPolicy, false);
}
 
Example #11
Source File: CuratorZookeeperClient.java    From curator with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param connectString list of servers to connect to
 * @param sessionTimeoutMs session timeout
 * @param connectionTimeoutMs connection timeout
 * @param watcher default watcher or null
 * @param retryPolicy the retry policy to use
 */
public CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy)
{
    this(new DefaultZookeeperFactory(), new FixedEnsembleProvider(connectString), sessionTimeoutMs, connectionTimeoutMs, watcher, retryPolicy, false);
}