Class REDIRECT

java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.raft.REDIRECT
All Implemented Interfaces:
org.jgroups.Lifecycle, DynamicMembership, Settable

public class REDIRECT extends org.jgroups.stack.Protocol implements Settable, DynamicMembership
Protocol that redirects RAFT commands from clients to the actual RAFT leader. E.g. if a client issues a set(), but the current mode is not the leader, the set() is redirected to the leader and the client blocked until the set() has been committed by a majority of nodes.
Since:
0.1
Author:
Bela Ban
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static enum 
     
    protected class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected RAFT
     
    protected static final short
     
    protected static final short
     
    protected final AtomicInteger
     
    protected final Map<Integer,CompletableFuture<byte[]>>
     
    protected org.jgroups.View
     

    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
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    protected CompletableFuture<byte[]>
    changeServer(String name, boolean add)
     
    getAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous get operation that returns immediately without blocking.
    protected void
    handleEvent(org.jgroups.Message msg, REDIRECT.RedirectHeader hdr)
     
    void
     
    protected org.jgroups.Address
    leader(String req_type)
     
     
    setAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous set, returns immediately with a CompletableFuture.
    up(org.jgroups.Event evt)
     
    up(org.jgroups.Message msg)
     
    void
    up(org.jgroups.util.MessageBatch batch)
     

    Methods inherited from class org.jgroups.stack.Protocol

    accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, down, enableStats, getAddress, 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, start, statsEnabled, stop, toString

    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, get, getAsync, set, set, setAsync
  • Field Details

  • Constructor Details

    • REDIRECT

      public REDIRECT()
  • Method Details

    • 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.
      options - Options to pass along in the call chain, may be null.
      Returns:
      A buffer representing the result after submitting the read-only operation.
      Throws:
      Exception - Thrown if the operation could not be submitted.
    • addServer

      public CompletableFuture<byte[]> addServer(String name) throws Exception
      Specified by:
      addServer in interface DynamicMembership
      Throws:
      Exception
    • removeServer

      public CompletableFuture<byte[]> removeServer(String name) throws Exception
      Specified by:
      removeServer in interface DynamicMembership
      Throws:
      Exception
    • init

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

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

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

      public void up(org.jgroups.util.MessageBatch batch)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • handleEvent

      protected void handleEvent(org.jgroups.Message msg, REDIRECT.RedirectHeader hdr)
    • leader

      protected org.jgroups.Address leader(String req_type) throws RaftLeaderException
      Throws:
      RaftLeaderException
    • changeServer

      protected CompletableFuture<byte[]> changeServer(String name, boolean add) throws Exception
      Throws:
      Exception