org.jgroups.protocols
Class UNICAST2

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by 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

Nested Class Summary
static class UNICAST2.Unicast2Header
          The following types and fields are serialized:
 
Field Summary
static long DEFAULT_FIRST_SEQNO
           
protected  long max_bytes
           
protected  long max_retransmit_time
           
protected  int max_stable_msgs
           
protected  long stable_interval
           
 
Fields inherited from class org.jgroups.stack.Protocol
down_prot, ergonomics, id, log, name, stack, stats, up_prot
 
Constructor Summary
UNICAST2()
           
 
Method Summary
 void compact()
           
 java.lang.Object down(Event evt)
          An event is to be sent down the stack.
 java.util.Map<java.lang.String,java.lang.Object> dumpStats()
           
 void expired(Address key)
          Called by AgeOutCache, to removed expired connections
 AgeOutCache<Address> getAgeOutCache()
           
 int getAgeOutCacheSize()
           
 java.lang.String getLocalAddress()
           
 long getMaxRetransmitTime()
           
 java.lang.String getMembers()
           
 int getNumberOfMessagesInReceiveWindows()
           
 long getNumberOfRetransmissions()
           
 long getNumBytesReceived()
           
 long getNumBytesSent()
           
 long getNumMessagesReceived()
           
 long getNumMessagesSent()
           
 long[] getTimeout()
           
 TimeScheduler getTimer()
           
 void init()
          Called after instance has been created (null constructor) and before protocol is started.
 java.lang.String printAgeOutCache()
           
 java.lang.String printConnections()
           
 java.lang.String printRetransmitTableSizes()
           
 void purgeAndCompact()
           
 void removeAllConnections()
          This method is public only so it can be invoked by unit testing, but should not otherwise be used !
 void removeConnection(Address mbr)
          Removes and resets from connection table (which is already locked).
 void resetStats()
           
 void retransmit(long first_seqno, long last_seqno, Address sender)
          Get the missing messages between sequence numbers first_seqno and last_seqno.
protected  void sendStableMessage(Address dest, long low, long high)
           
 void sendStableMessages()
           
 void setMaxMessageBatchSize(int size)
           
 void setMaxRetransmitTime(long max_retransmit_time)
           
 void setTimeout(long[] val)
           
 void setTimer(TimeScheduler timer)
          Only used for unit tests, don't use !
protected  void stable(Address sender, long highest_delivered, long highest_seen)
          Purge all messages in window for local_addr, which are <= low.
 void start()
          This method is called on a Channel.connect(String).
 void stop()
          This method is called on a Channel.disconnect().
 java.lang.Object up(Event evt)
          An event was received from the layer below.
 
Methods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, enableStats, getConfigurableObjects, getDownProtocol, getId, getLevel, getName, getProperties, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getValue, isErgonomics, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, setDownProtocol, setErgonomics, setId, setLevel, setProperties, setPropertiesInternal, setProperty, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, statsEnabled, upThreadEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FIRST_SEQNO

public static final long DEFAULT_FIRST_SEQNO
See Also:
Constant Field Values

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 Detail

UNICAST2

public UNICAST2()
Method Detail

getTimeout

public long[] getTimeout()

setTimeout

public void setTimeout(long[] val)

setMaxMessageBatchSize

public void setMaxMessageBatchSize(int size)

getLocalAddress

public java.lang.String getLocalAddress()

getMembers

public java.lang.String getMembers()

printConnections

public java.lang.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 java.lang.String printAgeOutCache()

getAgeOutCache

public AgeOutCache<Address> getAgeOutCache()

getNumberOfMessagesInReceiveWindows

public int getNumberOfMessagesInReceiveWindows()

printRetransmitTableSizes

public java.lang.String printRetransmitTableSizes()

compact

public void compact()

purgeAndCompact

public void purgeAndCompact()

resetStats

public void resetStats()
Overrides:
resetStats in class Protocol

dumpStats

public java.util.Map<java.lang.String,java.lang.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 java.lang.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:
java.lang.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 java.lang.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:
java.lang.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 java.lang.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 java.lang.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 <= 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 -


Copyright © 1998-2009 Bela Ban / Red Hat. All Rights Reserved.