@Override public void close() throws IOException { if (zkStateReader != null && closeZkStateReader) { synchronized (this) { if (zkStateReader != null) zkStateReader.close(); zkStateReader = null; } } }
@Override public void connect() { if (zkStateReader == null) { synchronized (this) { if (zkStateReader == null) { ZkStateReader zk = null; try { zk = new ZkStateReader(zkHost, zkClientTimeout, zkConnectTimeout); zk.createClusterStateWatchersAndUpdate(); zkStateReader = zk; log.info("Cluster at {} ready", zkHost); } catch (InterruptedException e) { zk.close(); Thread.currentThread().interrupt(); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } catch (KeeperException e) { zk.close(); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } catch (Exception e) { if (zk != null) zk.close(); // do not wrap because clients may be relying on the underlying exception being thrown throw e; } } } } }
@Override @Deprecated public void shutdown() { if (zkStateReader != null) { synchronized(this) { if (zkStateReader!= null) zkStateReader.close(); zkStateReader = null; } } if (shutdownLBHttpSolrServer) { lbClient.shutdown(); } if (clientIsInternal && myClient!=null) { HttpClientUtil.close(myClient); } if(this.threadPool != null && !this.threadPool.isShutdown()) { this.threadPool.shutdown(); } }
/** * Connect to the zookeeper ensemble. * This is an optional method that may be used to force a connect before any other requests are sent. * */ public void connect() { if (zkStateReader == null) { synchronized (this) { if (zkStateReader == null) { ZkStateReader zk = null; try { zk = new ZkStateReader(zkHost, zkClientTimeout, zkConnectTimeout); zk.createClusterStateWatchersAndUpdate(); zkStateReader = zk; } catch (InterruptedException e) { zk.close(); Thread.currentThread().interrupt(); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } catch (KeeperException e) { zk.close(); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } catch (Exception e) { if (zk != null) zk.close(); // do not wrap because clients may be relying on the underlying exception being thrown throw e; } } } } }