/** * Allows package private classes to update volatile ZooKeeper. */ void updateKeeper(SolrZooKeeper keeper) throws InterruptedException { SolrZooKeeper oldKeeper = this.keeper; this.keeper = keeper; if (oldKeeper != null) { oldKeeper.close(); } // we might have been closed already if (isClosed) this.keeper.close(); }
@Override public Stat execute() throws KeeperException, InterruptedException { keeper.delete(path, version); return null; } });
@Override public Stat execute() throws KeeperException, InterruptedException { return keeper.exists(path, wrapWatcher(watcher)); } });
protected SolrZooKeeper createSolrZooKeeper(final String serverAddress, final int zkClientTimeout, final Watcher watcher) throws IOException { SolrZooKeeper result = new SolrZooKeeper(serverAddress, zkClientTimeout, watcher); zkCredentialsToAddAutomaticallyUsed = true; for (ZkCredentials zkCredentials : zkCredentialsToAddAutomatically.getCredentials()) { result.addAuthInfo(zkCredentials.getScheme(), zkCredentials.getAuth()); } return result; }
@Override public Object execute() throws KeeperException, InterruptedException { keeper.create(currentPath, finalBytes, zkACLProvider.getACLsToAdd(currentPath), finalMode); return null; } });
@Override public byte[] execute() throws KeeperException, InterruptedException { return keeper.getData(path, wrapWatcher(watcher), stat); } });
@Override public List<String> execute() throws KeeperException, InterruptedException { return keeper.getChildren(path, wrapWatcher(watcher)); } });
/** * Returns true if client is connected */ public boolean isConnected() { return keeper != null && keeper.getState() == ZooKeeper.States.CONNECTED; }
@SuppressForbidden(reason = "Hack for Zookeper needs access to private methods.") private Void closeZookeeperChannel() { final ClientCnxn cnxn = getConnection(); synchronized (cnxn) { try { final Field sendThreadFld = cnxn.getClass().getDeclaredField("sendThread"); sendThreadFld.setAccessible(true); Object sendThread = sendThreadFld.get(cnxn); if (sendThread != null) { Method method = sendThread.getClass().getDeclaredMethod("testableCloseSocket"); method.setAccessible(true); try { method.invoke(sendThread); } catch (InvocationTargetException e) { // is fine } } } catch (Exception e) { throw new RuntimeException("Closing Zookeeper send channel failed.", e); } } return null; // Void } };
protected SolrZooKeeper createSolrZooKeeper(final String serverAddress, final int zkClientTimeout, final Watcher watcher) throws IOException { SolrZooKeeper result = new SolrZooKeeper(serverAddress, zkClientTimeout, watcher); zkCredentialsToAddAutomaticallyUsed = true; for (ZkCredentials zkCredentials : zkCredentialsToAddAutomatically.getCredentials()) { result.addAuthInfo(zkCredentials.getScheme(), zkCredentials.getAuth()); } return result; }
@Override public String execute() throws KeeperException, InterruptedException { return keeper.create(path, data, zkACLProvider.getACLsToAdd(path), createMode); } });
/** * Returns node's data */ public byte[] getData(final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(() -> keeper.getData(path, wrapWatcher(watcher), stat)); } else { return keeper.getData(path, wrapWatcher(watcher), stat); } }
/** * Returns children of the node at the path */ public List<String> getChildren(final String path, final Watcher watcher, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(() -> keeper.getChildren(path, wrapWatcher(watcher))); } else { return keeper.getChildren(path, wrapWatcher(watcher)); } }
/** * Returns true if client is connected */ public boolean isConnected() { return keeper != null && keeper.getState() == ZooKeeper.States.CONNECTED; }
@Override public void run() { try { final ClientCnxn cnxn = getConnection(); synchronized (cnxn) { try { final Field sendThreadFld = cnxn.getClass().getDeclaredField("sendThread"); sendThreadFld.setAccessible(true); Object sendThread = sendThreadFld.get(cnxn); if (sendThread != null) { Method method = sendThread.getClass().getDeclaredMethod("testableCloseSocket"); method.setAccessible(true); try { method.invoke(sendThread); } catch (InvocationTargetException e) { // is fine } } } catch (Exception e) { throw new RuntimeException("Closing Zookeeper send channel failed.", e); } } } finally { spawnedThreads.remove(this); } } };
/** * Allows package private classes to update volatile ZooKeeper. */ void updateKeeper(SolrZooKeeper keeper) throws InterruptedException { SolrZooKeeper oldKeeper = this.keeper; this.keeper = keeper; if (oldKeeper != null) { oldKeeper.close(); } // we might have been closed already if (isClosed) this.keeper.close(); }
@Override public Boolean execute() throws KeeperException, InterruptedException { return keeper.exists(path, null) != null; } });
/** * Returns path of created node */ public String create(final String path, final byte[] data, final CreateMode createMode, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(() -> keeper.create(path, data, zkACLProvider.getACLsToAdd(path), createMode)); } else { List<ACL> acls = zkACLProvider.getACLsToAdd(path); return keeper.create(path, data, acls, createMode); } }
/** * Returns node's data */ public byte[] getData(final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(new ZkOperation() { @Override public byte[] execute() throws KeeperException, InterruptedException { return keeper.getData(path, wrapWatcher(watcher), stat); } }); } else { return keeper.getData(path, wrapWatcher(watcher), stat); } }