ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( new TephraZKClientService(zkQuorumServersString, timeOut, null, ArrayListMultimap.<String, byte[]>create()), RetryStrategies.exponentialDelay(500, retryTimeOut, TimeUnit.MILLISECONDS))
/** * Create a new instance. * @param zkStr zookeper connection string * @param sessionTimeout timeout in milliseconds * @param connectionWatcher watcher to set * @param authInfos authorization bytes */ public TephraZKClientService(String zkStr, int sessionTimeout, Watcher connectionWatcher, Multimap<String, byte[]> authInfos) { this.zkStr = zkStr; this.sessionTimeout = sessionTimeout; this.connectionWatchers = new CopyOnWriteArrayList<>(); this.authInfos = copyAuthInfo(authInfos); addConnectionWatcher(connectionWatcher); this.zooKeeper = new AtomicReference<>(); this.stopTask = createStopTask(); }
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent) { return create(path, data, createMode, createParent, ZooDefs.Ids.OPEN_ACL_UNSAFE); }
@Override protected void doStart() { // A single thread executor for all events ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), Threads.createDaemonThreadFactory("zk-client-EventThread")); // Just discard the execution if the executor is closed executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); eventExecutor = executor; try { zooKeeper.set(createZooKeeper()); } catch (IOException e) { notifyFailed(e); } }
@Override public OperationFuture<Stat> exists(String path) { return exists(path, null); }
@Override public OperationFuture<String> delete(String path) { return delete(path, -1); }
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, boolean createParent, Iterable<ACL> acl) { return doCreate(path, data, createMode, createParent, ImmutableList.copyOf(acl), false); }
@Provides @Singleton private ZKClientService provideZKClientService(Configuration conf) { String zkStr = conf.get(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM); if (zkStr == null) { // Default to HBase one. zkStr = conf.get(TxConstants.HBase.ZOOKEEPER_QUORUM); } int timeOut = conf.getInt(TxConstants.HBase.ZK_SESSION_TIMEOUT, TxConstants.HBase.DEFAULT_ZK_SESSION_TIMEOUT); ZKClientService zkClientService = new TephraZKClientService(zkStr, timeOut, null, ArrayListMultimap.<String, byte[]>create()); return ZKClientServices.delegate( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure(zkClientService, RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS) ) ) ); } }
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode, Iterable<ACL> acl) { return create(path, data, createMode, true, acl); }
ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( new TephraZKClientService(zkQuorumServersString, timeOut, null, ArrayListMultimap.<String, byte[]>create()), RetryStrategies.exponentialDelay(500, retryTimeOut, TimeUnit.MILLISECONDS))
@Override public OperationFuture<String> create(String path, @Nullable byte[] data, CreateMode createMode) { return create(path, data, createMode, true); }
ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( new TephraZKClientService(zkQuorumServersString, timeOut, null, ArrayListMultimap.<String, byte[]>create()), RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))