public final class ResourceServer extends Object
The AtomixServer provides a standalone node that can server as a member of a cluster to
service operations on Resources from an ResourceClient. Servers do not expose
an interface for managing resources directly. Users can only access server resources through an
ResourceClient implementation.
To create a server, use the builder(Address) builder factory. Each server must
be initially configured with a server Address and a list of addresses for other members of the
core cluster. Note that the list of member addresses does not have to include the local server nor does
it have to include all the servers in the cluster. As long as the server can reach one live member of
the cluster, it can join.
List<Address> members = Arrays.asList(new Address("123.456.789.0", 5000), new Address("123.456.789.1", 5000));
AtomixServer server = AtomixServer.builder(address, members)
.withTransport(new NettyTransport())
.withStorage(new Storage(StorageLevel.MEMORY))
.build();
Servers must be configured with a Transport and Storage. By default, if no transport is
configured, the NettyTransport will be used and will thus be expected to be available on the classpath.
Similarly, if no storage module is configured, replicated commit logs will be written to
System.getProperty("user.dir") with a default log name.
Server lifecycle
When the server is started, the server will attempt to contact members in the configured
startup Address list. If any of the members are already in an active state, the server will request
to join the cluster. During the process of joining the cluster, the server will notify the current cluster
leader of its existence. If the leader already knows about the joining server, the server will immediately
join and become a full voting member. If the joining server is not yet known to the rest of the cluster,
it will join the cluster in a passive state in which it receives replicated state from other
servers in the cluster but does not participate in elections or other quorum-based aspects of the
underlying consensus algorithm. Once the joining server is caught up with the rest of the cluster, the
leader will promote it to a full voting member.
| Modifier and Type | Class and Description |
|---|---|
static class |
ResourceServer.Builder
Builds an
ResourceServer. |
| Constructor and Description |
|---|
ResourceServer(CopycatServer server) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<ResourceServer> |
bootstrap()
Bootstraps a single-node cluster.
|
CompletableFuture<ResourceServer> |
bootstrap(Address... cluster)
Bootstraps the cluster using the provided cluster configuration.
|
CompletableFuture<ResourceServer> |
bootstrap(Collection<Address> cluster)
Bootstraps the cluster using the provided cluster configuration.
|
static ResourceServer.Builder |
builder(Address address)
Returns a new Atomix server builder.
|
static ResourceServer.Builder |
builder(Address clientAddress,
Address serverAddress)
Returns a new Atomix server builder.
|
static ResourceServer.Builder |
builder(Address clientAddress,
Address serverAddress,
Properties properties)
Returns a new Atomix server builder.
|
static ResourceServer.Builder |
builder(Address address,
Properties properties)
Returns a new Atomix server builder.
|
ThreadContext |
context()
Returns the server thread context.
|
boolean |
isRunning()
Returns a boolean indicating whether the server is running.
|
CompletableFuture<ResourceServer> |
join(Address... cluster)
Joins the cluster.
|
CompletableFuture<ResourceServer> |
join(Collection<Address> cluster)
Joins the cluster.
|
CompletableFuture<Void> |
leave()
Leaves the Copycat cluster.
|
Serializer |
serializer()
Returns the server serializer.
|
CopycatServer |
server()
Returns the underlying Copycat server.
|
CompletableFuture<Void> |
shutdown()
Shuts down the server without leaving the Copycat cluster.
|
public ResourceServer(CopycatServer server)
NullPointerException - if server is nullpublic static ResourceServer.Builder builder(Address address)
The provided set of members will be used to connect to the other members in the Raft cluster.
address - The local server member address.NullPointerException - if address or members are nullpublic static ResourceServer.Builder builder(Address clientAddress, Address serverAddress)
The provided set of members will be used to connect to the other members in the Raft cluster.
clientAddress - The address through which clients connect to the server.serverAddress - The address through which servers connect to each other.NullPointerException - if any argument is nullpublic static ResourceServer.Builder builder(Address address, Properties properties)
The provided set of members will be used to connect to the other members in the Raft cluster.
address - The local server member address.NullPointerException - if address or members are nullpublic static ResourceServer.Builder builder(Address clientAddress, Address serverAddress, Properties properties)
The provided set of members will be used to connect to the other members in the Raft cluster.
clientAddress - The address through which clients connect to the server.serverAddress - The address through which servers connect to each other.NullPointerException - if any argument is nullpublic ThreadContext context()
public Serializer serializer()
The server serializer handles serialization for all operations within the resource server. Serializable
types registered on the server serializer will be reflected in the Storage and Transport
layers.
public CopycatServer server()
public CompletableFuture<ResourceServer> bootstrap()
Bootstrapping a single-node cluster results in the server forming a new cluster to which additional servers can be joined.
Only Member.Type#ACTIVE members can be included in a bootstrap configuration. If the local server is
not initialized as an active member, it cannot be part of the bootstrap configuration for the cluster.
When the cluster is bootstrapped, the local server will be transitioned into the active state and begin
participating in the Raft consensus algorithm. When the cluster is first bootstrapped, no leader will exist.
The bootstrapped members will elect a leader amongst themselves. Once a cluster has been bootstrapped, additional
members may be joined to the cluster. In the event that the bootstrapped members cannot
reach a quorum to elect a leader, bootstrap will continue until successful.
It is critical that all servers in a bootstrap configuration be started with the same exact set of members. Bootstrapping multiple servers with different configurations may result in split brain.
The CompletableFuture returned by this method will be completed once the cluster has been bootstrapped,
a leader has been elected, and the leader has been notified of the local server's client configurations.
public CompletableFuture<ResourceServer> bootstrap(Address... cluster)
Bootstrapping the cluster results in a new cluster being formed with the provided configuration. The initial nodes in a cluster must always be bootstrapped. This is necessary to prevent split brain. If the provided configuration is empty, the local server will form a single-node cluster.
Only Member.Type#ACTIVE members can be included in a bootstrap configuration. If the local server is
not initialized as an active member, it cannot be part of the bootstrap configuration for the cluster.
When the cluster is bootstrapped, the local server will be transitioned into the active state and begin
participating in the Raft consensus algorithm. When the cluster is first bootstrapped, no leader will exist.
The bootstrapped members will elect a leader amongst themselves. Once a cluster has been bootstrapped, additional
members may be joined to the cluster. In the event that the bootstrapped members cannot
reach a quorum to elect a leader, bootstrap will continue until successful.
It is critical that all servers in a bootstrap configuration be started with the same exact set of members. Bootstrapping multiple servers with different configurations may result in split brain.
The CompletableFuture returned by this method will be completed once the cluster has been bootstrapped,
a leader has been elected, and the leader has been notified of the local server's client configurations.
cluster - The bootstrap cluster configuration.public CompletableFuture<ResourceServer> bootstrap(Collection<Address> cluster)
Bootstrapping the cluster results in a new cluster being formed with the provided configuration. The initial nodes in a cluster must always be bootstrapped. This is necessary to prevent split brain. If the provided configuration is empty, the local server will form a single-node cluster.
Only Member.Type#ACTIVE members can be included in a bootstrap configuration. If the local server is
not initialized as an active member, it cannot be part of the bootstrap configuration for the cluster.
When the cluster is bootstrapped, the local server will be transitioned into the active state and begin
participating in the Raft consensus algorithm. When the cluster is first bootstrapped, no leader will exist.
The bootstrapped members will elect a leader amongst themselves. Once a cluster has been bootstrapped, additional
members may be joined to the cluster. In the event that the bootstrapped members cannot
reach a quorum to elect a leader, bootstrap will continue until successful.
It is critical that all servers in a bootstrap configuration be started with the same exact set of members. Bootstrapping multiple servers with different configurations may result in split brain.
The CompletableFuture returned by this method will be completed once the cluster has been bootstrapped,
a leader has been elected, and the leader has been notified of the local server's client configurations.
cluster - The bootstrap cluster configuration.public CompletableFuture<ResourceServer> join(Address... cluster)
Joining the cluster results in the local server being added to an existing cluster that has already been bootstrapped. The provided configuration will be used to connect to the existing cluster and submit a join request. Once the server has been added to the existing cluster's configuration, the join operation is complete.
Any type of server may join a cluster. In order to join a cluster, the provided list of
bootstrapped members must be non-empty and must include at least one active member of the cluster. If no member
in the configuration is reachable, the server will continue to attempt to join the cluster until successful. If
the provided cluster configuration is empty, the returned CompletableFuture will be completed exceptionally.
When the server joins the cluster, the local server will be transitioned into its initial state as defined by
the configured Member.Type. Once the server has joined, it will immediately begin participating in
Raft and asynchronous replication according to its configuration.
It's important to note that the provided cluster configuration will only be used the first time the server attempts
to join the cluster. Thereafter, in the event that the server crashes and is restarted by joining the cluster
again, the last known configuration will be used assuming the server is configured with persistent storage. Only when
the server leaves the cluster will its configuration and log be reset.
In order to preserve safety during configuration changes, Copycat leaders do not allow concurrent configuration
changes. In the event that an existing configuration change (a server joining or leaving the cluster or a
member being promoted or demoted) is under way, the local
server will retry attempts to join the cluster until successful. If the server fails to reach the leader,
the join will be retried until successful.
cluster - A collection of cluster member addresses to join.public CompletableFuture<ResourceServer> join(Collection<Address> cluster)
Joining the cluster results in the local server being added to an existing cluster that has already been bootstrapped. The provided configuration will be used to connect to the existing cluster and submit a join request. Once the server has been added to the existing cluster's configuration, the join operation is complete.
Any type of server may join a cluster. In order to join a cluster, the provided list of
bootstrapped members must be non-empty and must include at least one active member of the cluster. If no member
in the configuration is reachable, the server will continue to attempt to join the cluster until successful. If
the provided cluster configuration is empty, the returned CompletableFuture will be completed exceptionally.
When the server joins the cluster, the local server will be transitioned into its initial state as defined by
the configured Member.Type. Once the server has joined, it will immediately begin participating in
Raft and asynchronous replication according to its configuration.
It's important to note that the provided cluster configuration will only be used the first time the server attempts
to join the cluster. Thereafter, in the event that the server crashes and is restarted by joining the cluster
again, the last known configuration will be used assuming the server is configured with persistent storage. Only when
the server leaves the cluster will its configuration and log be reset.
In order to preserve safety during configuration changes, Copycat leaders do not allow concurrent configuration
changes. In the event that an existing configuration change (a server joining or leaving the cluster or a
member being promoted or demoted) is under way, the local
server will retry attempts to join the cluster until successful. If the server fails to reach the leader,
the join will be retried until successful.
cluster - A collection of cluster member addresses to join.public boolean isRunning()
public CompletableFuture<Void> shutdown()
public CompletableFuture<Void> leave()
Copyright © 2013–2017. All rights reserved.