Package org.jgroups.protocols
Class SEQUENCER2
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.SEQUENCER2
-
- All Implemented Interfaces:
Lifecycle
public class SEQUENCER2 extends Protocol
Implementation of total order protocol using a sequencer_uum. Todo 1: on a sequencer change, the new coordinator needs to determine the highest seqno from all members Todo 2: on a sequencer change, if a member has pendindg messages in the forward-queue, they need to be resent Todo 3: this protocol is currently broken, as a new member doesn't get the highest seqno and thus creates its table at offset=0, which means it will queue all messages higher than 0, and eventually run out of memory!!!- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SEQUENCER2.SequencerHeader
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.function.BiConsumer<MessageBatch,Message>
BATCH_ACCUMULATOR
protected long
bcasts_delivered
protected long
bcasts_received
protected long
bcasts_sent
protected Address
coord
protected java.util.concurrent.BlockingQueue<Message>
fwd_queue
protected boolean
is_coord
protected Table<Message>
received_msgs
protected long
received_requests
protected long
received_responses
protected long
request_msgs
protected long
response_msgs
protected boolean
running
protected long
sent_requests
protected long
sent_responses
protected java.util.concurrent.atomic.AtomicLong
seqno
protected java.util.concurrent.atomic.AtomicInteger
seqno_reqs
protected View
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 SEQUENCER2()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
broadcast(Message msg, long seqno)
protected void
deliver(Message msg, SEQUENCER2.SequencerHeader hdr)
protected void
deliverBatch(MessageBatch batch)
java.lang.Object
down(Event evt)
An event is to be sent down the stack.java.lang.Object
down(Message msg)
A message is sent down the stack.Address
getCoordinator()
int
getFwdQueueSize()
protected void
handleViewChange(View v)
boolean
isCoordinator()
protected void
removeAndDeliver(Table<Message> win, Address sender)
void
resetStats()
protected void
sendSeqnoRequest(int num_seqnos)
protected void
sendSeqnoResponse(Address original_sender, long seqno, int num_seqnos)
void
start()
This method is called on aJChannel.connect(String)
; starts work.void
stop()
Called on aJChannel.disconnect()
; stops work (e.g.java.lang.Object
up(Event evt)
An event was received from the protocol below.java.lang.Object
up(Message msg)
A single message was received.void
up(MessageBatch batch)
Sends up a multiple messages in aMessageBatch
.-
Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, destroy, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, init, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, toString
-
-
-
-
Field Detail
-
coord
protected volatile Address coord
-
view
protected volatile View view
-
is_coord
protected volatile boolean is_coord
-
seqno
protected final java.util.concurrent.atomic.AtomicLong seqno
-
fwd_queue
protected final java.util.concurrent.BlockingQueue<Message> fwd_queue
-
seqno_reqs
protected final java.util.concurrent.atomic.AtomicInteger seqno_reqs
-
running
protected volatile boolean running
-
BATCH_ACCUMULATOR
protected static final java.util.function.BiConsumer<MessageBatch,Message> BATCH_ACCUMULATOR
-
request_msgs
protected long request_msgs
-
response_msgs
protected long response_msgs
-
bcasts_sent
protected long bcasts_sent
-
bcasts_received
protected long bcasts_received
-
bcasts_delivered
protected long bcasts_delivered
-
sent_requests
protected long sent_requests
-
received_requests
protected long received_requests
-
sent_responses
protected long sent_responses
-
received_responses
protected long received_responses
-
-
Method Detail
-
isCoordinator
public boolean isCoordinator()
-
getCoordinator
public Address getCoordinator()
-
getFwdQueueSize
public int getFwdQueueSize()
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classProtocol
-
start
public void start() throws java.lang.Exception
Description copied from class:Protocol
This method is called on aJChannel.connect(String)
; starts work. Protocols are connected ready to receive events. Will be called from bottom to top.- Specified by:
start
in interfaceLifecycle
- Overrides:
start
in classProtocol
- Throws:
java.lang.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soJChannel.connect(String)
will throw an exception
-
stop
public void stop()
Description copied from class:Protocol
Called on aJChannel.disconnect()
; stops work (e.g. by closing multicast socket). Will be called from top to bottom.
-
down
public java.lang.Object down(Event evt)
Description copied from class:Protocol
An event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down()
.
-
down
public java.lang.Object down(Message msg)
Description copied from class:Protocol
A message is sent down the stack. Protocols may examine the message and do something (e.g. add a header) with it, before passing it down.
-
up
public java.lang.Object up(Event evt)
Description copied from class:Protocol
An event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally, the event is either a) discarded, or b) an event is sent down the stack usingdown_prot.down()
or c) the event (or another event) is sent up the stack usingup_prot.up()
.
-
up
public java.lang.Object up(Message msg)
Description copied from class:Protocol
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
up
public void up(MessageBatch batch)
Description copied from class:Protocol
Sends up a multiple messages in aMessageBatch
. The sender of the batch is always the same, and so is the destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed messages, although the transport itself will create initial MessageBatches that contain only either OOB or regular messages. The default processing below sends messages up the stack individually, based on a matching criteria (callingProtocol.accept(Message)
), and - if true - callsProtocol.up(org.jgroups.Event)
for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped. Subclasses should check if there are any messages destined for them (e.g. usingMessageBatch.iterator(Predicate)
), then possibly remove and process them and finally pass the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all encrypted messages in the batch, not remove them, and pass the batch up when done.
-
handleViewChange
protected void handleViewChange(View v)
-
sendSeqnoRequest
protected void sendSeqnoRequest(int num_seqnos)
-
sendSeqnoResponse
protected void sendSeqnoResponse(Address original_sender, long seqno, int num_seqnos)
-
broadcast
protected void broadcast(Message msg, long seqno)
-
deliver
protected void deliver(Message msg, SEQUENCER2.SequencerHeader hdr)
-
deliverBatch
protected void deliverBatch(MessageBatch batch)
-
-