public static class ResourceServer.Builder extends Object implements Builder<ResourceServer>
ResourceServer.
The server builder configures an ResourceServer to listen for connections from clients and other
servers, connect to other servers in a cluster, and manage a replicated log. To create a server builder,
use the ResourceServer.builder(Address, Address...) method:
AtomixServer server = AtomixServer.builder(address, servers)
.withTransport(new NettyTransport())
.withStorage(Storage.builder()
.withDirectory("logs")
.withStorageLevel(StorageLevel.MAPPED)
.build())
.build();
The two most essential components of the builder are the Transport and Storage. The
transport provides the mechanism for the server to communicate with clients and other servers in the
cluster. All servers, clients, and replicas must implement the same Transport type. The Storage
module configures how the server manages the replicated log. Logs can be written to disk or held in
memory or memory-mapped files.| Modifier and Type | Method and Description |
|---|---|
ResourceServer.Builder |
addResourceType(Class<? extends io.atomix.resource.Resource<?>> type)
Adds a resource type to the server.
|
ResourceServer.Builder |
addResourceType(io.atomix.resource.ResourceType type)
Adds a resource type to the server.
|
ResourceServer |
build()
Builds the server.
|
ResourceServer.Builder |
withClientTransport(Transport transport)
Sets the client transport, returning the server builder for method chaining.
|
ResourceServer.Builder |
withElectionTimeout(Duration electionTimeout)
Sets the server election timeout, returning the server builder for method chaining.
|
ResourceServer.Builder |
withHeartbeatInterval(Duration heartbeatInterval)
Sets the server heartbeat interval, returning the server builder for method chaining.
|
ResourceServer.Builder |
withResourceTypes(Class<? extends io.atomix.resource.Resource<?>>... types)
Sets the available resource types.
|
ResourceServer.Builder |
withResourceTypes(Collection<io.atomix.resource.ResourceType> types)
Sets the available resource types.
|
ResourceServer.Builder |
withResourceTypes(io.atomix.resource.ResourceType... types)
Sets the available resource types.
|
ResourceServer.Builder |
withSerializer(Serializer serializer)
Sets the serializer, returning the server builder for method chaining.
|
ResourceServer.Builder |
withServerTransport(Transport transport)
Sets the server transport, returning the server builder for method chaining.
|
ResourceServer.Builder |
withSessionTimeout(Duration sessionTimeout)
Sets the server session timeout, returning the server builder for method chaining.
|
ResourceServer.Builder |
withStorage(Storage storage)
Sets the server storage module, returning the server builder for method chaining.
|
ResourceServer.Builder |
withTransport(Transport transport)
Sets the server transport, returning the server builder for method chaining.
|
public ResourceServer.Builder withTransport(Transport transport)
The configured transport should be the same transport as all other nodes in the cluster.
If no transport is explicitly provided, the instance will default to the NettyTransport
if available on the classpath.
transport - The server transport.NullPointerException - if transport is nullpublic ResourceServer.Builder withClientTransport(Transport transport)
The configured transport should be the same transport as all clients.
If no transport is explicitly provided, the instance will default to the NettyTransport
if available on the classpath.
transport - The server transport.NullPointerException - if transport is nullpublic ResourceServer.Builder withServerTransport(Transport transport)
The configured transport should be the same transport as all other servers in the cluster.
If no transport is explicitly provided, the instance will default to the NettyTransport
if available on the classpath.
transport - The server transport.NullPointerException - if transport is nullpublic ResourceServer.Builder withSerializer(Serializer serializer)
The serializer will be used to serialize and deserialize operations that are sent over the wire.
serializer - The serializer.NullPointerException - if serializer is nullpublic ResourceServer.Builder withStorage(Storage storage)
The storage module is the interface the server will use to store the persistent replicated log.
For simple configurations, users can simply construct a Storage object:
AtomixServer server = AtomixServer.builder(address, members)
.withStorage(new Storage("logs"))
.build();
For more complex storage configurations, use the Storage.Builder:
AtomixServer server = AtomixServer.builder(address, members)
.withStorage(Storage.builder()
.withDirectory("logs")
.withStorageLevel(StorageLevel.MAPPED)
.withCompactionThreads(2)
.build())
.build();
storage - The server storage module.NullPointerException - if storage is nullpublic ResourceServer.Builder withElectionTimeout(Duration electionTimeout)
The election timeout is the duration since last contact with the cluster leader after which
the server should start a new election. The election timeout should always be significantly
larger than withHeartbeatInterval(Duration) in order to prevent unnecessary elections.
electionTimeout - The server election timeout in milliseconds.NullPointerException - if electionTimeout is nullpublic ResourceServer.Builder withHeartbeatInterval(Duration heartbeatInterval)
The heartbeat interval is the interval at which the server, if elected leader, should contact
other servers within the cluster to maintain its leadership. The heartbeat interval should
always be some fraction of withElectionTimeout(Duration).
heartbeatInterval - The server heartbeat interval in milliseconds.NullPointerException - if heartbeatInterval is nullpublic ResourceServer.Builder withSessionTimeout(Duration sessionTimeout)
The session timeout is assigned by the server to a client which opens a new session. The session timeout dictates the interval at which the client must send keep-alive requests to the cluster to maintain its session. If a client fails to communicate with the cluster for larger than the configured session timeout, its session may be expired.
sessionTimeout - The server session timeout in milliseconds.NullPointerException - if sessionTimeout is nullpublic ResourceServer.Builder withResourceTypes(Class<? extends io.atomix.resource.Resource<?>>... types)
types - The available resource types.public ResourceServer.Builder withResourceTypes(io.atomix.resource.ResourceType... types)
types - The available resource types.public ResourceServer.Builder withResourceTypes(Collection<io.atomix.resource.ResourceType> types)
types - The available resource types.public ResourceServer.Builder addResourceType(Class<? extends io.atomix.resource.Resource<?>> type)
type - The resource type.public ResourceServer.Builder addResourceType(io.atomix.resource.ResourceType type)
type - The resource type.public ResourceServer build()
If no Transport was configured for the server, the builder will attempt to create a
NettyTransport instance. If io.atomix.catalyst.transport.NettyTransport is not available
on the classpath, a ConfigurationException will be thrown.
Once the server is built, it is not yet connected to the cluster. To connect the server to the cluster,
call the asynchronous #open() method.
build in interface Builder<ResourceServer>ConfigurationException - if the server is misconfiguredCopyright © 2013–2016. All rights reserved.