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, 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 |
|---|---|
static ResourceServer.Builder |
builder(Address address,
Address... members)
Returns a new Atomix server builder.
|
static ResourceServer.Builder |
builder(Address clientAddress,
Address serverAddress,
Address... members)
Returns a new Atomix server builder.
|
static ResourceServer.Builder |
builder(Address clientAddress,
Address serverAddress,
Collection<Address> members)
Returns a new Atomix server builder.
|
static ResourceServer.Builder |
builder(Address address,
Collection<Address> members)
Returns a new Atomix server builder.
|
static ResourceServer.Builder |
builder(Properties properties)
Returns a new ResourceServer builder from the given properties.
|
static ResourceServer.Builder |
builder(String properties)
Returns a new ResourceServer builder from the given configuration file.
|
ThreadContext |
context()
Returns the server thread context.
|
boolean |
isRunning()
Returns a boolean indicating whether the server is running.
|
Serializer |
serializer()
Returns the server serializer.
|
CopycatServer |
server()
Returns the underlying Copycat server.
|
CompletableFuture<ResourceServer> |
start()
Starts the server.
|
CompletableFuture<Void> |
stop()
Stops the server.
|
public ResourceServer(CopycatServer server)
NullPointerException - if server is nullpublic static ResourceServer.Builder builder(String properties)
properties - The properties file from which to load the replica builder.public static ResourceServer.Builder builder(Properties properties)
properties - The properties from which to load the replica builder.public static ResourceServer.Builder builder(Address address, Address... members)
The provided set of members will be used to connect to the other members in the Raft cluster.
address - The local server member address.members - The cluster members to which to connect.NullPointerException - if address or members are nullpublic static ResourceServer.Builder builder(Address address, Collection<Address> members)
The provided set of members will be used to connect to the other members in the Raft cluster.
address - The local server member address.members - The cluster members to which to connect.NullPointerException - if address or members are nullpublic static ResourceServer.Builder builder(Address clientAddress, Address serverAddress, Address... members)
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.members - The cluster members to which to connect.NullPointerException - if any argument is nullpublic static ResourceServer.Builder builder(Address clientAddress, Address serverAddress, Collection<Address> members)
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.members - The cluster members to which to connect.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> start()
public boolean isRunning()
public CompletableFuture<Void> stop()
Copyright © 2013–2016. All rights reserved.