@Override public void register(Watcher watcher) { delegate.register(watcher); }
@Override public void register(Watcher watcher) { delegate.register(watcher); }
@Override public void register(Watcher watcher) { _zk.register(watcher); }
@Override public void register(Watcher watcher) { delegate.register(watcher); }
public void register(final Watcher watcher) { zooKeeper.register(watcher); }
@Override public void register(Watcher watcher) { getZk().register(watcher); }
@Override public void register(Watcher watcher) { getDelegate().register(watcher); }
public void start() throws IOException { CompletableFuture<ZooKeeper> zkFuture = zlClientFactory.create(globalZkConnect, SessionType.AllowReadOnly, zkSessionTimeoutMillis); // Initial session creation with global ZK must work try { ZooKeeper newSession = zkFuture.get(10, TimeUnit.SECONDS); // Register self as a watcher to receive notification when session expires and trigger a new session to be // created newSession.register(this); zkSession.set(newSession); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.error("Failed to establish global zookeeper session: {}", e.getMessage(), e); throw new IOException(e); } }
private void internalClose() throws Exception { try { ZooKeeper zooKeeper = (helper != null) ? helper.getZooKeeper() : null; if ( zooKeeper != null ) { Watcher dummyWatcher = new Watcher() { @Override public void process(WatchedEvent event) { } }; zooKeeper.register(dummyWatcher); // clear the default watcher so that no new events get processed by mistake zooKeeper.close(); } } catch ( InterruptedException dummy ) { Thread.currentThread().interrupt(); } } }
private void internalClose() throws Exception { try { ZooKeeper zooKeeper = (helper != null) ? helper.getZooKeeper() : null; if ( zooKeeper != null ) { Watcher dummyWatcher = new Watcher() { @Override public void process(WatchedEvent event) { } }; zooKeeper.register(dummyWatcher); // clear the default watcher so that no new events get processed by mistake zooKeeper.close(); } } catch ( InterruptedException dummy ) { Thread.currentThread().interrupt(); } } }
private void internalClose() throws Exception { try { ZooKeeper zooKeeper = (helper != null) ? helper.getZooKeeper() : null; if ( zooKeeper != null ) { Watcher dummyWatcher = new Watcher() { @Override public void process(WatchedEvent event) { } }; zooKeeper.register(dummyWatcher); // clear the default watcher so that no new events get processed by mistake zooKeeper.close(); } } catch ( InterruptedException dummy ) { Thread.currentThread().interrupt(); } } }
private void internalClose() throws Exception { try { ZooKeeper zooKeeper = (helper != null) ? helper.getZooKeeper() : null; if ( zooKeeper != null ) { Watcher dummyWatcher = new Watcher() { @Override public void process(WatchedEvent event) { } }; zooKeeper.register(dummyWatcher); // clear the default watcher so that no new events get processed by mistake zooKeeper.close(); } } catch ( InterruptedException dummy ) { Thread.currentThread().interrupt(); } } }
@Override @Synchronized public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception { // prevent creating a new client, stick to the same client created earlier // this trick prevents curator from re-creating ZK client on session expiry if (client == null) { Exceptions.checkNotNullOrEmpty(connectString, "connectString"); Preconditions.checkArgument(sessionTimeout > 0, "sessionTimeout should be a positive integer"); Preconditions.checkNotNull(watcher, "watcher"); this.connectString = connectString; this.sessionTimeout = sessionTimeout; this.canBeReadOnly = canBeReadOnly; this.client = new ZooKeeper(connectString, sessionTimeout, watcher, canBeReadOnly); return this.client; } else { Preconditions.checkArgument(this.connectString.equals(connectString), "connectString differs"); Preconditions.checkArgument(this.sessionTimeout == sessionTimeout, "sessionTimeout differs"); Preconditions.checkArgument(this.canBeReadOnly == canBeReadOnly, "canBeReadOnly differs"); Preconditions.checkNotNull(watcher, "watcher"); this.client.register(watcher); return this.client; } } }
zooKeeper.register(dummyWatcher); // clear the default watcher so that no new events get processed by mistake if ( waitForShutdownTimeoutMs == 0 )
@VisibleForTesting @Private @Unstable protected synchronized ZooKeeper getNewZooKeeper() throws IOException, InterruptedException { ZooKeeper zk = new ZooKeeper(zkHostPort, zkSessionTimeout, null); zk.register(new ForwardingWatcher(zk)); return zk; }
@Override public void setSessionStateListener(SessionStateListener sessionStateListener) { zk.register((event) -> { // Check for expired connection. if (event.getType().equals(EventType.None) && event.getState().equals(KeeperState.Expired)) { sessionStateListener.onSessionExpired(); } }); } }
@VisibleForTesting @Private @Unstable protected synchronized ZooKeeper getNewZooKeeper() throws IOException, InterruptedException { ZooKeeper zk = new ZooKeeper(zkHostPort, zkSessionTimeout, null); zk.register(new ForwardingWatcher(zk)); return zk; }
public ZooKeeperConnection(String quorumAddresses) throws IOException { this.zookeeper = connect(quorumAddresses); this.quorumAddresses = quorumAddresses; zookeeper.register(new ConnectionWatcher(this)); }
public void start(ShutdownService shutdownService) throws IOException { // Connect to local ZK CompletableFuture<ZooKeeper> zkFuture = zkClientFactory.create(zkConnect, SessionType.ReadWrite, (int) zkSessionTimeoutMillis); try { localZooKeeper = zkFuture.get(zkSessionTimeoutMillis, TimeUnit.MILLISECONDS); localZooKeeperSessionWatcher = new ZooKeeperSessionWatcher(localZooKeeper, zkSessionTimeoutMillis, shutdownService); localZooKeeperSessionWatcher.start(); localZooKeeper.register(localZooKeeperSessionWatcher); } catch (Exception e) { throw new IOException("Failed to establish session with local ZK", e); } }
public ZKRegistrationManager(ServerConfiguration conf, ZooKeeper zk, String ledgersRootPath, RegistrationListener listener) { this.conf = conf; this.zk = zk; this.zkAcls = ZkUtils.getACLs(conf); this.ledgersRootPath = ledgersRootPath; this.cookiePath = ledgersRootPath + "/" + COOKIE_NODE; this.bookieRegistrationPath = ledgersRootPath + "/" + AVAILABLE_NODE; this.bookieReadonlyRegistrationPath = this.bookieRegistrationPath + "/" + READONLY; this.zkTimeoutMs = conf.getZkTimeout(); this.layoutManager = new ZkLayoutManager( zk, ledgersRootPath, zkAcls); this.zk.register(event -> { if (!zkRegManagerInitialized) { // do nothing until first registration return; } // Check for expired connection. if (event.getType().equals(EventType.None) && event.getState().equals(KeeperState.Expired)) { listener.onRegistrationExpired(); } }); }