Class RaftNode

java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.raft.testfwk.RaftNode
All Implemented Interfaces:
Closeable, AutoCloseable, org.jgroups.Lifecycle, Settable

public class RaftNode extends org.jgroups.stack.Protocol implements org.jgroups.Lifecycle, Settable, Closeable
Wraps the RAFT and/or ELECTION protocols
Since:
1.0.5
Author:
Bela Ban
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final MockRaftCluster
     
    protected final BaseElection
     
    protected final org.jgroups.stack.Protocol[]
     
    protected final RAFT
     

    Fields inherited from class org.jgroups.stack.Protocol

    after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot
  • Constructor Summary

    Constructors
    Constructor
    Description
    RaftNode(MockRaftCluster cluster, org.jgroups.stack.Protocol[] protocols)
     
    RaftNode(RaftCluster cluster, RAFT raft)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    down(org.jgroups.Event evt)
     
    down(org.jgroups.Message msg)
     
     
    protected <T extends org.jgroups.stack.Protocol>
    T
    find(Class<T> cl)
     
    org.jgroups.Address
     
    getAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous get operation that returns immediately without blocking.
    void
    handleView(org.jgroups.View v)
     
    void
     
    protected org.jgroups.Address
     
    org.jgroups.stack.Protocol[]
     
     
    setAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous set, returns immediately with a CompletableFuture.
    void
     
    void
     
     
    up(org.jgroups.Message msg)
     

    Methods inherited from class org.jgroups.stack.Protocol

    accept, addPolicy, addr, addr, afterCreationHook, down, enableStats, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, up, up

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.jgroups.raft.Settable

    get, getAsync, set, set, setAsync
  • Field Details

    • prots

      protected final org.jgroups.stack.Protocol[] prots
    • raft

      protected final RAFT raft
    • election

      protected final BaseElection election
    • cluster

      protected final MockRaftCluster cluster
  • Constructor Details

    • RaftNode

      public RaftNode(MockRaftCluster cluster, org.jgroups.stack.Protocol[] protocols)
    • RaftNode

      public RaftNode(RaftCluster cluster, RAFT raft)
  • Method Details

    • protocols

      public org.jgroups.stack.Protocol[] protocols()
    • getAddress

      public org.jgroups.Address getAddress()
      Overrides:
      getAddress in class org.jgroups.stack.Protocol
    • init

      public void init() throws Exception
      Specified by:
      init in interface org.jgroups.Lifecycle
      Overrides:
      init in class org.jgroups.stack.Protocol
      Throws:
      Exception
    • start

      public void start() throws Exception
      Specified by:
      start in interface org.jgroups.Lifecycle
      Overrides:
      start in class org.jgroups.stack.Protocol
      Throws:
      Exception
    • stop

      public void stop()
      Specified by:
      stop in interface org.jgroups.Lifecycle
      Overrides:
      stop in class org.jgroups.stack.Protocol
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.jgroups.Lifecycle
      Overrides:
      destroy in class org.jgroups.stack.Protocol
    • handleView

      public void handleView(org.jgroups.View v)
    • down

      public Object down(org.jgroups.Event evt)
      Overrides:
      down in class org.jgroups.stack.Protocol
    • down

      public Object down(org.jgroups.Message msg)
      Overrides:
      down in class org.jgroups.stack.Protocol
    • up

      public Object up(org.jgroups.Message msg)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • setAsync

      public CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length, Options options) throws Exception
      Description copied from interface: Settable
      Asynchronous set, returns immediately with a CompletableFuture. To wait for the result, CompletableFuture.get() or CompletableFuture.get(long, TimeUnit) can be called.
      Specified by:
      setAsync in interface Settable
      Parameters:
      buf - The buffer (usually a serialized command) which represent the change to be applied to all state machines
      offset - The offset into the buffer
      length - he number of bytes to be used in the buffer, starting at offset
      options - Options to pass to the call, may be null
      Returns:
      A CompletableFuture which can be used to fetch the result.
      Throws:
      Exception
    • getAsync

      public CompletableFuture<byte[]> getAsync(byte[] buf, int offset, int length, Options options) throws Exception
      Description copied from interface: Settable
      Asynchronous get operation that returns immediately without blocking.

      This method submits a read-only operation to the state machine. Read-only operations are treated differently by the replication algorithm. Since read-only operations do not change the state-machine state, these operations are not appended to the replicated log.

      Warning: Do not change the state-machine state by operations submitted through this method. Otherwise, the state-machine will diverge and lead to an undefined state.

      Specified by:
      getAsync in interface Settable
      Parameters:
      buf - The buffer representing the read-only operation to submit to the state machine.
      offset - The offset to skip the bytes in the buffer.
      length - The number of bytes to use from the buffer starting at offset.
      Returns:
      A buffer representing the result after submitting the read-only operation.
      Throws:
      Exception - Thrown if the operation could not be submitted.
    • toString

      public String toString()
      Overrides:
      toString in class org.jgroups.stack.Protocol
    • find

      protected <T extends org.jgroups.stack.Protocol> T find(Class<T> cl)
    • localAddress

      protected org.jgroups.Address localAddress()
    • raft

      public RAFT raft()
    • election

      public BaseElection election()