|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.dream.AbstractComponent
org.objectweb.dream.queue.keyed.AbstractBufferKeyedAddKeyedRemoveImpl
public abstract class AbstractBufferKeyedAddKeyedRemoveImpl
Abstract implementation of a keyed buffer. Keyed buffers allow mapping
messages to keys. This class implements the BufferAttributeController
,
KeyedBufferAdd
and KeyedBufferRemove
interfaces. When a
message is added to the buffer, an associated key is specified. This key can
later be used to retrieve the message.
The add
and remove
methods are implemented as
follows
add
method checks for available space and then calls
the doAdd
method to add the message to the buffer.remove
method checks for available messages and then
calls the doRemove
method to remove a message from the buffer.
Buffer developers can inherit this class. They must implement several methods:
canAdd(message, key)
returns a boolean indicating whether
the given message can be added into the buffer.doAdd(message, key)
adds the given message into the
buffer.hasAvailableMessage(key)
returns a boolean indicating
whether there is an available message mapping the given key.doRemove(key)
removes a message from the buffer.
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 KeyedBufferRemove.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.keyed.KeyedBufferAdd |
---|
ITF_NAME |
Fields inherited from interface org.objectweb.dream.queue.keyed.KeyedBufferRemove |
---|
ITF_NAME |
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController |
---|
STARTED, STOPPED |
Constructor Summary | |
---|---|
AbstractBufferKeyedAddKeyedRemoveImpl()
|
Method Summary | |
---|---|
void |
add(Message message,
Object key)
Adds the specified message to the buffer, associated with the specified key object. |
protected int |
availableSpace(Object key)
|
void |
bindFc(String clientItfName,
Object serverItf)
|
protected boolean |
canAdd(Message message,
Object key)
Checks whether the given message can be added into the buffer. |
protected abstract void |
doAdd(Message message,
Object key)
Adds a message to the buffer. |
protected abstract Message |
doGet(Object key)
Gets a message from the buffer. |
protected abstract Message |
doRemove(Object key)
Removes a message from the buffer. |
protected abstract Message |
doRemoveAll()
Removes all the messages stored into the buffer. |
Message |
get(Object key)
Gets the message from the buffer that is associated with the specified key object. |
int |
getCurrentSize()
Returns the current size of the queue. |
int |
getMaxCapacity()
Returns the maximum capacity of the queue. |
protected boolean |
hasAvailableMessage(Object key)
Checks whether there is a message available to get or remove. |
protected void |
incrementAvailableMessagesCount(int delta,
Object key)
Increments the count of available messages. |
protected void |
incrementStoredMessagesCount(int delta,
Object key)
Increments the count of stored messages. |
String[] |
listFc()
|
Message |
remove(Object key)
Removes the message from the buffer that is associated with the specified key object. |
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,
Object key)
Adds the specified message to the buffer, associated with the specified key object. |
Message |
tryGet(Object key)
Gets the message from the buffer that is associated with the specified key object. |
Message |
tryRemove(Object key)
Removes the message from the buffer that is associated with the specified key object. |
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 |
---|
protected static final String[] CLIENT_INTERFACE_NAMES
protected MessageManager messageManagerItf
KeyedBufferRemove.removeAll()
.
protected int maxCapacity
protected int availableMessagesCount
incrementAvailableMessagesCount(int, Object)
method.
protected int storedMessagesCount
incrementStoredMessagesCount(int, Object)
method.
protected final Object lock
Constructor Detail |
---|
public AbstractBufferKeyedAddKeyedRemoveImpl()
Method Detail |
---|
public void add(Message message, Object key) throws InterruptedException
KeyedBufferAdd
Buffers may place limitations on what elements may be added to this buffer. In particular, some buffers require that messages contain particular chunks.
add
in interface KeyedBufferAdd
message
- the message to be added; never null
.key
- the key that is associated with the message to be added; never
null
.
InterruptedException
- if it is interrupted while waiting for a
message to be removed.KeyedBufferAdd.add(Message, Object)
public boolean tryAdd(Message message, Object key)
KeyedBufferAdd
Buffers may place limitations on what elements may be added to this buffer. In particular, some buffers require that messages contain particular chunks.
tryAdd
in interface KeyedBufferAdd
message
- the message to be added; never null
.key
- the key that is associated with the message to be added; never
null
.
true
if the message has been added.KeyedBufferAdd.tryAdd(Message, Object)
public Message remove(Object key) throws InterruptedException
KeyedBufferRemove
remove
in interface KeyedBufferRemove
key
- the key that is associated with the message to be removed.
null
.
InterruptedException
- if it is interrupted while waiting for a
message to be added.KeyedBufferRemove.remove(Object)
public Message tryRemove(Object key)
KeyedBufferRemove
tryRemove
in interface KeyedBufferRemove
key
- the key that is associated with the message to be removed.
null
otherwise.KeyedBufferRemove.tryRemove(Object)
public Message get(Object key) throws InterruptedException
KeyedBufferRemove
get
in interface KeyedBufferRemove
key
- the key that is associated with the message to get.
null
.
InterruptedException
- if it is interrupted while waiting for a
message to be added.KeyedBufferRemove.get(Object)
public Message tryGet(Object key)
KeyedBufferRemove
tryGet
in interface KeyedBufferRemove
key
- the key that is associated with the message to get.
null
otherwise.KeyedBufferRemove.tryGet(Object)
public Message removeAll()
KeyedBufferRemove
null
. This method does not block.
removeAll
in interface KeyedBufferRemove
null
if no message was available.KeyedBufferRemove.removeAll()
protected abstract void doAdd(Message message, Object key)
add(org.objectweb.dream.message.Message, java.lang.Object)
method. The lock
has been acquired when this
method is called.
message
- the message to be added.protected abstract Message doRemove(Object key)
remove(java.lang.Object)
method. The lock
has been acquired when this
method is called.
protected abstract Message doRemoveAll()
lock
has
been acquired when this method is called.
protected abstract Message doGet(Object key)
get(java.lang.Object)
method. The lock
has been acquired when this method is
called.
protected boolean canAdd(Message message, Object key)
lock
has been acquired when this method is called.
message
- the message to be tested.
true
if the message can be added.protected boolean hasAvailableMessage(Object key)
true
if there is an available message.protected int availableSpace(Object key)
protected void incrementAvailableMessagesCount(int delta, Object key)
lock
must have already been acquired.
delta
- the value that must be added to the previous count.protected void incrementStoredMessagesCount(int delta, Object key)
lock
must have already been acquired.
delta
- the value that must be added to previous indicator.public int getMaxCapacity()
BufferAttributeController
getMaxCapacity
in interface BufferAttributeController
BufferAttributeController.getMaxCapacity()
public void setMaxCapacity(int maxCapacity)
BufferAttributeController
setMaxCapacity
in interface BufferAttributeController
maxCapacity
- the maximum capacity of the queue.BufferAttributeController.setMaxCapacity(int)
public int getCurrentSize()
BufferAttributeController
getCurrentSize
in interface BufferAttributeController
BufferAttributeController.getCurrentSize()
public void bindFc(String clientItfName, Object serverItf) throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException
bindFc
in interface BindingController
bindFc
in class AbstractComponent
NoSuchInterfaceException
IllegalBindingException
IllegalLifeCycleException
BindingController.bindFc(String,
Object)
public String[] listFc()
listFc
in interface BindingController
BindingController.listFc()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |