org.objectweb.dream.queue
Class BufferMatchingImpl

java.lang.Object
  extended by org.objectweb.dream.AbstractComponent
      extended by org.objectweb.dream.queue.AbstractBufferImpl
          extended by org.objectweb.dream.queue.BufferMatchingImpl
All Implemented Interfaces:
ContextualBindingController, NeedAsyncStartController, PrepareStopLifeCycleController, Loggable, BufferAdd, BufferAttributeController, BufferRemove, AttributeController, BindingController, LifeCycleController

public class BufferMatchingImpl
extends AbstractBufferImpl

A buffer in which stored messages are available to get or remove only if they are accepted by the message matcher bound to this component.

If the availability criteria of the message matcher are modified while get() calls and/or remove() calls are blocked waiting for available messages, and the message matcher criteria modification would let them return messages, the blocked calls can be unblocked by calling AbstractBufferImpl.tryGet() after the message matcher has been modified.


Field Summary
protected static String[] CLIENT_INTERFACE_NAMES
          The names of client interfaces.
protected  int gettersCount
          The number of calls that are waiting to get (not remove) matching messages.
protected  MessageMatcher messageMatcherItf
          The message matcher that is used to select the messages that can be returned by calls to get(), AbstractBufferImpl.tryGet(), remove(), AbstractBufferImpl.tryRemove() and AbstractBufferImpl.removeAll().
protected  LinkedList<Message> messages
          The messages stored in this buffer, in adding order (FIFO).
protected  LinkedList<Message> messagesToBeReturned
          Messages that have matched messageMatcherItf and that are ready to be returned.
protected  int removersCount
          The number of calls that are waiting to remove matching messages.
 
Fields inherited from class org.objectweb.dream.queue.AbstractBufferImpl
availableMessagesCount, lock, maxCapacity, messageManagerItf, storedMessagesCount
 
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
BufferMatchingImpl()
           
 
Method Summary
 void bindFc(String clientItfName, Object serverItf)
           
protected  void doAdd(Message message)
          Adds a message to the buffer.
protected  Message doGet()
          Gets a message from the buffer.
protected  Message doRemove()
          Removes a message from the buffer.
protected  Message doRemoveAll()
          Removes all the messages stored into the buffer.
 Message get()
          Gets a message from the buffer.
protected  boolean hasAvailableMessage()
          Checks whether there is a message available to get or remove.
 String[] listFc()
           
 Message remove()
          Removes a message from the buffer.
protected  void searchMessagesToBeReturned()
          If there are waiting removers (i.e., if removersCount > 0 or if gettersCount > 0), iterate over the received messages, and test each message by calling MessageMatcher.acceptMessage(Message) using the bound matcher, until at most enough matching messages for waiting removers and getters have been found.
 
Methods inherited from class org.objectweb.dream.queue.AbstractBufferImpl
add, availableSpace, canAdd, getCurrentSize, getMaxCapacity, incrementAvailableMessagesCount, incrementStoredMessagesCount, removeAll, setMaxCapacity, tryAdd, tryGet, tryRemove
 
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.


messageMatcherItf

protected MessageMatcher messageMatcherItf
The message matcher that is used to select the messages that can be returned by calls to get(), AbstractBufferImpl.tryGet(), remove(), AbstractBufferImpl.tryRemove() and AbstractBufferImpl.removeAll(). This is the client interface named "message-matcher".


messages

protected LinkedList<Message> messages
The messages stored in this buffer, in adding order (FIFO).


messagesToBeReturned

protected LinkedList<Message> messagesToBeReturned
Messages that have matched messageMatcherItf and that are ready to be returned. The messages are in adding order (FIFO).


removersCount

protected int removersCount
The number of calls that are waiting to remove matching messages.


gettersCount

protected int gettersCount
The number of calls that are waiting to get (not remove) matching messages.

Constructor Detail

BufferMatchingImpl

public BufferMatchingImpl()
Method Detail

doAdd

protected void doAdd(Message message)
Description copied from class: AbstractBufferImpl
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 AbstractBufferImpl.add(org.objectweb.dream.message.Message)method. The lockhas been acquired when this method is called.

Specified by:
doAdd in class AbstractBufferImpl
Parameters:
message - the message to be added.

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
Overrides:
remove in class AbstractBufferImpl
Returns:
the removed message; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemove.remove()

doRemove

protected Message doRemove()
Description copied from class: AbstractBufferImpl
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 AbstractBufferImpl.remove()method. The lockhas been acquired when this method is called.

Specified by:
doRemove in class AbstractBufferImpl
Returns:
a message.

doRemoveAll

protected Message doRemoveAll()
Description copied from class: AbstractBufferImpl
Removes all the messages stored into the buffer. The lockhas been acquired when this method is called.

Specified by:
doRemoveAll in class AbstractBufferImpl
Returns:
an aggregated message.

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
Overrides:
get in class AbstractBufferImpl
Returns:
a message; never null.
Throws:
InterruptedException - if it is interrupted while waiting for a message to be added.
See Also:
BufferRemove.get()

doGet

protected Message doGet()
Description copied from class: AbstractBufferImpl
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 AbstractBufferImpl.get() method. The lockhas been acquired when this method is called.

Specified by:
doGet in class AbstractBufferImpl
Returns:
a message.

hasAvailableMessage

protected boolean hasAvailableMessage()
Description copied from class: AbstractBufferImpl
Checks whether there is a message available to get or remove.

Overrides:
hasAvailableMessage in class AbstractBufferImpl
Returns:
true if there is an available message.

searchMessagesToBeReturned

protected void searchMessagesToBeReturned()
If there are waiting removers (i.e., if removersCount > 0 or if gettersCount > 0), iterate over the received messages, and test each message by calling MessageMatcher.acceptMessage(Message) using the bound matcher, until at most enough matching messages for waiting removers and getters have been found. The matching messages are put in the same order into messagesToBeReturned, then removers are notified. The lock has been acquired when this method is called.


listFc

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

bindFc

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


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