Java Code Examples for com.datastax.driver.core.Session#isClosed()

The following examples show how to use com.datastax.driver.core.Session#isClosed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraStore.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
protected void initKeyspace() {
    Statement stmt = SchemaBuilder.createKeyspace(this.keyspace)
                                  .ifNotExists().with()
                                  .replication(parseReplica(this.conf));
    // Create keyspace with non-keyspace-session
    LOG.debug("Create keyspace: {}", stmt);
    Session session = this.cluster().connect();
    try {
        session.execute(stmt);
    } finally {
        if (!session.isClosed()) {
            session.close();
        }
    }
}
 
Example 2
Source File: CassandraStore.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
protected void clearKeyspace() {
    // Drop keyspace with non-keyspace-session
    Statement stmt = SchemaBuilder.dropKeyspace(this.keyspace).ifExists();
    LOG.debug("Drop keyspace: {}", stmt);

    Session session = this.cluster().connect();
    try {
        session.execute(stmt);
    } finally {
        if (!session.isClosed()) {
            session.close();
        }
    }
}
 
Example 3
Source File: CassandraHelper.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** Closes Cassandra driver session. */
public static void closeSession(Session driverSes) {
    if (driverSes == null)
        return;

    Cluster cluster = driverSes.getCluster();

    if (!driverSes.isClosed())
        U.closeQuiet(driverSes);

    if (!cluster.isClosed())
        U.closeQuiet(cluster);
}
 
Example 4
Source File: IsConnected.java    From Karaf-Cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public Object doExecute() throws Exception {

	Session session = (Session) this.session
			.get(SessionParameter.CASSANDRA_SESSION);

	boolean isActive = (session != null && !session.isClosed());

	String loggedKeyspace = "";

	if (isActive)
		loggedKeyspace = session.getLoggedKeyspace();

	if (loggedKeyspace == null || loggedKeyspace.isEmpty())
		System.out.println(isActive);
	else
		System.out.println(isActive + ": " + loggedKeyspace);


	return null;
}