org.objectweb.dream.queue.keyed
Class BufferAscendingKeyKeyChunkAddDoubleKeyedRemoveImpl

java.lang.Object
  extended by org.objectweb.dream.AbstractComponent
      extended by org.objectweb.dream.queue.keyed.BufferAscendingKeyKeyChunkAddDoubleKeyedRemoveImpl
All Implemented Interfaces:
ContextualBindingController, NeedAsyncStartController, PrepareStopLifeCycleController, Loggable, BufferAttributeController, BufferAttributeControllerAscendingKeyKeyChunkAdd, BufferAttributeControllerKeyChunkAdd, BufferAttributeControllerKeyed, DoubleKeyedBufferRemove, KeyedBufferAdd, AttributeController, BindingController, LifeCycleController

public class BufferAscendingKeyKeyChunkAddDoubleKeyedRemoveImpl
extends AbstractComponent
implements KeyedBufferAdd, DoubleKeyedBufferRemove, BufferAttributeControllerAscendingKeyKeyChunkAdd

This buffer stores every incoming message according to

Messages can then be removed from the buffer using the remove(Object, Object) method. This method returns the message with the highest key for the specified keyChunk key.


Field Summary
protected static String[] CLIENT_INTERFACE_NAMES
          The names of client interfaces.
protected  String keyChunkName
           
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 DoubleKeyedBufferRemove.removeAll().
protected  Map<AbstractChunk,TreeMap<Object,Message>> queue
          Used to sort the messages according to the key stored in each message as a chunk.
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.keyed.KeyedBufferAdd
ITF_NAME
 
Fields inherited from interface org.objectweb.dream.queue.keyed.DoubleKeyedBufferRemove
ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Constructor Summary
BufferAscendingKeyKeyChunkAddDoubleKeyedRemoveImpl()
           
 
Method Summary
 void add(Message message, Object key)
          Adds the specified message to the buffer, associated with the specified key object.
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  void doAdd(Message message, Object key)
           
 Message get(Object key1, Object key2)
          Gets the message from the buffer that is associated with the specified keys.
 int getCurrentSize()
          Returns the current size of the queue.
 String getKeyChunkName()
          Returns the name of the chunk that is used as a key.
 Object[] getKeys()
          Returns an array containing the keys that are used in the buffer.
 int getMaxCapacity()
          Returns the maximum capacity of the queue.
protected  void incrementStoredMessagesCount(int delta, Object key)
          Increments the count of stored messages.
 String[] listFc()
           
 Message remove(Object key1, Object key2)
          Removes the message from the buffer that is associated with the specified keys.
 Message removeAll()
          Removes all the available messages from the buffer.
 Message removeAll(Object key)
          Removes all the available messages from the buffer that maps the specified key.
 void setKeyChunkName(String keyChunkName)
          Sets the name of the chunk that is used as a key.
 void setMaxCapacity(int maxCapacity)
          Sets the maximum capacity of the queue.
 boolean tryAdd(Message message, Object key)
          Adds the specified message to the buffer, associated with the specified key object.
 Message tryGet(Object key1, Object key2)
          Gets the message from the buffer that is associated with the specified keys.
 Message tryRemove(Object key1, Object key2)
          Removes the message from the buffer that is associated with the specified keys.
 
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 DoubleKeyedBufferRemove.removeAll().


maxCapacity

protected int maxCapacity
The maximal capacity of the buffer.


storedMessagesCount

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


keyChunkName

protected String keyChunkName

queue

protected Map<AbstractChunk,TreeMap<Object,Message>> queue
Used to sort the messages according to the key stored in each message as a chunk.


lock

protected final Object lock
The lock object.

Constructor Detail

BufferAscendingKeyKeyChunkAddDoubleKeyedRemoveImpl

public BufferAscendingKeyKeyChunkAddDoubleKeyedRemoveImpl()
Method Detail

add

public void add(Message message,
                Object key)
         throws InterruptedException
Description copied from interface: KeyedBufferAdd
Adds the specified message to the buffer, associated with the specified key object. This method blocks while there is not enough space available, and while this buffer contains a message already associated with the specified key.

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 KeyedBufferAdd
Parameters:
message - the message to be added; never null.
key - the key that is associated with the message to be added; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be removed.
See Also:
KeyedBufferAdd.add(Message, Object)

tryAdd

public boolean tryAdd(Message message,
                      Object key)
Description copied from interface: KeyedBufferAdd
Adds the specified message to the buffer, associated with the specified key object. If the message cannot be added (due to space limitation, or if a message is already associated with the specified key), 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 KeyedBufferAdd
Parameters:
message - the message to be added; never null.
key - the key that is associated with the message to be added; never null.
Returns:
true if the message has been added.
See Also:
KeyedBufferAdd.tryAdd(Message, Object)

remove

public Message remove(Object key1,
                      Object key2)
               throws InterruptedException
Description copied from interface: DoubleKeyedBufferRemove
Removes the message from the buffer that is associated with the specified keys. This method blocks while no message associated with the specified keys is available.

Specified by:
remove in interface DoubleKeyedBufferRemove
Parameters:
key1 - the first key that is associated with the message to get; never null.
key2 - the second key that is associated with the message to get; can be null.
Returns:
the removed message that was associated with the specified keys; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
DoubleKeyedBufferRemove.remove(Object, Object)

tryRemove

public Message tryRemove(Object key1,
                         Object key2)
Description copied from interface: DoubleKeyedBufferRemove
Removes the message from the buffer that is associated with the specified keys. This method does not block.

Specified by:
tryRemove in interface DoubleKeyedBufferRemove
Parameters:
key1 - the first key that is associated with the message to get; never null.
key2 - the second key that is associated with the message to get; can be null.
Returns:
the removed message that was associated with the specified key if there was one, null otherwise.
See Also:
DoubleKeyedBufferRemove.tryRemove(Object, Object)

get

public Message get(Object key1,
                   Object key2)
            throws InterruptedException
Description copied from interface: DoubleKeyedBufferRemove
Gets the message from the buffer that is associated with the specified keys. This method blocks while no message associated with the specified keys is available.

Specified by:
get in interface DoubleKeyedBufferRemove
Parameters:
key1 - the first key that is associated with the message to get; never null.
key2 - the second key that is associated with the message to get; can be null.
Returns:
the message that is associated with the specified key; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
DoubleKeyedBufferRemove.get(Object, Object)

tryGet

public Message tryGet(Object key1,
                      Object key2)
Description copied from interface: DoubleKeyedBufferRemove
Gets the message from the buffer that is associated with the specified keys. This method does not block.

Specified by:
tryGet in interface DoubleKeyedBufferRemove
Parameters:
key1 - the first key that is associated with the message to get; never null.
key2 - the second key that is associated with the message to get; can be null.
Returns:
the message that is associated with the specified keys if there is one, null otherwise.
See Also:
DoubleKeyedBufferRemove.tryGet(Object, Object)

removeAll

public Message removeAll(Object key)
Description copied from interface: DoubleKeyedBufferRemove
Removes all the available messages from the buffer that maps the specified key. 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 DoubleKeyedBufferRemove
Parameters:
key - the key which messages that are removed must match.
Returns:
an aggregated message containing all the messages available from the buffer, or null if no message was available.
See Also:
DoubleKeyedBufferRemove.removeAll(Object)

removeAll

public Message removeAll()
Description copied from interface: DoubleKeyedBufferRemove
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 DoubleKeyedBufferRemove
Returns:
an aggregated message containing all the messages available from the buffer, or null if no message was available.
See Also:
DoubleKeyedBufferRemove.removeAll()

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.

doAdd

protected void doAdd(Message message,
                     Object key)

availableSpace

protected int availableSpace()

incrementStoredMessagesCount

protected void incrementStoredMessagesCount(int delta,
                                            Object key)
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()

setKeyChunkName

public void setKeyChunkName(String keyChunkName)
Description copied from interface: BufferAttributeControllerKeyChunkAdd
Sets the name of the chunk that is used as a key.

Specified by:
setKeyChunkName in interface BufferAttributeControllerKeyChunkAdd
Parameters:
keyChunkName - the name of the chunk.
See Also:
BufferAttributeControllerKeyChunkAdd.setKeyChunkName(String)

getKeyChunkName

public String getKeyChunkName()
Description copied from interface: BufferAttributeControllerKeyChunkAdd
Returns the name of the chunk that is used as a key.

Specified by:
getKeyChunkName in interface BufferAttributeControllerKeyChunkAdd
Returns:
the name of the chunk that is used as a key.
See Also:
BufferAttributeControllerKeyChunkAdd.getKeyChunkName()

getKeys

public Object[] getKeys()
Description copied from interface: BufferAttributeControllerKeyed
Returns an array containing the keys that are used in the buffer.

Specified by:
getKeys in interface BufferAttributeControllerKeyed
Returns:
an array containing the keys that are used in the buffer.
See Also:
BufferAttributeControllerKeyed.getKeys()

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.