public abstract class DelegatingCluster extends Cluster
Cluster
implementations that wrap another instance (delegate / decorator pattern).Cluster.Builder, Cluster.Initializer
Modifier | Constructor and Description |
---|---|
protected |
DelegatingCluster()
Builds a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Initiates a shutdown of this cluster instance and blocks until
that shutdown completes.
|
CloseFuture |
closeAsync()
Initiates a shutdown of this cluster instance.
|
Session |
connect()
Creates a new session on this cluster and initialize it.
|
Session |
connect(String keyspace)
Creates a new session on this cluster, initialize it and sets the
keyspace to the provided one.
|
ListenableFuture<Session> |
connectAsync()
Creates a new session on this cluster and initializes it asynchronously.
|
ListenableFuture<Session> |
connectAsync(String keyspace)
Creates a new session on this cluster, and initializes it to the given
keyspace asynchronously.
|
protected abstract Cluster |
delegate()
Returns the delegate instance where all calls will be forwarded.
|
Configuration |
getConfiguration()
The cluster configuration.
|
Metadata |
getMetadata()
Returns read-only metadata on the connected cluster.
|
Metrics |
getMetrics()
The cluster metrics.
|
Cluster |
init()
Initialize this Cluster instance.
|
boolean |
isClosed()
Whether this Cluster instance has been closed.
|
Session |
newSession()
Creates a new session on this cluster but does not initialize it.
|
Cluster |
register(Host.StateListener listener)
Registers the provided listener to be notified on hosts
up/down/added/removed events.
|
Cluster |
register(LatencyTracker tracker)
Registers the provided tracker to be updated with hosts read
latencies.
|
Cluster |
register(SchemaChangeListener listener)
Registers the provided listener to be updated with schema change events.
|
Cluster |
unregister(Host.StateListener listener)
Unregisters the provided listener from being notified on hosts events.
|
Cluster |
unregister(LatencyTracker tracker)
Unregisters the provided latency tracking from being updated
with host read latencies.
|
Cluster |
unregister(SchemaChangeListener listener)
Unregisters the provided schema change listener from being updated
with schema change events.
|
builder, buildFrom, getClusterName, getDriverVersion
protected abstract Cluster delegate()
public Cluster init()
Cluster
Cluster
instance. That connection is then
used to populate the cluster Metadata
.
Calling this method is optional in the sense that any call to one of the
connect
methods of this object will automatically trigger a call
to this method beforehand. It is thus only useful to call this method if
for some reason you want to populate the metadata (or test that at least
one contact point can be reached) without creating a first Session
.
Please note that this method only creates one control connection for
gathering cluster metadata. In particular, it doesn't create any connection pools.
Those are created when a new Session
is created through
connect
.
This method has no effect if the cluster is already initialized.public Session newSession()
Cluster
Session.init()
method is
called explicitly, or whenever the returned session 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()
method of this class.newSession
in class Cluster
public Session connect()
Cluster
Cluster.newSession()
.public Session connect(String keyspace)
Cluster
Cluster.newSession()
.public ListenableFuture<Session> connectAsync()
Cluster
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.connectAsync
in class Cluster
Cluster.connect()
public ListenableFuture<Session> connectAsync(String keyspace)
Cluster
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.connectAsync
in class Cluster
keyspace
- The name of the keyspace to use for the created
Session
.public Metadata getMetadata()
Cluster
init()
nor connect()
has been called yet).getMetadata
in class Cluster
public Configuration getConfiguration()
Cluster
getConfiguration
in class Cluster
public Metrics getMetrics()
Cluster
getMetrics
in class Cluster
null
if this cluster has not yet been initialized
, or if
metrics collection has been disabled (that is if Configuration.getMetricsOptions()
returns null
).public Cluster register(Host.StateListener listener)
Cluster
Cluster.Builder.withInitialListeners(Collection)
.
Calling this method on a non-initialized cluster
will result in the listener being
notified
twice of cluster registration: once inside this method, and once at cluster initialization.register
in class Cluster
listener
- the new Host.StateListener
to register.Cluster
object;public Cluster unregister(Host.StateListener listener)
Cluster
listener
hasn't previously been
registered against this Cluster.unregister
in class Cluster
listener
- the Host.StateListener
to unregister.Cluster
object;public Cluster register(LatencyTracker tracker)
Cluster
update
method will be called
very frequently (at the end of every query to a Cassandra host) and
should thus not be costly.
The main use case for a LatencyTracker
is to allow
load balancing policies to implement latency awareness.
For example, LatencyAwarePolicy
registers it's own internal
LatencyTracker
(automatically, you don't have to call this
method directly).register
in class Cluster
tracker
- the new LatencyTracker
to register.Cluster
object;public Cluster unregister(LatencyTracker tracker)
Cluster
tracker
hasn't previously been
registered against this Cluster.unregister
in class Cluster
tracker
- the LatencyTracker
to unregister.Cluster
object;public Cluster register(SchemaChangeListener listener)
Cluster
register
in class Cluster
listener
- the new SchemaChangeListener
to register.Cluster
object;public Cluster unregister(SchemaChangeListener listener)
Cluster
listener
hasn't previously been
registered against this Cluster.unregister
in class Cluster
listener
- the SchemaChangeListener
to unregister.Cluster
object;public CloseFuture closeAsync()
Cluster
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).closeAsync
in class Cluster
public void close()
Cluster
closeAsync().get()
.public boolean isClosed()
Cluster
Cluster.closeAsync()
or Cluster.close()
) has been called, it does not guarantee
that the closing is done. If you want to guarantee that the closing is done,
you can call close()
and wait until it returns (or call the get method
on closeAsync()
with a very short timeout and check this doesn't timeout).Copyright © 2012–2018. All rights reserved.