org.jgroups.stack
Class AckReceiverWindow

java.lang.Object
  extended by org.jgroups.stack.AckReceiverWindow

public class AckReceiverWindow
extends java.lang.Object

Counterpart of AckSenderWindow. Simple FIFO buffer. Every message received is ACK'ed (even duplicates) and added to a hashmap keyed by seqno. The next seqno to be received is stored in next_to_remove. When a message with a seqno less than next_to_remove is received, it will be discarded. The remove() method removes and returns a message whose seqno is equal to next_to_remove, or null if not found.
Change May 28 2002 (bela): replaced TreeSet with HashMap. Keys do not need to be sorted, and adding a key to a sorted set incurs overhead.

Version:
$Id: AckReceiverWindow.java,v 1.41 2010/01/20 11:42:04 belaban Exp $
Author:
Bela Ban

Constructor Summary
AckReceiverWindow(long initial_seqno)
           
 
Method Summary
 boolean add(long seqno, Message msg)
          Adds a new message.
 byte add2(long seqno, Message msg)
          Adds a message if not yet received
 java.util.concurrent.atomic.AtomicBoolean getProcessing()
           
 boolean hasMessagesToRemove()
           
 java.lang.String printDetails()
           
 Message remove()
          Removes a message whose seqno is equal to next_to_remove, increments the latter.
 java.util.List<Message> removeMany()
          Removes as many messages as possible (in sequence, without gaps)
 Message removeOOBMessage()
           
 long removeOOBMessages()
          Removes as many OOB messages as possible and return the highest seqno
 void reset()
           
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AckReceiverWindow

public AckReceiverWindow(long initial_seqno)
Method Detail

getProcessing

public java.util.concurrent.atomic.AtomicBoolean getProcessing()

add

public boolean add(long seqno,
                   Message msg)
Adds a new message. Message cannot be null

Returns:
True if the message was added, false if not (e.g. duplicate, message was already present)

add2

public byte add2(long seqno,
                 Message msg)
Adds a message if not yet received

Parameters:
seqno -
msg -
Returns:
-1 if not added because seqno < next_to_remove, 0 if not added because already present, 1 if added successfully

remove

public Message remove()
Removes a message whose seqno is equal to next_to_remove, increments the latter. Returns message that was removed, or null, if no message can be removed. Messages are thus removed in order.


removeMany

public java.util.List<Message> removeMany()
Removes as many messages as possible (in sequence, without gaps)

Returns:

removeOOBMessage

public Message removeOOBMessage()

removeOOBMessages

public long removeOOBMessages()
Removes as many OOB messages as possible and return the highest seqno

Returns:
the highest seqno or -1 if no OOB message was found

hasMessagesToRemove

public boolean hasMessagesToRemove()

reset

public void reset()

size

public int size()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

printDetails

public java.lang.String printDetails()


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