ZKClients.reWatchOnExpire( ZKClients.retryOnFailure(zkClientService, RetryStrategies.limit(5, RetryStrategies.fixDelay(5, TimeUnit.SECONDS))));
@Override public void start() { Preconditions.checkNotNull(zkConnectStr); eventConverter = new LogEventConverter(hostname, runnableName); scheduler = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory(PUBLISH_THREAD_NAME)); zkClientService = ZKClientServices.delegate( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure(ZKClientService.Builder.of(zkConnectStr).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS)))); kafkaClient = new ZKKafkaClientService(zkClientService); Futures.addCallback(Services.chainStart(zkClientService, kafkaClient), new FutureCallback<List<ListenableFuture<Service.State>>>() { @Override public void onSuccess(List<ListenableFuture<Service.State>> result) { for (ListenableFuture<Service.State> future : result) { Preconditions.checkState(Futures.getUnchecked(future) == Service.State.RUNNING, "Service is not running."); } addInfo("Kafka client started: " + zkConnectStr); scheduler.scheduleWithFixedDelay(flushTask, 0, flushPeriod, TimeUnit.MILLISECONDS); } @Override public void onFailure(Throwable t) { // Fail to talk to kafka. Other than logging, what can be done? addError("Failed to start kafka appender.", t); } }, Threads.SAME_THREAD_EXECUTOR); super.start(); }
@Override public void start() { Preconditions.checkNotNull(zkConnectStr); eventConverter = new LogEventConverter(hostname, runnableName); scheduler = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory(PUBLISH_THREAD_NAME)); zkClientService = ZKClientServices.delegate( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure(ZKClientService.Builder.of(zkConnectStr).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS)))); kafkaClient = new ZKKafkaClientService(zkClientService); Futures.addCallback(Services.chainStart(zkClientService, kafkaClient), new FutureCallback<List<ListenableFuture<Service.State>>>() { @Override public void onSuccess(List<ListenableFuture<Service.State>> result) { for (ListenableFuture<Service.State> future : result) { Preconditions.checkState(Futures.getUnchecked(future) == Service.State.RUNNING, "Service is not running."); } addInfo("Kafka client started: " + zkConnectStr); scheduler.scheduleWithFixedDelay(flushTask, 0, flushPeriod, TimeUnit.MILLISECONDS); } @Override public void onFailure(Throwable t) { // Fail to talk to kafka. Other than logging, what can be done? addError("Failed to start kafka appender.", t); } }, Threads.SAME_THREAD_EXECUTOR); super.start(); }
private ZKClientService getZKService(String connectString) { return ZKClientServices.delegate( ZKClients.namespace( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( ZKClientService.Builder.of(connectString) .setSessionTimeout(conf.getInt(Constants.ZOOKEEPER_SESSION_TIMEOUT_MILLIS)) .build(), RetryStrategies.fixDelay(2, TimeUnit.SECONDS) ) ), conf.get(Constants.ZOOKEEPER_NAMESPACE) ) ); } }
/** * Creates a {@link ZKClientService}. */ protected final ZKClientService createZKClient() { TwillRuntimeSpecification twillRuntimeSpec = getTwillRuntimeSpecification(); return ZKClientServices.delegate( ZKClients.namespace( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( ZKClientService.Builder.of(twillRuntimeSpec.getZkConnectStr()).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS) ) ), "/" + twillRuntimeSpec.getTwillAppName() ) ); }
/** * Creates a {@link ZKClientService}. */ protected final ZKClientService createZKClient() { TwillRuntimeSpecification twillRuntimeSpec = getTwillRuntimeSpecification(); return ZKClientServices.delegate( ZKClients.namespace( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( ZKClientService.Builder.of(twillRuntimeSpec.getZkConnectStr()).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS) ) ), "/" + twillRuntimeSpec.getTwillAppName() ) ); }
.setSessionTimeout(conf.getInt(Constants.ZOOKEEPER_SESSION_TIMEOUT_MILLIS)) .build(), RetryStrategies.fixDelay(2, TimeUnit.SECONDS)