@Override @SneakyThrows(BKException.class) public void close() { this.logFactory.close(); this.zkClient.close(); // There is no need to close the BK Admin object since it doesn't own anything; however it does have a close() // method and it's a good idea to invoke it. Exceptions.handleInterrupted(this.bkAdmin::close); } }
@Override protected void shutDown() { this.logs.values().forEach(DurableDataLog::close); this.logs.clear(); BookKeeperLogFactory lf = this.logFactory; if (lf != null) { lf.close(); this.logFactory = null; } stopBookKeeper(); CuratorFramework zkClient = this.zkClient; if (zkClient != null) { zkClient.close(); this.zkClient = null; } Runtime.getRuntime().removeShutdownHook(this.stopBookKeeperProcess); }
@Override public void initialize() throws DurableDataLogException { Preconditions.checkState(this.bookKeeper.get() == null, "BookKeeperLogFactory is already initialized."); try { this.bookKeeper.set(startBookKeeperClient()); } catch (IllegalArgumentException | NullPointerException ex) { // Most likely a configuration issue; re-throw as is. close(); throw ex; } catch (Throwable ex) { if (!Exceptions.mustRethrow(ex)) { // Make sure we close anything we may have opened. close(); } // ZooKeeper not reachable, some other environment issue. throw new DataLogNotAvailableException("Unable to establish connection to ZooKeeper or BookKeeper.", ex); } }
@After public void tearDown() { val factory = this.factory.getAndSet(null); if (factory != null) { factory.close(); } val zkClient = this.zkClient.getAndSet(null); if (zkClient != null) { zkClient.close(); } }