java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.raft.REDIRECT
- All Implemented Interfaces:
org.jgroups.Lifecycle,DynamicMembership,Settable
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 ClassesModifier and TypeClassDescriptionstatic classstatic enumprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RAFTprotected static final shortprotected static final shortprotected final AtomicIntegerprotected final Map<Integer, CompletableFuture<byte[]>> protected org.jgroups.ViewFields 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 -
Method Summary
Modifier and TypeMethodDescriptionCompletableFuture<byte[]> protected CompletableFuture<byte[]> changeServer(String name, boolean add) CompletableFuture<byte[]> Asynchronous get operation that returns immediately without blocking.protected voidhandleEvent(org.jgroups.Message msg, REDIRECT.RedirectHeader hdr) voidinit()protected org.jgroups.AddressCompletableFuture<byte[]> removeServer(String name) CompletableFuture<byte[]> Asynchronous set, returns immediately with a CompletableFuture.up(org.jgroups.Event evt) up(org.jgroups.Message msg) voidup(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
-
Field Details
-
REDIRECT_ID
protected static final short REDIRECT_ID- See Also:
-
REDIRECT_HDR
protected static final short REDIRECT_HDR- See Also:
-
raft
-
view
protected volatile org.jgroups.View view -
request_ids
-
requests
-
-
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:SettableAsynchronous set, returns immediately with a CompletableFuture. To wait for the result,CompletableFuture.get()orCompletableFuture.get(long, TimeUnit)can be called.- Specified by:
setAsyncin interfaceSettable- Parameters:
buf- The buffer (usually a serialized command) which represent the change to be applied to all state machinesoffset- The offset into the bufferlength- he number of bytes to be used in the buffer, starting at offsetoptions- 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:SettableAsynchronous 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:
getAsyncin interfaceSettable- 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
- Specified by:
addServerin interfaceDynamicMembership- Throws:
Exception
-
removeServer
- Specified by:
removeServerin interfaceDynamicMembership- Throws:
Exception
-
init
- Specified by:
initin interfaceorg.jgroups.Lifecycle- Overrides:
initin classorg.jgroups.stack.Protocol- Throws:
Exception
-
up
- Overrides:
upin classorg.jgroups.stack.Protocol
-
up
- Overrides:
upin classorg.jgroups.stack.Protocol
-
up
public void up(org.jgroups.util.MessageBatch batch) - Overrides:
upin classorg.jgroups.stack.Protocol
-
handleEvent
-
leader
- Throws:
RaftLeaderException
-
changeServer
- Throws:
Exception
-