org.objectweb.dream.message
Class MessageManagerImpl

java.lang.Object
  extended by org.objectweb.dream.AbstractComponent
      extended by org.objectweb.dream.message.MessageManagerImpl
All Implemented Interfaces:
ContextualBindingController, NeedAsyncStartController, PrepareStopLifeCycleController, Loggable, MessageManager, MessageManagerAttributeController, AttributeController, BindingController, LifeCycleController
Direct Known Subclasses:
MessageManagerPoolingImpl

public class MessageManagerImpl
extends AbstractComponent
implements MessageManager, MessageManagerAttributeController

Basic message manager implementation.


Field Summary
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, fcNeedAsyncStart, fcState, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.dream.message.MessageManager
ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Constructor Summary
MessageManagerImpl()
           
 
Method Summary
 void addChunk(Message message, String chunkName, AbstractChunk chunk)
          Adds a chunk in the given message.
 AbstractChunk addOrReplaceChunk(Message message, String chunkName, AbstractChunk chunk)
          Adds a chunk in the given message.
 void addSubMessage(Message message, Message subMessage)
          Adds a sub message to a message.
protected  void checkNull(AbstractChunk chunk)
           
protected  void checkNull(Message message)
           
protected  void checkNull(String chunkName)
           
protected  void checkOwner(AbstractChunk<?> chunk)
           
protected  void checkOwner(Message message)
           
protected  void checkSubMessage(Message message, Message subMessage)
           
<T extends AbstractChunk<T>>
T
cloneChunk(T chunk)
          Clones the given chunk.
<T extends AbstractChunk<T>>
T
createChunk(ChunkFactoryReference<T> chunkFactory)
          Creates a chunk using the chunk factory referenced by the given reference.
protected
<T extends AbstractChunk<T>>
ChunkFactoryReference<T>
createChunkFactory(Class<T> chunkType)
           
 Message createMessage()
          Creates a new message and returns a reference to the newly created message.
 void deleteChunk(AbstractChunk<?> chunk)
          Deletes the given chunk.
 void deleteMessage(Message message)
          Delete the message referenced by the given reference.
 Message duplicateMessage(Message message, boolean clone)
          Duplicates a message.
 AbstractChunk getChunk(Message message, String chunkName)
          Returns the chunk in the given message with the given name.
<T extends AbstractChunk<T>>
ChunkFactoryReference<T>
getChunkFactory(Class<T> chunkType)
          Returns a reference to a chunk factory for the given chunk type.
 Iterator<String> getChunkNameIterator(Message message)
          Returns an iterator over the chunk names of the given message.
 boolean getDoCheck()
          Returns the doCheck attribute value.
 Iterator<Message> getSubMessageIterator(Message message)
          Returns an iterator over sub messages of the given message.
 boolean isEmpty(Message message)
          Returns true if the message is empty (ie. contains no chunk and no sub message).
 String[] listFc()
           
protected  void recycleMessageInstance(Message message)
           
 AbstractChunk removeChunk(Message message, String chunkName)
          Removes a chunk from the given message.
 void removeSubMessage(Message message, Message subMessage)
          Removes a sub message from a message.
 void setDoCheck(boolean doCheck)
          Sets the doCheck attribute value.
 
Methods inherited from class org.objectweb.dream.AbstractComponent
beforeFirstStart, bindFc, 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
 

Constructor Detail

MessageManagerImpl

public MessageManagerImpl()
Method Detail

createMessage

public Message createMessage()
Description copied from interface: MessageManager
Creates a new message and returns a reference to the newly created message.

Specified by:
createMessage in interface MessageManager
Returns:
a reference to a newly created message.
See Also:
MessageManager.createMessage()

deleteMessage

public void deleteMessage(Message message)
Description copied from interface: MessageManager
Delete the message referenced by the given reference. If the message has been duplicated by reference (see MessageManager.duplicateMessage(org.objectweb.dream.message.Message, boolean)), this operation releases the given reference. The message is effectively deleted only if all its references have been released. In this case, chunks in the message are removed and recycled, so as message instance.

Specified by:
deleteMessage in interface MessageManager
Parameters:
message - the reference of the message to delete.
See Also:
MessageManager.deleteMessage(Message)

duplicateMessage

public Message duplicateMessage(Message message,
                                boolean clone)
Description copied from interface: MessageManager
Duplicates a message. There are two kinds of duplication:

Specified by:
duplicateMessage in interface MessageManager
Parameters:
message - the reference of the message to be duplicated.
clone - the duplication mode. false for reference duplication, true for value duplication.
Returns:
the reference of the duplicated message.
See Also:
MessageManager.duplicateMessage(Message, boolean)

getChunkFactory

public <T extends AbstractChunk<T>> ChunkFactoryReference<T> getChunkFactory(Class<T> chunkType)
Description copied from interface: MessageManager
Returns a reference to a chunk factory for the given chunk type.

Specified by:
getChunkFactory in interface MessageManager
Type Parameters:
T - the chunk type.
Parameters:
chunkType - the class object of the required chunk type.
Returns:
a reference to a chunk factory for the given chunk type.
See Also:
MessageManager.getChunkFactory(Class)

createChunk

public <T extends AbstractChunk<T>> T createChunk(ChunkFactoryReference<T> chunkFactory)
Description copied from interface: MessageManager
Creates a chunk using the chunk factory referenced by the given reference.

Specified by:
createChunk in interface MessageManager
Type Parameters:
T - the chunk type.
Parameters:
chunkFactory - a chunk factory reference.
Returns:
a chunk instance of the given type.
See Also:
MessageManager.createChunk(ChunkFactoryReference)

cloneChunk

public <T extends AbstractChunk<T>> T cloneChunk(T chunk)
Description copied from interface: MessageManager
Clones the given chunk.

Specified by:
cloneChunk in interface MessageManager
Type Parameters:
T - the type of the chunk to clone.
Parameters:
chunk - the chunk to clone.
Returns:
the cloned chunk.
See Also:
MessageManager.cloneChunk(AbstractChunk)

deleteChunk

public void deleteChunk(AbstractChunk<?> chunk)
Description copied from interface: MessageManager
Deletes the given chunk.

Specified by:
deleteChunk in interface MessageManager
Parameters:
chunk - the chunk to delete.
See Also:
MessageManager.deleteChunk(AbstractChunk)

isEmpty

public boolean isEmpty(Message message)
Description copied from interface: MessageManager
Returns true if the message is empty (ie. contains no chunk and no sub message).

Specified by:
isEmpty in interface MessageManager
Parameters:
message - the reference of a message
Returns:
true if the message is empty.
See Also:
MessageManager.isEmpty(Message)

getChunk

public AbstractChunk getChunk(Message message,
                              String chunkName)
Description copied from interface: MessageManager
Returns the chunk in the given message with the given name.

Specified by:
getChunk in interface MessageManager
Parameters:
message - the reference of the message
chunkName - the name of the chunk.
Returns:
a chunk of the type specified by the chunk name, or null if no chunk can be found.
See Also:
MessageManager.getChunk(Message, String)

addChunk

public void addChunk(Message message,
                     String chunkName,
                     AbstractChunk chunk)
Description copied from interface: MessageManager
Adds a chunk in the given message. If chunk with the given name already exist in the message, a ChunkAlreadyExistException is thrown.

Specified by:
addChunk in interface MessageManager
Parameters:
message - the reference of the message in which the chunk will be added.
chunkName - the name of the chunk.
chunk - the chunk to add
See Also:
MessageManager.addChunk(Message, String, AbstractChunk)

addOrReplaceChunk

public AbstractChunk addOrReplaceChunk(Message message,
                                       String chunkName,
                                       AbstractChunk chunk)
Description copied from interface: MessageManager
Adds a chunk in the given message. If a chunk with the given name already exist in the message, it is replaced and returned.

Specified by:
addOrReplaceChunk in interface MessageManager
Parameters:
message - the reference of the message in which the message will be added.
chunkName - the name of the chunk.
chunk - the chunk to add
Returns:
the previous chunk with the given name, or null.
See Also:
MessageManager.addOrReplaceChunk(Message, String, AbstractChunk)

removeChunk

public AbstractChunk removeChunk(Message message,
                                 String chunkName)
Description copied from interface: MessageManager
Removes a chunk from the given message. If no chunk with the given name can be found in the message, a UnknownChunkException is thrown.

Specified by:
removeChunk in interface MessageManager
Parameters:
message - the reference of the message from which the chunk will be removed.
chunkName - the name of the chunk.
Returns:
the removed chunk.
See Also:
MessageManager.removeChunk(Message, String)

getChunkNameIterator

public Iterator<String> getChunkNameIterator(Message message)
Description copied from interface: MessageManager
Returns an iterator over the chunk names of the given message.

Specified by:
getChunkNameIterator in interface MessageManager
Parameters:
message - a message reference.
Returns:
an iterator over the chunk names of the given message.
See Also:
MessageManager.getChunkNameIterator(Message)

addSubMessage

public void addSubMessage(Message message,
                          Message subMessage)
Description copied from interface: MessageManager
Adds a sub message to a message.

Specified by:
addSubMessage in interface MessageManager
Parameters:
message - the message where the sub message will be added.
subMessage - the sub message.
See Also:
MessageManager.addSubMessage(Message, Message)

getSubMessageIterator

public Iterator<Message> getSubMessageIterator(Message message)
Description copied from interface: MessageManager
Returns an iterator over sub messages of the given message.

Specified by:
getSubMessageIterator in interface MessageManager
Parameters:
message - a message reference.
Returns:
an iterator over the sub messages of the given message.
See Also:
MessageManager.getSubMessageIterator(Message)

removeSubMessage

public void removeSubMessage(Message message,
                             Message subMessage)
Description copied from interface: MessageManager
Removes a sub message from a message.

Specified by:
removeSubMessage in interface MessageManager
Parameters:
message - the message from which the sub message will be removed.
subMessage - the sub message.
See Also:
MessageManager.removeSubMessage(Message, Message)

checkOwner

protected final void checkOwner(Message message)

checkOwner

protected final void checkOwner(AbstractChunk<?> chunk)

checkNull

protected final void checkNull(String chunkName)

checkNull

protected final void checkNull(AbstractChunk chunk)

checkNull

protected final void checkNull(Message message)

checkSubMessage

protected final void checkSubMessage(Message message,
                                     Message subMessage)

createChunkFactory

protected <T extends AbstractChunk<T>> ChunkFactoryReference<T> createChunkFactory(Class<T> chunkType)

recycleMessageInstance

protected void recycleMessageInstance(Message message)

setDoCheck

public void setDoCheck(boolean doCheck)
Description copied from interface: MessageManagerAttributeController
Sets the doCheck attribute value. If true, additional (expensive) checks will be performed by the message manager. This can be useful to detect bugs in a dream architecture. Default value is false.

Specified by:
setDoCheck in interface MessageManagerAttributeController
Parameters:
doCheck - the new doCheck attribute value.
See Also:
MessageManagerAttributeController.setDoCheck(boolean)

getDoCheck

public boolean getDoCheck()
Description copied from interface: MessageManagerAttributeController
Returns the doCheck attribute value.

Specified by:
getDoCheck in interface MessageManagerAttributeController
Returns:
the doCheck attribute value.
See Also:
MessageManagerAttributeController.getDoCheck()

listFc

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


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