org.mule.providers
Class AbstractMessageDispatcher

java.lang.Object
  extended by org.mule.providers.AbstractMessageDispatcher
All Implemented Interfaces:
ExceptionListener, Disposable, UMOConnectable, UMOMessageDispatcher, UMOMessageDispatching
Direct Known Subclasses:
AxisMessageDispatcher, FileMessageDispatcher, FtpMessageDispatcher, HttpClientMessageDispatcher, JbiMessageDispatcher, JdbcMessageDispatcher, JmsMessageDispatcher, ProcessMessageDispatcher, QuartzMessageDispatcher, RetrieveMessageDispatcher, RmiMessageDispatcher, SmtpMessageDispatcher, StreamMessageDispatcher, TcpMessageDispatcher, TestMessageDispatcher, UdpMessageDispatcher, VMMessageDispatcher, XFireMessageDispatcher, XmppMessageDispatcher

public abstract class AbstractMessageDispatcher
extends Object
implements UMOMessageDispatcher, ExceptionListener

AbstractMessageDispatcher provides a default dispatch (client) support for handling threads lifecycle and validation.


Field Summary
protected  boolean connected
           
protected  boolean connecting
           
protected  ConnectionStrategy connectionStrategy
           
protected  AbstractConnector connector
           
protected  boolean disposed
           
protected  UMOImmutableEndpoint endpoint
           
protected  Log logger
          logger used by this class
protected  UMOWorkManager workManager
          Thread pool of Connector sessions
 
Fields inherited from interface org.mule.umo.provider.UMOMessageDispatching
RECEIVE_NO_WAIT, RECEIVE_WAIT_INDEFINITELY
 
Constructor Summary
AbstractMessageDispatcher(UMOImmutableEndpoint endpoint)
           
 
Method Summary
 void activate()
          This method can perform necessary state updates before any of the UMOMessageDispatching methods are invoked.
 void connect()
          Make the connection to the underlying transport.
 void disconnect()
          Disconnect the from the underlying transport
 void dispatch(UMOEvent event)
          Dispatches an event from the endpoint to the external system
 void dispose()
          Template method to destroy any resources held by the Message Dispatcher
protected abstract  void doConnect()
           
protected abstract  void doDisconnect()
           
protected abstract  void doDispatch(UMOEvent event)
           
protected abstract  void doDispose()
           
protected abstract  UMOMessage doReceive(long timeout)
          Make a specific request to the underlying transport
protected abstract  UMOMessage doSend(UMOEvent event)
           
 void exceptionThrown(Exception e)
           
protected  String getConnectEventId(UMOImmutableEndpoint endpoint)
           
 String getConnectionDescription()
          Returns a string identifying the underlying resource
 UMOConnector getConnector()
          Gets the connector for this dispatcher
 UMOImmutableEndpoint getEndpoint()
           
 boolean isConnected()
          Determines if this object is connected or not
protected  boolean isDoThreading()
           
protected  boolean isTransactionRollback()
          Checks to see if the current transaction has been rolled back
 void passivate()
          After sending/receiving a message, the dispatcher can use this method e.g.
 UMOMessage receive(long timeout)
          Make a specific request to the underlying transport
 void reconnect()
           
 UMOMessage send(UMOEvent event)
          Sends an event from the endpoint to the external system
 String toString()
           
protected  boolean useRemoteSync(UMOEvent event)
          RemoteSync causes the message dispatch to wait for a response to an event on a response channel after it sends the event.
 boolean validate()
          Determines whether this dispatcher can be reused after message sending/receiving.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected transient Log logger
logger used by this class


workManager

protected UMOWorkManager workManager
Thread pool of Connector sessions


endpoint

protected final UMOImmutableEndpoint endpoint

connector

protected final AbstractConnector connector

disposed

protected boolean disposed

connectionStrategy

protected ConnectionStrategy connectionStrategy

connecting

protected volatile boolean connecting

connected

protected volatile boolean connected
Constructor Detail

AbstractMessageDispatcher

public AbstractMessageDispatcher(UMOImmutableEndpoint endpoint)
Method Detail

dispatch

public final void dispatch(UMOEvent event)
                    throws DispatchException
Description copied from interface: UMOMessageDispatching
Dispatches an event from the endpoint to the external system

Specified by:
dispatch in interface UMOMessageDispatching
Parameters:
event - The event to dispatch
Throws:
DispatchException - if the event fails to be dispatched

send

public final UMOMessage send(UMOEvent event)
                      throws DispatchException
Description copied from interface: UMOMessageDispatching
Sends an event from the endpoint to the external system

Specified by:
send in interface UMOMessageDispatching
Parameters:
event - The event to send
Returns:
event the response form the external system wrapped in a UMOEvent
Throws:
DispatchException - if the event fails to be dispatched

receive

public final UMOMessage receive(long timeout)
                         throws Exception
Make a specific request to the underlying transport

Specified by:
receive in interface UMOMessageDispatching
Parameters:
timeout - the maximum time the operation should block before returning. The call should return immediately if there is data available. If no data becomes available before the timeout elapses, null will be returned
Returns:
the result of the request wrapped in a UMOMessage object. Null will be returned if no data was avaialable
Throws:
Exception - if the call to the underlying protocal cuases an exception

exceptionThrown

public void exceptionThrown(Exception e)
Specified by:
exceptionThrown in interface ExceptionListener

validate

public boolean validate()
Description copied from interface: UMOMessageDispatcher
Determines whether this dispatcher can be reused after message sending/receiving.

Specified by:
validate in interface UMOMessageDispatcher
Returns:
true if this dispatcher can be reused, false otherwise (for example when Disposable.dispose() has been called because an Exception was raised)

activate

public void activate()
Description copied from interface: UMOMessageDispatcher
This method can perform necessary state updates before any of the UMOMessageDispatching methods are invoked.

Specified by:
activate in interface UMOMessageDispatcher
See Also:
UMOMessageDispatcherFactory#activate(org.mule.umo.endpoint.UMOImmutableEndpoint, UMOMessageDispatcher)}

passivate

public void passivate()
Description copied from interface: UMOMessageDispatcher
After sending/receiving a message, the dispatcher can use this method e.g. to clean up its internal state (if it has any) or return pooled resources to whereever it got them during UMOMessageDispatcher.activate().

Specified by:
passivate in interface UMOMessageDispatcher
See Also:
UMOMessageDispatcherFactory#passivate(org.mule.umo.endpoint.UMOImmutableEndpoint, UMOMessageDispatcher)}

dispose

public final void dispose()
Template method to destroy any resources held by the Message Dispatcher

Specified by:
dispose in interface Disposable

getConnector

public UMOConnector getConnector()
Description copied from interface: UMOMessageDispatcher
Gets the connector for this dispatcher

Specified by:
getConnector in interface UMOMessageDispatcher
Returns:
the connector for this dispatcher

getEndpoint

public UMOImmutableEndpoint getEndpoint()

useRemoteSync

protected boolean useRemoteSync(UMOEvent event)
RemoteSync causes the message dispatch to wait for a response to an event on a response channel after it sends the event. The following rules apply to RemoteSync 1. The connector has to support remoteSync. Some transports do not have the notion of a response channel 2. Check if the endpoint has been configured for remoteSync 3. Check if the REMOTE_SYNC message header has been set 4. Finally, if the current component has a response router configured, that the router will handle the response channel event and we should not try and receive a response in the Message dispatcher If remotesync should not be used we must remove the REMOTE_SYNC header Note the MuleClient will automatically set the REMOTE_SYNC header when client.send(..) is called so that results are returned from remote invocations too.

Parameters:
event - the current event
Returns:
true if a response channel should be used to get a resposne from the event dispatch.

connect

public void connect()
             throws Exception
Description copied from interface: UMOConnectable
Make the connection to the underlying transport. The fact that this object is connected or not should have no influence on the lifecycle, especially the start / stop state if applicable.

Specified by:
connect in interface UMOConnectable
Throws:
Exception

disconnect

public void disconnect()
                throws Exception
Description copied from interface: UMOConnectable
Disconnect the from the underlying transport

Specified by:
disconnect in interface UMOConnectable
Throws:
Exception

getConnectEventId

protected String getConnectEventId(UMOImmutableEndpoint endpoint)

isConnected

public final boolean isConnected()
Description copied from interface: UMOConnectable
Determines if this object is connected or not

Specified by:
isConnected in interface UMOConnectable
Returns:

isDoThreading

protected boolean isDoThreading()

getConnectionDescription

public String getConnectionDescription()
Returns a string identifying the underlying resource

Specified by:
getConnectionDescription in interface UMOConnectable
Returns:

reconnect

public void reconnect()
               throws Exception
Throws:
Exception

doDispose

protected abstract void doDispose()

doDispatch

protected abstract void doDispatch(UMOEvent event)
                            throws Exception
Throws:
Exception

doSend

protected abstract UMOMessage doSend(UMOEvent event)
                              throws Exception
Throws:
Exception

doConnect

protected abstract void doConnect()
                           throws Exception
Throws:
Exception

doDisconnect

protected abstract void doDisconnect()
                              throws Exception
Throws:
Exception

doReceive

protected abstract UMOMessage doReceive(long timeout)
                                 throws Exception
Make a specific request to the underlying transport

Parameters:
timeout - the maximum time the operation should block before returning. The call should return immediately if there is data available. If no data becomes available before the timeout elapses, null will be returned
Returns:
the result of the request wrapped in a UMOMessage object. Null will be returned if no data was avaialable
Throws:
Exception - if the call to the underlying protocal cuases an exception

isTransactionRollback

protected boolean isTransactionRollback()
Checks to see if the current transaction has been rolled back

Returns:

toString

public String toString()
Overrides:
toString in class Object


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