org.mule.providers
Class AbstractMessageAdapter

java.lang.Object
  extended by org.mule.providers.AbstractMessageAdapter
All Implemented Interfaces:
Serializable, ThreadSafeAccess, UMOMessageAdapter
Direct Known Subclasses:
AxisMessageAdapter, DefaultMessageAdapter, FileMessageAdapter, FtpMessageAdapter, HttpMessageAdapter, HttpRequestMessageAdapter, JbiMessageAdapter, JdbcMessageAdapter, JmsMessageAdapter, OutStreamMessageAdapter, RmiMessageAdapter, SimpleMailMessageAdapter, StreamMessageAdapter, StreamMessageAdapter, TcpMessageAdapter, TestConnector.DummyMessageAdapter, UdpMessageAdapter, VMMessageAdapter, WriterMessageAdapter, XFireMessageAdapter, XmppMessageAdapter

public abstract class AbstractMessageAdapter
extends Object
implements UMOMessageAdapter, ThreadSafeAccess

AbstractMessageAdapter provides a base implementation for simple message types that maybe don't normally allow for meta information, such as a File or TCP.

See Also:
Serialized Form

Field Summary
protected  ConcurrentMap attachments
           
static boolean DEFAULT_FAILFAST
          Should we fail when we detect scribbling? This can be overridden by setting the property MuleProperties.MULE_THREAD_UNSAFE_MESSAGES_PROPERTY
protected  String encoding
           
protected  UMOExceptionPayload exceptionPayload
           
protected  String id
           
protected  Log logger
          logger used by this class
protected  ConcurrentMap properties
           
static boolean READ
           
static boolean WRITE
           
 
Constructor Summary
protected AbstractMessageAdapter()
           
protected AbstractMessageAdapter(UMOMessageAdapter template)
           
 
Method Summary
 void addAttachment(String name, DataHandler dataHandler)
           
 void addProperties(Map props)
          Adds a map of properties to be associated with this message
 void assertAccess(boolean write)
          Restrict mutation to private use within a single thread.
 void clearProperties()
          Removes all properties on this message
protected  byte[] convertToBytes(Object object)
           
 DataHandler getAttachment(String name)
           
 Set getAttachmentNames()
           
 boolean getBooleanProperty(String name, boolean defaultValue)
          Gets a boolean property from the event
 int getCorrelationGroupSize()
          Determines how many messages are in the correlation group
 String getCorrelationId()
          Sets a correlationId for this message.
 int getCorrelationSequence()
          Gets the sequence or ordering number for this message in the the correlation group (as defined by the correlationId)
 double getDoubleProperty(String name, double defaultValue)
          Gets a double property from the event
 String getEncoding()
          Gets the encoding for the current message.
 UMOExceptionPayload getExceptionPayload()
          If an error occurred during the processing of this message this will return a ErrorPayload that contains the root exception and Mule error code, plus any other releated info
 int getIntProperty(String name, int defaultValue)
          Gets an integer property from the event
 long getLongProperty(String name, long defaultValue)
          Gets a long property from the event
 String getPayloadAsString()
          Converts the message implementation into a String representation.
 Object getProperty(String key)
          Gets a property of the message implementation
 Object getProperty(String name, Object defaultValue)
          Gets a property from the event
 Set getPropertyNames()
           
 Object getReplyTo()
          Returns a replyTo address for this message.
 String getStringProperty(String name, String defaultValue)
          Gets a String property from the event
 String getUniqueId()
          gets the unique identifier for the message.
protected  boolean isDisabled()
           
protected  IllegalStateException newException(String message)
           
 ThreadSafeAccess newThreadCopy()
          By default we return "this".
 void removeAttachment(String name)
           
 Object removeProperty(String key)
          Removes an associated property from the message
 void resetAccessControl()
          This method should ONLY be used in the construction of composite ThreadSafeAccess instances.
 void setBooleanProperty(String name, boolean value)
          Sets a boolean property on the event
 void setCorrelationGroupSize(int size)
          Determines how many messages are in the correlation group
 void setCorrelationId(String correlationId)
          Sets a correlationId for this message.
 void setCorrelationSequence(int sequence)
          Gets the sequence or ordering number for this message in the the correlation group (as defined by the correlationId)
 void setDoubleProperty(String name, double value)
          Sets a double property on the event
 void setEncoding(String encoding)
          Sets the encoding for this message
 void setExceptionPayload(UMOExceptionPayload payload)
          If an error occurs while processing this message, a ErrorPayload is attached which contains the root exception and Mule error code, plus any other releated info
 void setIntProperty(String name, int value)
          Sets a integerproperty on the event
 void setLongProperty(String name, long value)
          Sets a long property on the event
 void setProperty(String key, Object value)
          Set a property on the message
 void setReplyTo(Object replyTo)
          Sets a replyTo address for this message.
 void setStringProperty(String name, String value)
          Sets a String property on the event
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mule.umo.provider.UMOMessageAdapter
getPayload, getPayloadAsBytes, getPayloadAsString
 

Field Detail

logger

protected transient Log logger
logger used by this class


properties

protected ConcurrentMap properties

attachments

protected ConcurrentMap attachments

encoding

protected String encoding

DEFAULT_FAILFAST

public static final boolean DEFAULT_FAILFAST
Should we fail when we detect scribbling? This can be overridden by setting the property MuleProperties.MULE_THREAD_UNSAFE_MESSAGES_PROPERTY

See Also:
Constant Field Values

exceptionPayload

protected UMOExceptionPayload exceptionPayload

id

protected String id

WRITE

public static final boolean WRITE
See Also:
Constant Field Values

READ

public static final boolean READ
See Also:
Constant Field Values
Constructor Detail

AbstractMessageAdapter

protected AbstractMessageAdapter()

AbstractMessageAdapter

protected AbstractMessageAdapter(UMOMessageAdapter template)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

addProperties

public void addProperties(Map props)
Description copied from interface: UMOMessageAdapter
Adds a map of properties to be associated with this message

Specified by:
addProperties in interface UMOMessageAdapter
Parameters:
props - the properties add to this message

clearProperties

public void clearProperties()
Description copied from interface: UMOMessageAdapter
Removes all properties on this message

Specified by:
clearProperties in interface UMOMessageAdapter

removeProperty

public Object removeProperty(String key)
Removes an associated property from the message

Specified by:
removeProperty in interface UMOMessageAdapter
Parameters:
key - the key of the property to remove
Returns:
the removed property value or null if the property did not exist

getProperty

public Object getProperty(String key)
Description copied from interface: UMOMessageAdapter
Gets a property of the message implementation

Specified by:
getProperty in interface UMOMessageAdapter
Parameters:
key - the key on which to lookup the property value
Returns:
the property value or null if the property does not exist

getPropertyNames

public Set getPropertyNames()
Specified by:
getPropertyNames in interface UMOMessageAdapter
Returns:
all property keys on this message

setProperty

public void setProperty(String key,
                        Object value)
Description copied from interface: UMOMessageAdapter
Set a property on the message

Specified by:
setProperty in interface UMOMessageAdapter
Parameters:
key - the key on which to associate the value
value - the property value

getUniqueId

public String getUniqueId()
Description copied from interface: UMOMessageAdapter
gets the unique identifier for the message. It's up to the implementation to ensure a unique id

Specified by:
getUniqueId in interface UMOMessageAdapter
Returns:
a unique message id. The Id should never be null. If the underlying transport does not have the notion of a message Id, one shuold be generated. The generated Id should be a UUID.

getProperty

public Object getProperty(String name,
                          Object defaultValue)
Description copied from interface: UMOMessageAdapter
Gets a property from the event

Specified by:
getProperty in interface UMOMessageAdapter
Parameters:
name - the name or key of the property
defaultValue - a default value if the property doesn't exist in the event
Returns:
the property value or the defaultValue if the property does not exist

getIntProperty

public int getIntProperty(String name,
                          int defaultValue)
Description copied from interface: UMOMessageAdapter
Gets an integer property from the event

Specified by:
getIntProperty in interface UMOMessageAdapter
Parameters:
name - the name or key of the property
defaultValue - a default value if the property doesn't exist in the event
Returns:
the property value or the defaultValue if the property does not exist

getLongProperty

public long getLongProperty(String name,
                            long defaultValue)
Description copied from interface: UMOMessageAdapter
Gets a long property from the event

Specified by:
getLongProperty in interface UMOMessageAdapter
Parameters:
name - the name or key of the property
defaultValue - a default value if the property doesn't exist in the event
Returns:
the property value or the defaultValue if the property does not exist

getDoubleProperty

public double getDoubleProperty(String name,
                                double defaultValue)
Description copied from interface: UMOMessageAdapter
Gets a double property from the event

Specified by:
getDoubleProperty in interface UMOMessageAdapter
Parameters:
name - the name or key of the property
defaultValue - a default value if the property doesn't exist in the event
Returns:
the property value or the defaultValue if the property does not exist

getBooleanProperty

public boolean getBooleanProperty(String name,
                                  boolean defaultValue)
Description copied from interface: UMOMessageAdapter
Gets a boolean property from the event

Specified by:
getBooleanProperty in interface UMOMessageAdapter
Parameters:
name - the name or key of the property
defaultValue - a default value if the property doesn't exist in the event
Returns:
the property value or the defaultValue if the property does not exist

getStringProperty

public String getStringProperty(String name,
                                String defaultValue)
Description copied from interface: UMOMessageAdapter
Gets a String property from the event

Specified by:
getStringProperty in interface UMOMessageAdapter
Parameters:
name - the name or key of the property
defaultValue - a default value if the property doesn't exist in the event
Returns:
the property value or the defaultValue if the property does not exist

setBooleanProperty

public void setBooleanProperty(String name,
                               boolean value)
Description copied from interface: UMOMessageAdapter
Sets a boolean property on the event

Specified by:
setBooleanProperty in interface UMOMessageAdapter
Parameters:
name - the property name or key
value - the property value

setIntProperty

public void setIntProperty(String name,
                           int value)
Description copied from interface: UMOMessageAdapter
Sets a integerproperty on the event

Specified by:
setIntProperty in interface UMOMessageAdapter
Parameters:
name - the property name or key
value - the property value

setLongProperty

public void setLongProperty(String name,
                            long value)
Description copied from interface: UMOMessageAdapter
Sets a long property on the event

Specified by:
setLongProperty in interface UMOMessageAdapter
Parameters:
name - the property name or key
value - the property value

setDoubleProperty

public void setDoubleProperty(String name,
                              double value)
Description copied from interface: UMOMessageAdapter
Sets a double property on the event

Specified by:
setDoubleProperty in interface UMOMessageAdapter
Parameters:
name - the property name or key
value - the property value

setStringProperty

public void setStringProperty(String name,
                              String value)
Description copied from interface: UMOMessageAdapter
Sets a String property on the event

Specified by:
setStringProperty in interface UMOMessageAdapter
Parameters:
name - the property name or key
value - the property value

getReplyTo

public Object getReplyTo()
Description copied from interface: UMOMessageAdapter
Returns a replyTo address for this message. This is useful in an asynchronous environment where the caller doesn't wait for a response and the response needs to be routed somewhere for further processing. The value of this field can be any valid endpointUri url.

Specified by:
getReplyTo in interface UMOMessageAdapter
Returns:
the endpointUri url to reply to or null if one has not been set

setReplyTo

public void setReplyTo(Object replyTo)
Description copied from interface: UMOMessageAdapter
Sets a replyTo address for this message. This is useful in an asynchronous environment where the caller doesn't wait for a response and the response needs to be routed somewhere for further processing. The value of this field can be any valid endpointUri url.

Specified by:
setReplyTo in interface UMOMessageAdapter
Parameters:
replyTo - the endpointUri url to reply to

getCorrelationId

public String getCorrelationId()
Description copied from interface: UMOMessageAdapter
Sets a correlationId for this message. The correlation Id can be used by components in the system to manage message relations.

The correlationId is associated with the message using the underlying transport protocol. As such not all messages will support the notion of a correlationId i.e. tcp or file. In this situation the correlation Id is set as a property of the message where it's up to developer to keep the association with the message. For example if the message is serialised to xml the correlationId will be available in the message.

Specified by:
getCorrelationId in interface UMOMessageAdapter
Returns:
the correlationId for this message or null if one hasn't been set

setCorrelationId

public void setCorrelationId(String correlationId)
Description copied from interface: UMOMessageAdapter
Sets a correlationId for this message. The correlation Id can be used by components in the system to manage message relations

transport protocol. As such not all messages will support the notion of a correlationId i.e. tcp or file. In this situation the correlation Id is set as a property of the message where it's up to developer to keep the association with the message. For example if the message is serialised to xml the correlationId will be available in the message.

Specified by:
setCorrelationId in interface UMOMessageAdapter
Parameters:
correlationId - the Id reference for this relationship

getCorrelationSequence

public int getCorrelationSequence()
Gets the sequence or ordering number for this message in the the correlation group (as defined by the correlationId)

Specified by:
getCorrelationSequence in interface UMOMessageAdapter
Returns:
the sequence number or -1 if the sequence is not important

setCorrelationSequence

public void setCorrelationSequence(int sequence)
Gets the sequence or ordering number for this message in the the correlation group (as defined by the correlationId)

Specified by:
setCorrelationSequence in interface UMOMessageAdapter
Parameters:
sequence - the sequence number or -1 if the sequence is not important

getCorrelationGroupSize

public int getCorrelationGroupSize()
Determines how many messages are in the correlation group

Specified by:
getCorrelationGroupSize in interface UMOMessageAdapter
Returns:
total messages in this group or -1 if the size is not known

setCorrelationGroupSize

public void setCorrelationGroupSize(int size)
Determines how many messages are in the correlation group

Specified by:
setCorrelationGroupSize in interface UMOMessageAdapter
Parameters:
size - the total messages in this group or -1 if the size is not known

getExceptionPayload

public UMOExceptionPayload getExceptionPayload()
Description copied from interface: UMOMessageAdapter
If an error occurred during the processing of this message this will return a ErrorPayload that contains the root exception and Mule error code, plus any other releated info

Specified by:
getExceptionPayload in interface UMOMessageAdapter
Returns:
The exception payload (if any) attached to this message

setExceptionPayload

public void setExceptionPayload(UMOExceptionPayload payload)
Description copied from interface: UMOMessageAdapter
If an error occurs while processing this message, a ErrorPayload is attached which contains the root exception and Mule error code, plus any other releated info

Specified by:
setExceptionPayload in interface UMOMessageAdapter
Parameters:
payload - The exception payloaad to attach to this message

addAttachment

public void addAttachment(String name,
                          DataHandler dataHandler)
                   throws Exception
Specified by:
addAttachment in interface UMOMessageAdapter
Throws:
Exception

removeAttachment

public void removeAttachment(String name)
                      throws Exception
Specified by:
removeAttachment in interface UMOMessageAdapter
Throws:
Exception

getAttachment

public DataHandler getAttachment(String name)
Specified by:
getAttachment in interface UMOMessageAdapter

getAttachmentNames

public Set getAttachmentNames()
Specified by:
getAttachmentNames in interface UMOMessageAdapter

getEncoding

public String getEncoding()
Description copied from interface: UMOMessageAdapter
Gets the encoding for the current message. For potocols that send encoding information with the message, this method should be overriden to expose the transport encoding, otherwise the default encoding in the Mule configuration will be used.

Specified by:
getEncoding in interface UMOMessageAdapter
Returns:
the encoding for this message. This method must never return null

setEncoding

public void setEncoding(String encoding)
Sets the encoding for this message

Specified by:
setEncoding in interface UMOMessageAdapter
Parameters:
encoding - the encoding to use

getPayloadAsString

public final String getPayloadAsString()
                                throws Exception
Converts the message implementation into a String representation. If encoding is required it will use the encoding set on the message

Specified by:
getPayloadAsString in interface UMOMessageAdapter
Returns:
String representation of the message payload
Throws:
Exception - Implementation may throw an endpoint specific exception

convertToBytes

protected byte[] convertToBytes(Object object)
                         throws TransformerException,
                                UnsupportedEncodingException
Throws:
TransformerException
UnsupportedEncodingException

assertAccess

public void assertAccess(boolean write)
Restrict mutation to private use within a single thread. Allow reading and writing by initial thread only. Once accessed by another thread, no writing allowed at all.

Specified by:
assertAccess in interface ThreadSafeAccess
Parameters:
write -

newException

protected IllegalStateException newException(String message)

isDisabled

protected boolean isDisabled()

resetAccessControl

public void resetAccessControl()
Description copied from interface: ThreadSafeAccess
This method should ONLY be used in the construction of composite ThreadSafeAccess instances. For example, a ThreadSafeAccess UMOEvent contains a ThreadSafeAccess UMOMessageAdapter. During the construction of the event, the message adapter may be bound to the contructing thread. Calling this method releases that binding so that the event as a whole can be passed to a new thread unbound.

Specified by:
resetAccessControl in interface ThreadSafeAccess

newThreadCopy

public ThreadSafeAccess newThreadCopy()
By default we return "this". This allows older code to inter-operate but doesn't, of course, give the required safety. Subclasses should override this method. Re-writing the threading handling should remove this requirement....

Specified by:
newThreadCopy in interface ThreadSafeAccess
Returns:
A new copy of this


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.