org.objectweb.dream.queue
Class AbstractBufferImpl

java.lang.Object
  extended by org.objectweb.dream.AbstractComponent
      extended by org.objectweb.dream.queue.AbstractBufferImpl
All Implemented Interfaces:
ContextualBindingController, NeedAsyncStartController, PrepareStopLifeCycleController, Loggable, BufferAdd, BufferAttributeController, BufferRemove, AttributeController, BindingController, LifeCycleController
Direct Known Subclasses:
BufferAscendingSequenceNumberImpl, BufferFIFOImpl, BufferKeyMutexSortedImpl, BufferLIFOImpl, BufferMatchingImpl, BufferSortingImpl

public abstract class AbstractBufferImpl
extends AbstractComponent
implements BufferAdd, BufferRemove, BufferAttributeController

Abstract implementation of a buffer. It implements the BufferAttributeController,BufferAddand BufferRemove interfaces.

The add and remove methods are implemented as follows

Buffer developers can inherit this class. They must implement several methods:

Moreover developers must use the incrementAvailableMessagesCount and incrementStoredMessagesCount methods to increment indicators on stored messages, available messages and available space.

Note: the add and remove methods should not be overridden.


Field Summary
protected  int availableMessagesCount
          The count of available messages in the buffer.
protected static String[] CLIENT_INTERFACE_NAMES
          The names of client interfaces.
protected  Object lock
          The lock object.
protected  int maxCapacity
          The maximal capacity of the buffer.
protected  MessageManager messageManagerItf
          Can be used by subclasses to create aggregated messages in BufferRemove.removeAll().
protected  int storedMessagesCount
          The count of stored messages into the buffer.
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, fcNeedAsyncStart, fcState, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.dream.queue.BufferAdd
ITF_NAME
 
Fields inherited from interface org.objectweb.dream.queue.BufferRemove
ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Constructor Summary
AbstractBufferImpl()
           
 
Method Summary
 void add(Message message)
          Adds the specified message to the buffer.
protected  int availableSpace()
           
 void bindFc(String clientItfName, Object serverItf)
           
protected  boolean canAdd(Message message)
          Checks whether the given message can be added into the buffer.
protected abstract  void doAdd(Message message)
          Adds a message to the buffer.
protected abstract  Message doGet()
          Gets a message from the buffer.
protected abstract  Message doRemove()
          Removes a message from the buffer.
protected abstract  Message doRemoveAll()
          Removes all the messages stored into the buffer.
 Message get()
          Gets a message from the buffer.
 int getCurrentSize()
          Returns the current size of the queue.
 int getMaxCapacity()
          Returns the maximum capacity of the queue.
protected  boolean hasAvailableMessage()
          Checks whether there is a message available to get or remove.
protected  void incrementAvailableMessagesCount(int delta)
          Increments the count of available messages.
protected  void incrementStoredMessagesCount(int delta)
          Increments the count of stored messages.
 String[] listFc()
           
 Message remove()
          Removes a message from the buffer.
 Message removeAll()
          Removes all the available messages from the buffer.
 void setMaxCapacity(int maxCapacity)
          Sets the maximum capacity of the queue.
 boolean tryAdd(Message message)
          Adds the specified message to the buffer.
 Message tryGet()
          Gets a message from the buffer.
 Message tryRemove()
          Removes a message from the buffer.
 
Methods inherited from class org.objectweb.dream.AbstractComponent
beforeFirstStart, bindFc, getFcNeedAsyncStart, getFcState, initComponent, lookupFc, prepareStopFc, setLogger, startFc, stopFc, unbindFc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLIENT_INTERFACE_NAMES

protected static final String[] CLIENT_INTERFACE_NAMES
The names of client interfaces.


messageManagerItf

protected MessageManager messageManagerItf
Can be used by subclasses to create aggregated messages in BufferRemove.removeAll().


maxCapacity

protected int maxCapacity
The maximal capacity of the buffer.


lock

protected final Object lock
The lock object.


availableMessagesCount

protected int availableMessagesCount
The count of available messages in the buffer. This attribute should only be updated using the incrementAvailableMessagesCount(int)method.


storedMessagesCount

protected int storedMessagesCount
The count of stored messages into the buffer. This attribute should only be updated using the incrementStoredMessagesCount(int)method.

Constructor Detail

AbstractBufferImpl

public AbstractBufferImpl()
Method Detail

add

public void add(Message message)
         throws InterruptedException
Description copied from interface: BufferAdd
Adds the specified message to the buffer. This method blocks if there is not enough space available.

Buffers may place limitations on what elements may be added to this buffer. In particular, some buffers require that messages contain particular chunks.

Specified by:
add in interface BufferAdd
Parameters:
message - the message to be added; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be removed.
See Also:
BufferAdd.add(Message)

tryAdd

public boolean tryAdd(Message message)
Description copied from interface: BufferAdd
Adds the specified message to the buffer. If the message cannot be added (due to space limitation), the message is not added.

Buffers may place limitations on what elements may be added to this buffer. In particular, some buffers require that messages contain particular chunks.

Specified by:
tryAdd in interface BufferAdd
Parameters:
message - the message to be added; never null.
Returns:
true if the message has been added.
See Also:
BufferAdd.tryAdd(Message)

remove

public Message remove()
               throws InterruptedException
Description copied from interface: BufferRemove
Removes a message from the buffer. This method blocks if no message is available.

Specified by:
remove in interface BufferRemove
Returns:
the removed message; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemove.remove()

tryRemove

public Message tryRemove()
Description copied from interface: BufferRemove
Removes a message from the buffer. This method does not block.

Specified by:
tryRemove in interface BufferRemove
Returns:
a message if there is one available, null otherwise.
See Also:
BufferRemove.tryRemove()

get

public Message get()
            throws InterruptedException
Description copied from interface: BufferRemove
Gets a message from the buffer. This method blocks if no message is available.

Specified by:
get in interface BufferRemove
Returns:
a message; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemove.get()

tryGet

public Message tryGet()
Description copied from interface: BufferRemove
Gets a message from the buffer. This method does not block.

Specified by:
tryGet in interface BufferRemove
Returns:
a message if there is one available, null otherwise.
See Also:
BufferRemove.tryGet()

removeAll

public Message removeAll()
Description copied from interface: BufferRemove
Removes all the available messages from the buffer. Messages are returned in an aggregated message. If no message has been removed, this method returns null. This method does not block.

Specified by:
removeAll in interface BufferRemove
Returns:
an aggregated message containing all the messages available from the buffer, or null if no message was available.
See Also:
BufferRemove.removeAll()

doAdd

protected abstract void doAdd(Message message)
Adds a message to the buffer. This method should not check if there is enough available space provided it has already been done in the add(org.objectweb.dream.message.Message)method. The lockhas been acquired when this method is called.

Parameters:
message - the message to be added.

doRemove

protected abstract Message doRemove()
Removes a message from the buffer. This method should not check if there is a message available provided it has already been done in the remove()method. The lockhas been acquired when this method is called.

Returns:
a message.

doRemoveAll

protected abstract Message doRemoveAll()
Removes all the messages stored into the buffer. The lockhas been acquired when this method is called.

Returns:
an aggregated message.

doGet

protected abstract Message doGet()
Gets a message from the buffer. This method should not check if there is a message available provided it has already been done in the get() method. The lockhas been acquired when this method is called.

Returns:
a message.

canAdd

protected boolean canAdd(Message message)
Checks whether the given message can be added into the buffer. The lockhas been acquired when this method is called.

Parameters:
message - the message to be tested.
Returns:
true if the message can be added.

hasAvailableMessage

protected boolean hasAvailableMessage()
Checks whether there is a message available to get or remove.

Returns:
true if there is an available message.

availableSpace

protected int availableSpace()

incrementAvailableMessagesCount

protected void incrementAvailableMessagesCount(int delta)
Increments the count of available messages. When calling this method, the lockmust have already been acquired.

Parameters:
delta - the value that must be added to the previous count.

incrementStoredMessagesCount

protected void incrementStoredMessagesCount(int delta)
Increments the count of stored messages. When calling this method, the lockmust have already been acquired.

Parameters:
delta - the value that must be added to previous indicator.

getMaxCapacity

public int getMaxCapacity()
Description copied from interface: BufferAttributeController
Returns the maximum capacity of the queue.

Specified by:
getMaxCapacity in interface BufferAttributeController
Returns:
the maximum capacity of the queue.
See Also:
BufferAttributeController.getMaxCapacity()

setMaxCapacity

public void setMaxCapacity(int maxCapacity)
Description copied from interface: BufferAttributeController
Sets the maximum capacity of the queue.

Specified by:
setMaxCapacity in interface BufferAttributeController
Parameters:
maxCapacity - the maximum capacity of the queue.
See Also:
BufferAttributeController.setMaxCapacity(int)

getCurrentSize

public int getCurrentSize()
Description copied from interface: BufferAttributeController
Returns the current size of the queue.

Specified by:
getCurrentSize in interface BufferAttributeController
Returns:
the current size of the queue.
See Also:
BufferAttributeController.getCurrentSize()

bindFc

public void bindFc(String clientItfName,
                   Object serverItf)
            throws NoSuchInterfaceException,
                   IllegalBindingException,
                   IllegalLifeCycleException
Specified by:
bindFc in interface BindingController
Overrides:
bindFc in class AbstractComponent
Throws:
NoSuchInterfaceException
IllegalBindingException
IllegalLifeCycleException
See Also:
BindingController.bindFc(String, Object)

listFc

public String[] listFc()
Specified by:
listFc in interface BindingController
See Also:
BindingController.listFc()


Copyright © 2003, 2005 - INRIA Rhone-Alpes - All Rights Reserved.