T - resource typepublic interface Resource<T extends Resource<T>> extends Managed<T>
Resources are stateful distributed objects that run across a set of CopycatServers
in a cluster.
Resources can be created either as standalone StateMachines in
a typical Copycat cluster or as Atomix resources. Operations on the resource are translated into
Commands and Querys which are submitted to the cluster where they're logged and
replicated.
Resource implementations must be annotated with the ResourceTypeInfo annotation to indicate the
ResourceStateMachine to be used by the Atomix resource manager. Additionally, resources must be
registered via the ServiceLoader pattern in a file at META-INF/services/io.atomix.resource.Resource
on the class path. The resource registration allows the Atomix resource manager to locate and load the resource
state machine on each server in the cluster.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Resource.Config
Base class for cluster-wide resource configurations.
|
static class |
Resource.Options
Base class for local resource options.
|
static class |
Resource.State
Resource session state constants.
|
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
close()
Closes the resource.
|
Resource.Config |
config()
Returns the resource configuration.
|
ThreadContext |
context()
Returns the resource thread context.
|
CompletableFuture<Void> |
delete()
Deletes the resource state.
|
Listener<Resource.State> |
onStateChange(Consumer<Resource.State> callback)
Registers a resource state change listener.
|
CompletableFuture<T> |
open()
Opens the resource.
|
Resource.Options |
options()
Returns the resource options.
|
Serializer |
serializer()
Returns the resource serializer.
|
Resource.State |
state()
Returns the current resource state.
|
ResourceType |
type()
Returns the resource type.
|
ResourceType type()
Serializer serializer()
Resource.Config config()
Resource.Options options()
Resource.State state()
The resource's Resource.State is indicative of the resource's ability to communicate with the cluster at any given
time. Users of the resource should use the state to determine when guarantees may be lost. See the Resource.State
documentation for information on the specific states, and see resource implementation documentation for the
implications of different states on resource consistency.
Listener<Resource.State> onStateChange(Consumer<Resource.State> callback)
callback - The callback to call when the resource state changes.ThreadContext context()
CompletableFuture<T> open()
Once the resource is opened, the resource will be transitioned to the Resource.State.CONNECTED state
and the returned CompletableFuture will be completed.
CompletableFuture<Void> close()
Once the resource is closed, the resource will be transitioned to the Resource.State.CLOSED state and
the returned CompletableFuture will be completed. Thereafter, attempts to operate on the resource
will fail.
CompletableFuture<Void> delete()
Copyright © 2013–2016. All rights reserved.