public class DseCluster extends DelegatingCluster
Cluster
object with DSE-specific
features. A simple example of access to a DSE cluster would be:
DseCluster cluster = DseCluster.builder().addContactPoint("192.168.0.1").build(); DseSession session = cluster.connect("db1"); for (Row row : session.execute("SELECT * FROM table1")) // do something ...
Modifier and Type | Class and Description |
---|---|
static class |
DseCluster.Builder
Helper class to build
DseCluster instances. |
Cluster.Initializer
Modifier and Type | Method and Description |
---|---|
static DseCluster.Builder |
builder()
Creates a new
DseCluster.Builder instance. |
DseSession |
connect()
Creates a new DSE session on this cluster and initializes it.
|
DseSession |
connect(String keyspace)
Creates a new DSE session on this cluster, initializes it and sets the
keyspace to the provided one.
|
ListenableFuture<Session> |
connectAsync()
Creates a new DSE session on this cluster and initializes it asynchronously.
|
ListenableFuture<Session> |
connectAsync(String keyspace)
Creates a new DSE session on this cluster, and initializes it to the given
keyspace asynchronously.
|
protected Cluster |
delegate()
Returns the delegate instance where all calls will be forwarded.
|
DseConfiguration |
getConfiguration()
The cluster configuration.
|
static String |
getDseDriverVersion()
Returns the current version of the DSE driver.
|
DseSession |
newSession()
Creates a new DSE session on this cluster but does not initialize it.
|
close, closeAsync, getMetadata, getMetrics, init, isClosed, register, register, register, unregister, unregister, unregister
buildFrom, getClusterName, getDriverVersion, logDriverVersion
public static String getDseDriverVersion()
Cluster.getDriverVersion()
;
both return exactly the same version.public static DseCluster.Builder builder()
DseCluster.Builder
instance.
This is a convenience method for new GraphCluster.Builder()
.public DseConfiguration getConfiguration()
Cluster
getConfiguration
in class DelegatingCluster
protected Cluster delegate()
DelegatingCluster
delegate
in class DelegatingCluster
public DseSession newSession()
DseSession.init()
method is
called explicitly, or whenever the returned object is used.
Once a session returned by this method gets initialized (see above), it
will be set to no keyspace. If you want to set such session to a
keyspace, you will have to explicitly execute a 'USE mykeyspace' query.
Note that if you do not particularly need to defer initialization, it is
simpler to use one of the connect()
methods of this class.newSession
in class DelegatingCluster
public DseSession connect()
newSession()
.connect
in class DelegatingCluster
NoHostAvailableException
- if the Cluster has not been initialized
yet (DelegatingCluster.init()
has not be called and this is the first connect call)
and no host amongst the contact points can be reached.AuthenticationException
- if an authentication error occurs while
contacting the initial contact points.IllegalStateException
- if the Cluster was closed prior to calling
this method. This can occur either directly (through DelegatingCluster.close()
or
DelegatingCluster.closeAsync()
), or as a result of an error while initializing the
Cluster.public DseSession connect(String keyspace)
newSession()
.
The keyspace set through this method is only valid for CQL queries; for graph queries, the graph to target is
determined by the graph name specified via GraphStatement.setGraphName(String)
} or
GraphOptions.setGraphName(String)
.connect
in class DelegatingCluster
keyspace
- the name of the keyspace to use for the created DseSession
.keyspace
.NoHostAvailableException
- if the Cluster has not been initialized
yet (DelegatingCluster.init()
has not be called and this is the first connect call)
and no host amongst the contact points can be reached, or if no host can
be contacted to set the keyspace
.AuthenticationException
- if an authentication error occurs while
contacting the initial contact points.InvalidQueryException
- if the keyspace does not exist.IllegalStateException
- if the Cluster was closed prior to calling
this method. This can occur either directly (through DelegatingCluster.close()
or
DelegatingCluster.closeAsync()
), or as a result of an error while initializing the
Cluster.public ListenableFuture<Session> connectAsync()
Cluster
if needed; note that cluster
initialization happens synchronously on the thread that called this method.
Therefore it is recommended to initialize the cluster at application
startup, and not rely on this method to do it.
The Session
object returned by the future's get
method can be safely cast
to DseSession
.connectAsync
in class DelegatingCluster
NoHostAvailableException
- if the Cluster has not been initialized
yet (DelegatingCluster.init()
has not been called and this is the first connect call)
and no host amongst the contact points can be reached.IllegalStateException
- if the Cluster was closed prior to calling
this method. This can occur either directly (through DelegatingCluster.close()
or
DelegatingCluster.closeAsync()
), or as a result of an error while initializing the
Cluster.connect()
public ListenableFuture<Session> connectAsync(String keyspace)
Cluster
if needed; note that cluster
initialization happens synchronously on the thread that called this method.
Therefore it is recommended to initialize the cluster at application
startup, and not rely on this method to do it.
The keyspace set through this method is only valid for CQL queries; for graph queries, the graph to target is
determined by the graph name specified via GraphStatement.setGraphName(String)
} or
GraphOptions.setGraphName(String)
.
The Session
object returned by the future's get
method can be safely cast
to DseSession
.connectAsync
in class DelegatingCluster
keyspace
- The name of the keyspace to use for the created
Session
.NoHostAvailableException
- if the Cluster has not been initialized
yet (DelegatingCluster.init()
has not been called and this is the first connect call)
and no host amongst the contact points can be reached.IllegalStateException
- if the Cluster was closed prior to calling
this method. This can occur either directly (through DelegatingCluster.close()
or
DelegatingCluster.closeAsync()
), or as a result of an error while initializing the
Cluster.Copyright © 2012–2018. All rights reserved.