public final class Cluster extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Cluster.Builder |
Modifier and Type | Method and Description |
---|---|
List<URI> |
availableHosts()
Gets the list of hosts that the
Cluster was able to connect to. |
static Cluster.Builder |
build() |
static Cluster.Builder |
build(File configurationFile) |
static Cluster.Builder |
build(String address) |
void |
close() |
CompletableFuture<Void> |
closeAsync() |
<T extends Client> |
connect()
Creates a
Client.ClusteredClient instance to this Cluster , meaning requests will be routed to
one or more servers (depending on the cluster configuration), where each request represents the entirety of a
transaction. |
<T extends Client> |
connect(String sessionId)
Creates a
Client.SessionedClient instance to this Cluster , meaning requests will be routed to
a single server (randomly selected from the cluster), where the same bindings will be available on each request. |
<T extends Client> |
connect(String sessionId,
boolean manageTransactions)
Creates a
Client.SessionedClient instance to this Cluster , meaning requests will be routed to
a single server (randomly selected from the cluster), where the same bindings will be available on each request. |
void |
init() |
boolean |
isClosed()
Determines if the
Cluster has completed its closing process after a call to close() or
closeAsync() . |
boolean |
isClosing()
|
static Cluster |
open()
Create a
Cluster with all default settings which will connect to one contact point at localhost . |
static Cluster |
open(String configurationFile)
Create a
Cluster using a YAML-based configuration file. |
String |
toString() |
public void init()
public <T extends Client> T connect()
Client.ClusteredClient
instance to this Cluster
, meaning requests will be routed to
one or more servers (depending on the cluster configuration), where each request represents the entirety of a
transaction. A commit or rollback (in case of error) is automatically executed at the end of the request.
Note that calling this method does not imply that a connection is made to the server itself at this point.
Therefore, if there is only one server specified in the Cluster
and that server is not available an
error will not be raised at this point. Connections get initialized in the Client
when a request is
submitted or can be directly initialized via Client.init()
.public <T extends Client> T connect(String sessionId)
Client.SessionedClient
instance to this Cluster
, meaning requests will be routed to
a single server (randomly selected from the cluster), where the same bindings will be available on each request.
Requests are bound to the same thread on the server and thus transactions may extend beyond the bounds of a
single request. The transactions are managed by the user and must be committed or rolled-back manually.
Note that calling this method does not imply that a connection is made to the server itself at this point.
Therefore, if there is only one server specified in the Cluster
and that server is not available an
error will not be raised at this point. Connections get initialized in the Client
when a request is
submitted or can be directly initialized via Client.init()
.sessionId
- user supplied id for the session which should be unique (a UUID is ideal).public <T extends Client> T connect(String sessionId, boolean manageTransactions)
Client.SessionedClient
instance to this Cluster
, meaning requests will be routed to
a single server (randomly selected from the cluster), where the same bindings will be available on each request.
Requests are bound to the same thread on the server and thus transactions may extend beyond the bounds of a
single request. If manageTransactions
is set to false
then transactions are managed by the
user and must be committed or rolled-back manually. When set to true
the transaction is committed or
rolled-back at the end of each request.
Note that calling this method does not imply that a connection is made to the server itself at this point.
Therefore, if there is only one server specified in the Cluster
and that server is not available an
error will not be raised at this point. Connections get initialized in the Client
when a request is
submitted or can be directly initialized via Client.init()
.sessionId
- user supplied id for the session which should be unique (a UUID is ideal).manageTransactions
- enables auto-transactions when set to truepublic static Cluster.Builder build()
public static Cluster.Builder build(String address)
public static Cluster.Builder build(File configurationFile) throws FileNotFoundException
FileNotFoundException
public static Cluster open()
Cluster
with all default settings which will connect to one contact point at localhost
.public static Cluster open(String configurationFile) throws Exception
Cluster
using a YAML-based configuration file.Exception
public void close()
public CompletableFuture<Void> closeAsync()
public boolean isClosing()
public boolean isClosed()
Cluster
has completed its closing process after a call to close()
or
closeAsync()
.public List<URI> availableHosts()
Cluster
was able to connect to. A Host
is assumed unavailable
until a connection to it is proven to be present. This will not happen until the the Client
submits
requests that succeed in reaching a server at the Host
or Client.init()
is called which
initializes the ConnectionPool
for the Client
itself. The number of available hosts returned
from this method will change as different servers come on and offline.Copyright © 2013–2016 Apache Software Foundation. All rights reserved.