Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.jgroups.protocols.pbcast
Class NAKACK  view NAKACK download NAKACK.java

java.lang.Object
  extended byorg.jgroups.stack.Protocol
      extended byorg.jgroups.protocols.pbcast.NAKACK
All Implemented Interfaces:
org.jgroups.stack.NakReceiverWindow.Listener, org.jgroups.stack.Retransmitter.RetransmitCommand

public class NAKACK
extends org.jgroups.stack.Protocol
implements org.jgroups.stack.Retransmitter.RetransmitCommand, org.jgroups.stack.NakReceiverWindow.Listener

Negative AcKnowledgement layer (NAKs). Messages are assigned a monotonically increasing sequence number (seqno). Receivers deliver messages ordered according to seqno and request retransmission of missing messages. Retransmitted messages are bundled into bigger ones, e.g. when getting an xmit request for messages 1-10, instead of sending 10 unicast messages, we bundle all 10 messages into 1 and send it. However, since this protocol typically sits below FRAG, we cannot count on FRAG to fragement/defragment the (possibly) large message into smaller ones. Therefore we only bundle messages up to max_xmit_size bytes to prevent too large messages. For example, if the bundled message size was a total of 34000 bytes, and max_xmit_size=16000, we'd send 3 messages: 2 16K and a 2K message. Note that max_xmit_size should be the same value as FRAG.frag_size (or smaller).
Retransmit requests are always sent to the sender. If the sender dies, and not everyone has received its messages, they will be lost. In the future, this may be changed to have receivers store all messages, so that retransmit requests can be answered by any member. Trivial to implement, but not done yet. For most apps, the default retransmit properties are sufficient, if not use vsync.


Nested Class Summary
(package private) static class NAKACK.Entry
           
(package private) static class NAKACK.MissingMessage
           
(package private) static class NAKACK.XmitRequest
           
 
Field Summary
private  boolean discard_delivered_msgs
          Messages that have been received in order are sent up the stack (= delivered to the application).
private  int gc_lag
           
private  boolean is_server
           
private  boolean leaving
           
private  org.jgroups.Address local_addr
           
private  int max_xmit_buf_size
          If value is > 0, the retransmit buffer is bounded: only the max_xmit_buf_size latest messages are kept, older ones are discarded when the buffer size is exceeded.
private  long max_xmit_size
           
private  java.util.Vector members
           
private  long missing_msgs_received
           
private static java.lang.String name
           
private  org.jgroups.util.BoundedList receive_history
          BoundedList.
private  java.util.HashMap received
          Captures stats on XMIT_REQS, XMIT_RSPS per receiver
private  java.util.HashMap received_msgs
          Hashtable.
private  long[] retransmit_timeout
           
private  org.jgroups.util.BoundedList send_history
          BoundedList.
private  java.util.HashMap sent
          Captures stats on XMIT_REQS, XMIT_RSPS per sender
private  java.util.TreeMap sent_msgs
          TreeMap.
private  long seqno
           
private  int stats_list_size
           
private  org.jgroups.util.TimeScheduler timer
           
private  boolean use_mcast_xmit
          Retransmit messages using multicast rather than unicast.
private  boolean xmit_from_random_member
          Ask a random member for retransmission of a missing message.
private  long xmit_reqs_received
           
private  long xmit_reqs_sent
           
private  long xmit_rsps_received
           
private  long xmit_rsps_sent
           
 
Fields inherited from class org.jgroups.stack.Protocol
down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, stats, trace, up_handler, up_prot, up_queue, up_thread, up_thread_prio, warn
 
Constructor Summary
NAKACK()
           
 
Method Summary
private  void adjustReceivers()
          Remove old members from NakReceiverWindows and add new members (starting seqno=0).
private  void clear()
           
private  org.jgroups.stack.NakReceiverWindow createNakReceiverWindow(org.jgroups.Address sender, long initial_seqno)
           
 void down(org.jgroups.Event evt)
          Callback.
 java.util.Map dumpStats()
           
private  Digest getDigest()
          Returns a message digest: for each member P the highest seqno received from P is added to the digest.
private  Digest getDigestHighestDeliveredMsgs()
          Returns a message digest: for each member P the highest seqno received from P without a gap is added to the digest.
 int getGcLag()
           
private  long getHighSeqnoSeen(org.jgroups.Address sender)
          Returns the highest seqno seen from sender.
private  org.jgroups.util.Range getLowestAndHighestSeqno(org.jgroups.Address sender, boolean stop_at_gaps)
          Returns the lowest seqno still in cache (so it can be retransmitted) and the highest seqno received so far.
 int getMaxXmitBufSize()
           
 long getMaxXmitSize()
           
 long getMissingMessagesReceived()
           
 java.lang.String getName()
           
private  long getNextSeqno()
           
 int getPendingRetransmissionRequests()
           
 int getReceivedTableSize()
           
 int getSentTableSize()
           
 long getXmitRequestsReceived()
           
 long getXmitRequestsSent()
           
 long getXmitResponsesReceived()
           
 long getXmitResponsesSent()
           
private  void handleConfigEvent(java.util.HashMap map)
           
private  void handleMessage(org.jgroups.Message msg, NakAckHeader hdr)
          Finds the corresponding NakReceiverWindow and adds the message to it (according to seqno).
private  void handleXmitReq(org.jgroups.Address xmit_requester, long first_seqno, long last_seqno, org.jgroups.Address original_sender)
          Retransmit from sent-table, called when XMIT_REQ is received.
private  void handleXmitRsp(org.jgroups.Message msg)
           
 void init()
          Called after instance has been created (null constructor) and before protocol is started.
 boolean isDiscardDeliveredMsgs()
           
 boolean isUseMcastXmit()
           
 boolean isXmitFromRandomMember()
           
private  void mergeDigest(Digest d)
          For all members of the digest, adjust the NakReceiverWindows in the received_msgs hashtable.
 void missingMessageReceived(long seqno, org.jgroups.Message msg)
           
 java.lang.String printMessages()
           
 java.lang.String printSentMsgs()
           
 java.lang.String printStats()
           
 java.util.Vector providedDownServices()
          List of events that are provided to layers below (they will be handled when sent down from below).
 java.util.Vector providedUpServices()
          List of events that are provided to layers above (they will be handled when sent down from above).
private  void removeAll()
           
 void resetStats()
           
 void retransmit(long first_seqno, long last_seqno, org.jgroups.Address sender)
          Implementation of Retransmitter.RetransmitCommand.
private  void send(org.jgroups.Event evt, org.jgroups.Message msg)
          Adds the message to the sent_msgs table and then passes it down the stack.
private  void sendXmitRsp(org.jgroups.Address dest, java.util.LinkedList xmit_list, long first_seqno, long last_seqno)
           
private  void setDigest(Digest d)
          Creates a NakReceiverWindow for each sender in the digest according to the sender's seqno.
 void setDiscardDeliveredMsgs(boolean discard_delivered_msgs)
           
 void setGcLag(int gc_lag)
           
 void setMaxXmitBufSize(int max_xmit_buf_size)
           
 void setMaxXmitSize(long max_xmit_size)
           
 boolean setProperties(java.util.Properties props)
          Configures the protocol initially.
 void setUseMcastXmit(boolean use_mcast_xmit)
           
 void setXmitFromRandomMember(boolean xmit_from_random_member)
           
private  void stable(Digest d)
          Garbage collect messages that have been seen by all members.
 void start()
          This method is called on a Channel.connect(String)>Channel.connect(String) 55 .
 void stop()
          This method is called on a Channel.disconnect()>Channel.disconnect() 55 .
 void up(org.jgroups.Event evt)
          Callback.
private static void updateStats(java.util.HashMap map, org.jgroups.Address key, int req, int rsp, int missing)
           
 
Methods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, enableStats, getDownProtocol, getDownQueue, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, isTrace, isWarn, passDown, passUp, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setPropertiesInternal, setProtocolStack, setTrace, setUpProtocol, setWarn, startDownHandler, startUpHandler, statsEnabled, stopInternal, upThreadEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

retransmit_timeout

private long[] retransmit_timeout

is_server

private boolean is_server

local_addr

private org.jgroups.Address local_addr

members

private final java.util.Vector members

seqno

private long seqno

max_xmit_size

private long max_xmit_size

gc_lag

private int gc_lag

use_mcast_xmit

private boolean use_mcast_xmit
Retransmit messages using multicast rather than unicast. This has the advantage that, if many receivers lost a message, the sender only retransmits once.


xmit_from_random_member

private boolean xmit_from_random_member
Ask a random member for retransmission of a missing message. If set to true, discard_delivered_msgs will be set to false


discard_delivered_msgs

private boolean discard_delivered_msgs
Messages that have been received in order are sent up the stack (= delivered to the application). Delivered messages are removed from NakReceiverWindow.received_msgs and moved to NakReceiverWindow.delivered_msgs, where they are later garbage collected (by STABLE). Since we do retransmits only from sent messages, never received or delivered messages, we can turn the moving to delivered_msgs off, so we don't keep the message around, and don't need to wait for garbage collection to remove them.


max_xmit_buf_size

private int max_xmit_buf_size
If value is > 0, the retransmit buffer is bounded: only the max_xmit_buf_size latest messages are kept, older ones are discarded when the buffer size is exceeded. A value <= 0 means unbounded buffers


received_msgs

private final java.util.HashMap received_msgs
Hashtable. Stores received messages (keyed by sender). Note that this is no long term storage; messages are just stored until they can be delivered (ie., until the correct FIFO order is established)


sent_msgs

private final java.util.TreeMap sent_msgs
TreeMap. Map of messages sent by me (keyed and sorted on sequence number)


leaving

private boolean leaving

timer

private org.jgroups.util.TimeScheduler timer

name

private static final java.lang.String name
See Also:
Constant Field Values

xmit_reqs_received

private long xmit_reqs_received

xmit_reqs_sent

private long xmit_reqs_sent

xmit_rsps_received

private long xmit_rsps_received

xmit_rsps_sent

private long xmit_rsps_sent

missing_msgs_received

private long missing_msgs_received

sent

private java.util.HashMap sent
Captures stats on XMIT_REQS, XMIT_RSPS per sender


received

private java.util.HashMap received
Captures stats on XMIT_REQS, XMIT_RSPS per receiver


stats_list_size

private int stats_list_size

receive_history

private org.jgroups.util.BoundedList receive_history
BoundedList. Keeps track of the last stats_list_size XMIT requests


send_history

private org.jgroups.util.BoundedList send_history
BoundedList. Keeps track of the last stats_list_size missing messages received

Constructor Detail

NAKACK

public NAKACK()
Method Detail

getName

public java.lang.String getName()

getXmitRequestsReceived

public long getXmitRequestsReceived()

getXmitRequestsSent

public long getXmitRequestsSent()

getXmitResponsesReceived

public long getXmitResponsesReceived()

getXmitResponsesSent

public long getXmitResponsesSent()

getMissingMessagesReceived

public long getMissingMessagesReceived()

getPendingRetransmissionRequests

public int getPendingRetransmissionRequests()

getSentTableSize

public int getSentTableSize()

getReceivedTableSize

public int getReceivedTableSize()

resetStats

public void resetStats()

init

public void init()
          throws java.lang.Exception
Description copied from class: org.jgroups.stack.Protocol
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.


getGcLag

public int getGcLag()

setGcLag

public void setGcLag(int gc_lag)

isUseMcastXmit

public boolean isUseMcastXmit()

setUseMcastXmit

public void setUseMcastXmit(boolean use_mcast_xmit)

isXmitFromRandomMember

public boolean isXmitFromRandomMember()

setXmitFromRandomMember

public void setXmitFromRandomMember(boolean xmit_from_random_member)

isDiscardDeliveredMsgs

public boolean isDiscardDeliveredMsgs()

setDiscardDeliveredMsgs

public void setDiscardDeliveredMsgs(boolean discard_delivered_msgs)

getMaxXmitBufSize

public int getMaxXmitBufSize()

setMaxXmitBufSize

public void setMaxXmitBufSize(int max_xmit_buf_size)

getMaxXmitSize

public long getMaxXmitSize()

setMaxXmitSize

public void setMaxXmitSize(long max_xmit_size)

setProperties

public boolean setProperties(java.util.Properties props)
Description copied from class: org.jgroups.stack.Protocol
Configures the protocol initially. A configuration string consists of name=value items, separated by a ';' (semicolon), e.g.:
 "loopback=false;unicast_inport=4444"
 


dumpStats

public java.util.Map dumpStats()

printStats

public java.lang.String printStats()

providedUpServices

public java.util.Vector providedUpServices()
Description copied from class: org.jgroups.stack.Protocol
List of events that are provided to layers above (they will be handled when sent down from above).


providedDownServices

public java.util.Vector providedDownServices()
Description copied from class: org.jgroups.stack.Protocol
List of events that are provided to layers below (they will be handled when sent down from below).


start

public void start()
           throws java.lang.Exception
Description copied from class: org.jgroups.stack.Protocol
This method is called on a Channel.connect(String)>Channel.connect(String) 55 . Starts work. Protocols are connected and queues are ready to receive events. Will be called from bottom to top. This call will replace the START and START_OK events.


stop

public void stop()
Description copied from class: org.jgroups.stack.Protocol
This method is called on a Channel.disconnect()>Channel.disconnect() 55 . Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed


down

public void down(org.jgroups.Event evt)
Callback. Called by superclass when event may be handled.

Do not use passDown() in this method as the event is passed down by default by the superclass after this method returns !


up

public void up(org.jgroups.Event evt)
Callback. Called by superclass when event may be handled.

Do not use PassUp in this method as the event is passed up by default by the superclass after this method returns !


getNextSeqno

private long getNextSeqno()

send

private void send(org.jgroups.Event evt,
                  org.jgroups.Message msg)
Adds the message to the sent_msgs table and then passes it down the stack. Change Bela Ban May 26 2002: we don't store a copy of the message, but a reference ! This saves us a lot of memory. However, this also means that a message should not be changed after storing it in the sent-table ! See protocols/DESIGN for details.


handleMessage

private void handleMessage(org.jgroups.Message msg,
                           NakAckHeader hdr)
Finds the corresponding NakReceiverWindow and adds the message to it (according to seqno). Then removes as many messages as possible from the NRW and passes them up the stack. Discards messages from non-members.


handleXmitReq

private void handleXmitReq(org.jgroups.Address xmit_requester,
                           long first_seqno,
                           long last_seqno,
                           org.jgroups.Address original_sender)
Retransmit from sent-table, called when XMIT_REQ is received. Bundles all messages to be xmitted into one large message and sends them back with an XMIT_RSP header. Note that since we cannot count on a fragmentation layer below us, we have to make sure the message doesn't exceed max_xmit_size bytes. If this is the case, we split the message into multiple, smaller-chunked messages. But in most cases this still yields fewer messages than if each requested message was retransmitted separately.


updateStats

private static void updateStats(java.util.HashMap map,
                                org.jgroups.Address key,
                                int req,
                                int rsp,
                                int missing)

sendXmitRsp

private void sendXmitRsp(org.jgroups.Address dest,
                         java.util.LinkedList xmit_list,
                         long first_seqno,
                         long last_seqno)

handleXmitRsp

private void handleXmitRsp(org.jgroups.Message msg)

adjustReceivers

private void adjustReceivers()
Remove old members from NakReceiverWindows and add new members (starting seqno=0). Essentially removes all entries from received_msgs that are not in members


getDigest

private Digest getDigest()
Returns a message digest: for each member P the highest seqno received from P is added to the digest.


getDigestHighestDeliveredMsgs

private Digest getDigestHighestDeliveredMsgs()
Returns a message digest: for each member P the highest seqno received from P without a gap is added to the digest. E.g. if the seqnos received from P are [+3 +4 +5 -6 +7 +8], then 5 will be returned. Also, the highest seqno seen is added. The max of all highest seqnos seen will be used (in STABLE) to determine whether the last seqno from a sender was received (see "Last Message Dropped" topic in DESIGN).


setDigest

private void setDigest(Digest d)
Creates a NakReceiverWindow for each sender in the digest according to the sender's seqno. If NRW already exists, reset it.


mergeDigest

private void mergeDigest(Digest d)
For all members of the digest, adjust the NakReceiverWindows in the received_msgs hashtable. If the member already exists, sets its seqno to be the max of the seqno and the seqno of the member in the digest. If no entry exists, create one with the initial seqno set to the seqno of the member in the digest.


createNakReceiverWindow

private org.jgroups.stack.NakReceiverWindow createNakReceiverWindow(org.jgroups.Address sender,
                                                                    long initial_seqno)

getLowestAndHighestSeqno

private org.jgroups.util.Range getLowestAndHighestSeqno(org.jgroups.Address sender,
                                                        boolean stop_at_gaps)
Returns the lowest seqno still in cache (so it can be retransmitted) and the highest seqno received so far.


getHighSeqnoSeen

private long getHighSeqnoSeen(org.jgroups.Address sender)
Returns the highest seqno seen from sender. E.g. if we received 1, 2, 4, 5 from P, then 5 will be returned (doesn't take gaps into account). If we are the sender, we will return the highest seqno sent rather then received


stable

private void stable(Digest d)
Garbage collect messages that have been seen by all members. Update sent_msgs: for the sender P in the digest which is equal to the local address, garbage collect all messages <= seqno at digest[P]. Update received_msgs: for each sender P in the digest and its highest seqno seen SEQ, garbage collect all delivered_msgs in the NakReceiverWindow corresponding to P which are <= seqno at digest[P].


retransmit

public void retransmit(long first_seqno,
                       long last_seqno,
                       org.jgroups.Address sender)
Implementation of Retransmitter.RetransmitCommand. Called by retransmission thread when gap is detected.

Specified by:
retransmit in interface org.jgroups.stack.Retransmitter.RetransmitCommand

missingMessageReceived

public void missingMessageReceived(long seqno,
                                   org.jgroups.Message msg)
Specified by:
missingMessageReceived in interface org.jgroups.stack.NakReceiverWindow.Listener

clear

private void clear()

removeAll

private void removeAll()

printMessages

public java.lang.String printMessages()

printSentMsgs

public java.lang.String printSentMsgs()

handleConfigEvent

private void handleConfigEvent(java.util.HashMap map)