Class UNICAST2

java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.UNICAST2
All Implemented Interfaces:
Retransmitter.RetransmitCommand, AgeOutCache.Handler<Address>

public class UNICAST2 extends Protocol implements Retransmitter.RetransmitCommand, AgeOutCache.Handler<Address>
Reliable unicast layer. Implemented with negative acks. Every sender keeps its messages in an AckSenderWindow. A receiver stores incoming messages in a NakReceiverWindow, and asks the sender for retransmission if a gap is detected. Every now and then (stable_interval), a timer task sends a STABLE message to all senders, including the highest received and delivered seqnos. A sender purges messages lower than highest delivered and asks the STABLE sender for messages it might have missed (smaller than highest received). A STABLE message can also be sent when a receiver has received more than max_bytes from a given sender.

The advantage of this protocol over UNICAST is that it doesn't send acks for every message. Instead, it sends 'acks' after receiving max_bytes and/ or periodically (stable_interval).

Author:
Bela Ban
  • Field Details

    • DEFAULT_FIRST_SEQNO

      public static final long DEFAULT_FIRST_SEQNO
      See Also:
    • max_bytes

      protected long max_bytes
    • stable_interval

      protected long stable_interval
    • max_stable_msgs

      protected int max_stable_msgs
    • max_retransmit_time

      protected long max_retransmit_time
  • Constructor Details

    • UNICAST2

      public UNICAST2()
  • Method Details

    • getTimeout

      public long[] getTimeout()
    • setTimeout

      public void setTimeout(long[] val)
    • setMaxMessageBatchSize

      public void setMaxMessageBatchSize(int size)
    • getLocalAddress

      public String getLocalAddress()
    • getMembers

      public String getMembers()
    • printConnections

      public String printConnections()
    • getNumMessagesSent

      public long getNumMessagesSent()
    • getNumMessagesReceived

      public long getNumMessagesReceived()
    • getNumBytesSent

      public long getNumBytesSent()
    • getNumBytesReceived

      public long getNumBytesReceived()
    • getNumberOfRetransmissions

      public long getNumberOfRetransmissions()
    • getMaxRetransmitTime

      public long getMaxRetransmitTime()
    • setMaxRetransmitTime

      public void setMaxRetransmitTime(long max_retransmit_time)
    • getAgeOutCacheSize

      public int getAgeOutCacheSize()
    • printAgeOutCache

      public String printAgeOutCache()
    • getAgeOutCache

      public AgeOutCache<Address> getAgeOutCache()
    • getNumberOfMessagesInReceiveWindows

      public int getNumberOfMessagesInReceiveWindows()
    • printRetransmitTableSizes

      public String printRetransmitTableSizes()
    • compact

      public void compact()
    • purgeAndCompact

      public void purgeAndCompact()
    • resetStats

      public void resetStats()
      Overrides:
      resetStats in class Protocol
    • dumpStats

      public Map<String,Object> dumpStats()
      Overrides:
      dumpStats in class Protocol
    • getTimer

      public TimeScheduler getTimer()
    • setTimer

      public void setTimer(TimeScheduler timer)
      Only used for unit tests, don't use !
      Parameters:
      timer -
    • init

      public void init() throws Exception
      Description copied from class: 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.
      Overrides:
      init in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception
    • start

      public void start() throws Exception
      Description copied from class: Protocol
      This method is called on a Channel.connect(String). 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.
      Overrides:
      start in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so Channel.connect(String) will throw an exception
    • stop

      public void stop()
      Description copied from class: Protocol
      This method is called on a Channel.disconnect(). 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
      Overrides:
      stop in class Protocol
    • up

      public Object up(Event evt)
      Description copied from class: Protocol
      An event was received from the layer below. Usually the current layer 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 using down_prot.down() or c) the event (or another event) is sent up the stack using up_prot.up().
      Overrides:
      up in class Protocol
    • down

      public Object down(Event evt)
      Description copied from class: Protocol
      An event is to be sent down the stack. The layer 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 layer may need to add a header to it (or do nothing at all) before sending it down the stack using down_prot.down(). In case of a GET_ADDRESS event (which tries to retrieve the stack's address from one of the bottom layers), the layer may need to send a new response event back up the stack using up_prot.up().
      Overrides:
      down in class Protocol
    • stable

      protected void stable(Address sender, long highest_delivered, long highest_seen)
      Purge all messages in window for local_addr, which are invalid input: '<'= low. Check if the window's highest received message is > high: if true, retransmit all messages from high - win.high to sender
      Parameters:
      sender -
      highest_delivered -
      highest_seen -
    • sendStableMessages

      public void sendStableMessages()
    • sendStableMessage

      protected void sendStableMessage(Address dest, long low, long high)
    • removeConnection

      public void removeConnection(Address mbr)
      Removes and resets from connection table (which is already locked). Returns true if member was found, otherwise false. This method is public only so it can be invoked by unit testing, but should not otherwise be used !
    • removeAllConnections

      public void removeAllConnections()
      This method is public only so it can be invoked by unit testing, but should not otherwise be used !
    • retransmit

      public void retransmit(long first_seqno, long last_seqno, Address sender)
      Description copied from interface: Retransmitter.RetransmitCommand
      Get the missing messages between sequence numbers first_seqno and last_seqno. This can either be done by sending a retransmit message to destination sender (nak-based scheme), or by retransmitting the missing message(s) to sender (ack-based scheme).
      Specified by:
      retransmit in interface Retransmitter.RetransmitCommand
      Parameters:
      first_seqno - The sequence number of the first missing message
      last_seqno - The sequence number of the last missing message
      sender - The destination of the member to which the retransmit request will be sent (nak-based scheme), or to which the message will be retransmitted (ack-based scheme).
    • expired

      public void expired(Address key)
      Called by AgeOutCache, to removed expired connections
      Specified by:
      expired in interface AgeOutCache.Handler<Address>
      Parameters:
      key -