org.objectweb.dream.queue
Class AbstractBufferImpl

java.lang.Object
  extended byorg.objectweb.dream.AbstractComponent
      extended byorg.objectweb.dream.queue.AbstractBufferImpl
All Implemented Interfaces:
AttributeController, BindingController, Buffer, BufferAddFirstLast, BufferRemoveFirstLast, LifeCycleController, Loggable, QueueAttributeController
Direct Known Subclasses:
BufferAscendingSequenceNumberImpl, BufferImpl

public abstract class AbstractBufferImpl
extends AbstractComponent
implements Buffer, BufferAddFirstLast, BufferRemoveFirstLast, QueueAttributeController

Abstract implementation of a buffer. It implements PushQueueAttributeController,Buffer, BufferAddFirstLast, and BufferRemoveFirstLastinterfaces.

Implementations of add, and remove methods (and their variants: addFirst,addLast, removeFirst,removeLast, getFirst, and getLast) are implemented as follows

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

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

Note: the add,remove, addFirst,addLast,removeFirst, removeLast,getFirst, and getLast methods should not be overriden.


Field Summary
protected  int availableMessagesIndicator
          An indicator on available messages into the buffer.
protected  Object lock
          A lock object.
protected  int maxCapacity
          The maximal capacity of the buffer.
protected  MessageManager messageManagerItf
          The MessageManager client interface.
protected  int storedMessagesIndicator
          An indicator on stored messages into the buffer.
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, componentDesc, fcState, firstStart, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.dream.queue.Buffer
ITF_NAME
 
Fields inherited from interface org.objectweb.dream.queue.BufferAddFirstLast
ITF_NAME
 
Fields inherited from interface org.objectweb.dream.queue.BufferRemoveFirstLast
ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Constructor Summary
AbstractBufferImpl()
           
 
Method Summary
 void add(Message message)
          This method should not be overriden.
 void addFirst(Message message)
          Inserts the given message at the beginning of this buffer.
 void addLast(Message message)
          Inserts the given message at the end of this buffer.
 int availableMessagesIndicator()
          Returns an indicator on available messages.
 int availableSpaceIndicator()
          Returns an indicator on available space.
 void bindFc(String clientItfName, Object serverItf)
           
protected abstract  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  void doAddFirst(Message message)
          Adds a message to the beginning of the buffer.
protected  void doAddLast(Message message)
          Adds a message to end of the buffer.
protected abstract  Message doGet()
          Gets a message from the buffer.
protected  Message doGetFirst()
          Gets the first message from the buffer.
protected  Message doGetLast()
          Gets the last message from the buffer.
protected abstract  Message doRemove()
          Removes a message from the buffer.
protected  Message doRemoveFirst()
          Removes the first message from the buffer.
protected  Message doRemoveLast()
          Removes the last message from the buffer.
 Message get()
          This method should not be overriden.
 int getCurrentSize()
          Returns the current size of the queue.
 Message getFirst()
          Returns the first message in this buffer.
 Message getLast()
          Returns the last message in this buffer.
 int getMaxCapacity()
          Returns the maximum capacity of the queue.
protected abstract  boolean hasAvailableMessage()
          Checks whether there is an available message.
protected  void incrementAvailableMessagesIndicator(int delta)
          Increments the indicator on available messages.
protected  void incrementStoredMessagesIndicator(int delta)
          Increments the indicator on stored messages.
 String[] listFc()
           
 Message remove()
          This method should not be overriden.
 Message removeFirst()
          Removes and returns the first message from this buffer.
 Message removeLast()
          Removes and returns the last message from this buffer.
 void setMaxCapacity(int maxCapacity)
          Sets the maximum capacity of the queue.
 int storedMessagesIndicator()
          Returns an indicator on stored messages.
 
Methods inherited from class org.objectweb.dream.AbstractComponent
beforeFirstStart, getFcState, initComponent, lookupFc, setLogger, startFc, stopFc, unbindFc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageManagerItf

protected MessageManager messageManagerItf
The MessageManager client interface.


maxCapacity

protected int maxCapacity
The maximal capacity of the buffer.


availableMessagesIndicator

protected int availableMessagesIndicator
An indicator on available messages into the buffer. This indicator should only be updated using the incrementAvailableMessagesIndicator method.


storedMessagesIndicator

protected int storedMessagesIndicator
An indicator on stored messages into the buffer. This indicator should only be updated using the incrementStoredMessagesIndicator method.


lock

protected final Object lock
A lock object.

Constructor Detail

AbstractBufferImpl

public AbstractBufferImpl()
Method Detail

availableMessagesIndicator

public int availableMessagesIndicator()
Description copied from interface: Buffer
Returns an indicator on available messages. The semantic of this indicator depends on the buffer implementation. Typical examples of indicators are the number of messages, the number of bytes, etc.

Specified by:
availableMessagesIndicator in interface Buffer
Returns:
an indicator on available messages.
See Also:
Buffer.availableMessagesIndicator()

storedMessagesIndicator

public int storedMessagesIndicator()
Description copied from interface: Buffer
Returns an indicator on stored messages. The semantic of this indicator depends on the buffer implementation. Typical examples of indicators are the number of messages, the number of bytes, etc.

Specified by:
storedMessagesIndicator in interface Buffer
Returns:
an indicator on stored messages.
See Also:
Buffer.storedMessagesIndicator()

availableSpaceIndicator

public int availableSpaceIndicator()
Description copied from interface: Buffer
Returns an indicator on available space. The semantic of this indicator depends on the buffer implementation. Typical examples of indicators are the number of messages, the number of bytes, etc. Note: when the buffer has no maximum storage capabilities, this method must return Integer.MAX_VALUE.

Specified by:
availableSpaceIndicator in interface Buffer
Returns:
an indicator on available space.
See Also:
Buffer.availableSpaceIndicator()

add

public void add(Message message)
         throws InterruptedException
This method should not be overriden.

Specified by:
add in interface Buffer
Parameters:
message - message to be addedto be appended to this list.
Throws:
InterruptedException - if it is interrupted while adding the message.
See Also:
Buffer.add(org.objectweb.dream.message.Message)

remove

public Message remove()
               throws InterruptedException
This method should not be overriden.

Specified by:
remove in interface Buffer
Returns:
a message.
Throws:
InterruptedException - if it is interrupted while removing a message.
See Also:
Buffer.remove()

get

public Message get()
            throws InterruptedException
This method should not be overriden.

Specified by:
get in interface Buffer
Returns:
a message.
Throws:
InterruptedException - if it is interrupted while removing a message.
See Also:
Buffer.get()

addFirst

public void addFirst(Message message)
              throws InterruptedException
Description copied from interface: BufferAddFirstLast
Inserts the given message at the beginning of this buffer.

Specified by:
addFirst in interface BufferAddFirstLast
Parameters:
message - the message to be inserted at the beginning of this buffer.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be removed.
See Also:
BufferAddFirstLast.addFirst(org.objectweb.dream.message.Message)

addLast

public void addLast(Message message)
             throws InterruptedException
Description copied from interface: BufferAddFirstLast
Inserts the given message at the end of this buffer.

Specified by:
addLast in interface BufferAddFirstLast
Parameters:
message - the message to be inserted at the end of this buffer.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be removed.
See Also:
BufferAddFirstLast.addLast(org.objectweb.dream.message.Message)

getFirst

public Message getFirst()
                 throws InterruptedException
Description copied from interface: BufferRemoveFirstLast
Returns the first message in this buffer. If no message is available, this method blocks.

Specified by:
getFirst in interface BufferRemoveFirstLast
Returns:
the first message in this list.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemoveFirstLast.getFirst()

getLast

public Message getLast()
                throws InterruptedException
Description copied from interface: BufferRemoveFirstLast
Returns the last message in this buffer. If no message is available, this method blocks.

Specified by:
getLast in interface BufferRemoveFirstLast
Returns:
the last message in this list.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemoveFirstLast.getLast()

removeFirst

public Message removeFirst()
                    throws InterruptedException
Description copied from interface: BufferRemoveFirstLast
Removes and returns the first message from this buffer. If no message is available, this method blocks.

Specified by:
removeFirst in interface BufferRemoveFirstLast
Returns:
the first message from this buffer.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemoveFirstLast.removeFirst()

removeLast

public Message removeLast()
                   throws InterruptedException
Description copied from interface: BufferRemoveFirstLast
Removes and returns the last message from this buffer. If no message is available, this method blocks.

Specified by:
removeLast in interface BufferRemoveFirstLast
Returns:
the last message from this buffer.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemoveFirstLast.removeLast()

incrementAvailableMessagesIndicator

protected void incrementAvailableMessagesIndicator(int delta)
Increments the indicator on available messages.

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

incrementStoredMessagesIndicator

protected void incrementStoredMessagesIndicator(int delta)
Increments the indicator on stored messages.

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

canAdd

protected abstract boolean canAdd(Message message)
Checks whether the given message can be added into the buffer.

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

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.

Parameters:
message - the message to be added.

hasAvailableMessage

protected abstract boolean hasAvailableMessage()
Checks whether there is an available message.

Returns:
true if there is an available message.

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.

Returns:
a 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 remove() method.

Returns:
a message.

doAddFirst

protected void doAddFirst(Message message)
Adds a message to the beginning of 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.

Parameters:
message - the message to be added.

doAddLast

protected void doAddLast(Message message)
Adds a message to end of 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.

Parameters:
message - the message to be added.

doGetFirst

protected Message doGetFirst()
Gets the first 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.

Returns:
a message.

doGetLast

protected Message doGetLast()
Gets the last 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.

Returns:
a message.

doRemoveFirst

protected Message doRemoveFirst()
Removes the first 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.

Returns:
a message.

doRemoveLast

protected Message doRemoveLast()
Removes the last 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.

Returns:
a message.

getMaxCapacity

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

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

setMaxCapacity

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

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

getCurrentSize

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

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

bindFc

public void bindFc(String clientItfName,
                   Object serverItf)
            throws NoSuchInterfaceException,
                   IllegalBindingException,
                   IllegalLifeCycleException
Specified by:
bindFc in interface BindingController
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, 2004 - INRIA Rhone-Alpes - All Rights Reserved.