org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient Java Examples
The following examples show how to use
org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient.
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: ZkClient.java From xio with Apache License 2.0 | 6 votes |
public static ZkClient fromExhibitor(Collection<String> serverSet, int restPort) { try { Exhibitors exhibitors = new Exhibitors(serverSet, restPort, () -> ""); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); ExhibitorEnsembleProvider ensemble = new ExhibitorEnsembleProvider( exhibitors, new DefaultExhibitorRestClient(), "/exhibitor/v1/cluster/list", 61000, retryPolicy); ensemble.pollForInitialEnsemble(); CuratorFramework curatorClient = CuratorFrameworkFactory.builder() .ensembleProvider(ensemble) .retryPolicy(retryPolicy) .build(); return new ZkClient(curatorClient); } catch (Exception e) { throw new RuntimeException(e); } }
Example #2
Source File: ZooKeeperHolder.java From nakadi with MIT License | 5 votes |
private EnsembleProvider createEnsembleProvider() throws Exception { switch (conn.getType()) { case EXHIBITOR: final Exhibitors exhibitors = new Exhibitors( conn.getAddresses().stream().map(AddressPort::getAddress).collect(Collectors.toList()), conn.getAddresses().get(0).getPort(), () -> { throw new RuntimeException("There is no backup connection string (or it is wrong)"); }); final ExhibitorRestClient exhibitorRestClient = new DefaultExhibitorRestClient(); final ExhibitorEnsembleProvider result = new ExhibitorEnsembleProvider( exhibitors, exhibitorRestClient, "/exhibitor/v1/cluster/list", EXHIBITOR_POLLING_MS, new ExponentialBackoffRetry(EXHIBITOR_RETRY_TIME, EXHIBITOR_RETRY_MAX)) { @Override public String getConnectionString() { return super.getConnectionString() + conn.getPathPrepared(); } }; result.pollForInitialEnsemble(); return result; case ZOOKEEPER: final String addressesJoined = conn.getAddresses().stream() .map(AddressPort::asAddressPort) .collect(Collectors.joining(",")); return new ChrootedFixedEnsembleProvider(addressesJoined, conn.getPathPrepared()); default: throw new RuntimeException("Connection type " + conn.getType() + " is not supported"); } }
Example #3
Source File: AwsDeployment.java From xio with Apache License 2.0 | 5 votes |
private EnsembleProvider buildEnsembleProvider(ExhibitorConfig config) throws Exception { Exhibitors exhibitors = new Exhibitors(config.getHostnames(), config.getRestPort(), () -> ""); RetryPolicy retryPolicy = buildRetryPolicy(config.getRetryConfig()); ExhibitorEnsembleProvider ensembleProvider = new ExhibitorEnsembleProvider( exhibitors, new DefaultExhibitorRestClient(), config.getRestUriPath(), config.getPollingMs(), retryPolicy); ensembleProvider.pollForInitialEnsemble(); return ensembleProvider; }
Example #4
Source File: ExhibitorCreator.java From exhibitor with Apache License 2.0 | 4 votes |
private CuratorFramework makeCurator(final String connectString, int baseSleepTimeMs, int maxRetries, int exhibitorPort, String exhibitorRestPath, int pollingMs) { List<String> hostnames = Lists.newArrayList(); String[] parts = connectString.split(","); for ( String spec : parts ) { String[] subParts = spec.split(":"); try { if ( subParts.length != 2 ) { log.error("Bad connection string: " + connectString); return null; } } catch ( NumberFormatException e ) { log.error("Bad connection string: " + connectString); return null; } hostnames.add(subParts[0]); } ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(baseSleepTimeMs, maxRetries); Exhibitors.BackupConnectionStringProvider backupConnectionStringProvider = new Exhibitors.BackupConnectionStringProvider() { @Override public String getBackupConnectionString() throws Exception { return connectString; } }; CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory .builder() .connectString(connectString) .retryPolicy(retryPolicy); if ( exhibitorPort > 0 ) { Exhibitors exhibitors = new Exhibitors(hostnames, exhibitorPort, backupConnectionStringProvider); ExhibitorEnsembleProvider ensembleProvider = new ExhibitorEnsembleProvider(exhibitors, new DefaultExhibitorRestClient(), exhibitorRestPath + "exhibitor/v1/cluster/list", pollingMs, retryPolicy); builder = builder.ensembleProvider(ensembleProvider); } else { log.warn("Exhibitor on the shared ZooKeeper config ensemble is not being used."); } return builder.build(); }