|
|||||||||
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.AbstractBufferImpl
public abstract class AbstractBufferImpl
Abstract implementation of a buffer. It implements the
BufferAttributeController
,BufferAdd
and BufferRemove
interfaces.
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)
returns a boolean indicating whether the
given message can be added into the buffer.doAdd(message)
adds the given message into the buffer.
hasAvailableMessage()
returns a boolean indicating
whether there is an available message.doRemove()
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 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 |
---|
protected static final String[] CLIENT_INTERFACE_NAMES
protected MessageManager messageManagerItf
BufferRemove.removeAll()
.
protected int maxCapacity
protected final Object lock
protected int availableMessagesCount
incrementAvailableMessagesCount(int)
method.
protected int storedMessagesCount
incrementStoredMessagesCount(int)
method.
Constructor Detail |
---|
public AbstractBufferImpl()
Method Detail |
---|
public void add(Message message) throws InterruptedException
BufferAdd
add
in interface BufferAdd
message
- the message to be added; never null
.
InterruptedException
- if it is interrupted while waiting for a
message to be removed.BufferAdd.add(Message)
public boolean tryAdd(Message message)
BufferAdd
tryAdd
in interface BufferAdd
message
- the message to be added; never null
.
true
if the message has been added.BufferAdd.tryAdd(Message)
public Message remove() throws InterruptedException
BufferRemove
remove
in interface BufferRemove
null
.
InterruptedException
- if it is interrupted while waiting for a
message to be added.BufferRemove.remove()
public Message tryRemove()
BufferRemove
tryRemove
in interface BufferRemove
null
otherwise.BufferRemove.tryRemove()
public Message get() throws InterruptedException
BufferRemove
get
in interface BufferRemove
null
.
InterruptedException
- if it is interrupted while waiting for a
message to be added.BufferRemove.get()
public Message tryGet()
BufferRemove
tryGet
in interface BufferRemove
null
otherwise.BufferRemove.tryGet()
public Message removeAll()
BufferRemove
null
. This method does not block.
removeAll
in interface BufferRemove
null
if no message was available.BufferRemove.removeAll()
protected abstract void doAdd(Message message)
add(org.objectweb.dream.message.Message)
method. The lock
has been acquired when this
method is called.
message
- the message to be added.protected abstract Message doRemove()
remove()
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()
get()
method. The lock
has been acquired when this method is
called.
protected boolean canAdd(Message message)
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()
true
if there is an available message.protected int availableSpace()
protected void incrementAvailableMessagesCount(int delta)
lock
must have already been acquired.
delta
- the value that must be added to the previous count.protected void incrementStoredMessagesCount(int delta)
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 |