Class PrimitiveBuilder<B extends PrimitiveBuilder<B,​C,​P>,​C extends PrimitiveConfig,​P extends SyncPrimitive>

java.lang.Object
io.atomix.primitive.PrimitiveBuilder<B,​C,​P>
Type Parameters:
B - builder type
P - primitive type
All Implemented Interfaces:
io.atomix.utils.Builder<P>

public abstract class PrimitiveBuilder<B extends PrimitiveBuilder<B,​C,​P>,​C extends PrimitiveConfig,​P extends SyncPrimitive>
extends Object
implements io.atomix.utils.Builder<P>
Abstract builder for distributed primitives.
  • Constructor Details

  • Method Details

    • withSerializer

      public B withSerializer​(io.atomix.utils.serializer.Serializer serializer)
      Sets the primitive serializer.
      Parameters:
      serializer - the primitive serializer
      Returns:
      the primitive builder
    • withReadOnly

      public B withReadOnly()
      Sets the primitive to read-only.
      Returns:
      the primitive builder
    • withReadOnly

      public B withReadOnly​(boolean readOnly)
      Sets whether the primitive is read-only.
      Parameters:
      readOnly - whether the primitive is read-only
      Returns:
      the primitive builder
    • build

      public P build()
      Builds a new instance of the primitive.

      The returned instance will be distinct from all other instances of the same primitive on this node, with a distinct session, ordering guarantees, memory, etc.

      Specified by:
      build in interface io.atomix.utils.Builder<B extends PrimitiveBuilder<B,​C,​P>>
      Returns:
      a new instance of the primitive
    • buildAsync

      public abstract CompletableFuture<P> buildAsync()
      Builds a new instance of the primitive asynchronously.

      The returned instance will be distinct from all other instances of the same primitive on this node, with a distinct session, ordering guarantees, memory, etc.

      Returns:
      asynchronous distributed primitive
    • get

      public P get()
      Gets or builds a singleton instance of the primitive.

      The returned primitive will be shared by all get() calls for the named primitive. If no instance has yet been constructed, the instance will be built from this builder's configuration.

      Returns:
      a singleton instance of the primitive
    • getAsync

      public CompletableFuture<P> getAsync()
      Gets or builds a singleton instance of the primitive asynchronously.

      The returned primitive will be shared by all get() calls for the named primitive. If no instance has yet been constructed, the instance will be built from this builder's configuration.

      Returns:
      a singleton instance of the primitive