com.datastax.driver.core.Cluster.closeAsync()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中com.datastax.driver.core.Cluster.closeAsync()方法的一些代码示例,展示了Cluster.closeAsync()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.closeAsync()方法的具体详情如下:
包路径:com.datastax.driver.core.Cluster
类名称:Cluster
方法名:closeAsync

Cluster.closeAsync介绍

[英]Initiates a shutdown of this cluster instance.

This method is asynchronous and return a future on the completion of the shutdown process. As soon a the cluster is shutdown, no new request will be accepted, but already submitted queries are allowed to complete. This method closes all connections from all sessions and reclaims all resources used by this Cluster instance.

If for some reason you wish to expedite this process, the CloseFuture#force can be called on the result future.

This method has no particular effect if the cluster was already closed (in which case the returned future will return immediately).
[中]启动此群集实例的关闭。
此方法是异步的,并在关闭过程完成时返回未来。一旦集群关闭,将不会接受新请求,但允许完成已提交的查询。此方法关闭所有会话的所有连接,并回收此群集实例使用的所有资源。
如果出于某种原因,你希望加快这一进程,那么可以在未来的结果上调用CloseFuture#force。
如果集群已经关闭(在这种情况下,返回的未来将立即返回),则此方法没有特别的效果。

代码示例

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/** 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();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
public CloseFuture closeAsync() {
 return delegate().closeAsync();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * 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();
 }
}

代码示例来源:origin: Impetus/Kundera

@Override
public void destroy()
{
  if (indexManager != null)
  {
    indexManager.close();
  }
  if (schemaManager != null)
  {
    schemaManager.dropSchema();
  }
  schemaManager = null;
  externalProperties = null;
  releaseConnection(this.session);
  ((Cluster) getConnectionPoolOrConnection()).closeAsync();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * 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();
 }
}

代码示例来源:origin: org.apache.james/apache-james-backends-cassandra

public void closeCluster() {
  cluster.closeAsync();
}

代码示例来源:origin: apache/james-project

public void closeCluster() {
  cluster.closeAsync();
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

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);
  }
}

代码示例来源:origin: jsevellec/cassandra-unit

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);
  }
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

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);
  }
}

代码示例来源:origin: com.yugabyte/cassandra-driver-core

@Override
public CloseFuture closeAsync() {
  return delegate().closeAsync();
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver

@Override
public CloseFuture closeAsync() {
  return delegate().closeAsync();
}

代码示例来源:origin: io.prestosql.cassandra/cassandra-driver

@Override
public CloseFuture closeAsync() {
  return delegate().closeAsync();
}

代码示例来源:origin: io.prestosql.cassandra/cassandra-driver

/**
 * 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();
  }
}

代码示例来源:origin: org.hawkular.accounts/hawkular-accounts-api

@PreDestroy
public void destroy() {
  logger.shuttingDownCassandraDriver();
  try {
    sessionFuture.get().getCluster().closeAsync();
  } catch (InterruptedException | ExecutionException e) {
    logger.failedToShutdownDriver(e);
  }
}

代码示例来源:origin: systems.composable/dropwizard-cassandra

@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();
    }
  }
}

代码示例来源:origin: composable-systems/dropwizard-cassandra

@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();
    }
  }
}

代码示例来源:origin: com.englishtown.vertx/vertx-cassandra

@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;
}

代码示例来源:origin: com.englishtown/vertx-mod-cassandra

@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;
}

代码示例来源:origin: ef-labs/vertx-cassandra

@Test
  public void testClose() throws Exception {
    cassandraSession.close();
    verify(cluster).closeAsync();
    verify(closeFuture).force();
  }
}

相关文章