/** Builds a new instance. */ protected DelegatingCluster() { // Implementation notes: // If Cluster was an interface, delegates would be trivial to write. But, for historical // reasons, it's a class, // and changing that would break backward compatibility. That makes delegates rather convoluted // and error-prone // to write, so we provide DelegatingCluster to abstract the details. // This class ensures that: // - init() is never called on the parent class, because that would initialize the // Cluster.Manager instance and // create a lot of internal state (thread pools, etc.) that we don't need, since another // Cluster instance is // already handling the calls. // - all public methods are properly forwarded to the delegate (otherwise they would call the // parent class and // return inconsistent results). // These two goals are closely related, since a lot of public methods call init(), so // accidentally calling a // parent method could initialize the parent state. // Construct parent class with dummy parameters that will never get used (since super.init() is // never called). super("delegating_cluster", Collections.<InetSocketAddress>emptyList(), null); // Immediately close the parent class's internal Manager, to make sure that it will fail fast if // it's ever // accidentally invoked. super.closeAsync(); }
@Override public CloseFuture closeAsync() { return delegate().closeAsync(); }
/** * Initiates a shutdown of this cluster instance and blocks until that shutdown completes. * * <p>This method is a shortcut for {@code closeAsync().get()}. */ @Override public void close() { try { closeAsync().get(); } catch (ExecutionException e) { throw DriverThrowables.propagateCause(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
@Override public void destroy() { if (indexManager != null) { indexManager.close(); } if (schemaManager != null) { schemaManager.dropSchema(); } schemaManager = null; externalProperties = null; releaseConnection(this.session); ((Cluster) getConnectionPoolOrConnection()).closeAsync(); }
/** * Validates that a Cluster that was never able to successfully establish connection a session can * be closed properly. * * @test_category connection * @expected_result Cluster closes within 1 second. */ @Test(groups = "short") public void should_be_able_to_close_cluster_that_never_successfully_connected() throws Exception { Cluster cluster = Cluster.builder() .addContactPointsWithPorts(new InetSocketAddress("127.0.0.1", 65534)) .withNettyOptions(nonQuietClusterCloseOptions) .build(); try { cluster.connect(); fail("Should not have been able to connect."); } catch (NoHostAvailableException e) { // Expected. CloseFuture closeFuture = cluster.closeAsync(); try { closeFuture.get(1, TimeUnit.SECONDS); } catch (TimeoutException e1) { fail("Close Future did not complete quickly."); } } finally { cluster.close(); } }
public void closeCluster() { cluster.closeAsync(); }
public void closeCluster() { cluster.closeAsync(); }
private static void closeSession(Session session) { //Close the session to satisfy to avoid warnings for the resource not being closed try { if (session != null) session.getCluster().closeAsync(); } catch (Throwable t) { logger.warn("Error closing connection", t); } }
private static void closeSession(Session session) { //Close the session to satisfy to avoid warnings for the resource not being closed try { if (session != null) session.getCluster().closeAsync(); } catch (Throwable t) { logger.warn("Error closing connection", t); } }
private static void closeSession(Session session) { //Close the session to satisfy to avoid warnings for the resource not being closed try { if (session != null) session.getCluster().closeAsync(); } catch (Throwable t) { logger.warn("Error closing connection", t); } }
@Override public CloseFuture closeAsync() { return delegate().closeAsync(); }
@Override public CloseFuture closeAsync() { return delegate().closeAsync(); }
@Override public CloseFuture closeAsync() { return delegate().closeAsync(); }
/** * Initiates a shutdown of this cluster instance and blocks until * that shutdown completes. * <p/> * This method is a shortcut for {@code closeAsync().get()}. */ @Override public void close() { try { closeAsync().get(); } catch (ExecutionException e) { throw DriverThrowables.propagateCause(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
@PreDestroy public void destroy() { logger.shuttingDownCassandraDriver(); try { sessionFuture.get().getCluster().closeAsync(); } catch (InterruptedException | ExecutionException e) { logger.failedToShutdownDriver(e); } }
@Override public void stop() throws Exception { LOG.debug("Attempting graceful shutdown of Cassandra cluster: {}", cluster.getClusterName()); CloseFuture future = cluster.closeAsync(); try { future.get(shutdownGracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { LOG.warn("Cassandra cluster did not close in {}. Forcing it now.", shutdownGracePeriod); future.force(); } } }
@Override public void stop() throws Exception { LOG.debug("Attempting graceful shutdown of Cassandra cluster: {}", cluster.getClusterName()); CloseFuture future = cluster.closeAsync(); try { future.get(shutdownGracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { LOG.warn("Cassandra cluster did not close in {}. Forcing it now.", shutdownGracePeriod); future.force(); } } }
@Override public void close() { logger.debug("Call to close the session has been made"); if (metrics != null) { metrics.close(); metrics = null; } if (cluster != null) { cluster.closeAsync().force(); cluster = null; session = null; } clusterBuilder = null; }
@Override public void close() { logger.debug("Call to close the session has been made"); if (metrics != null) { metrics.close(); metrics = null; } if (cluster != null) { cluster.closeAsync().force(); cluster = null; session = null; } clusterBuilder = null; }
@Test public void testClose() throws Exception { cassandraSession.close(); verify(cluster).closeAsync(); verify(closeFuture).force(); } }