org.mule.transport
Class AbstractTransportMessageHandler<O>

java.lang.Object
  extended by org.mule.transport.AbstractTransportMessageHandler<O>
All Implemented Interfaces:
Disposable, Initialisable, Lifecycle, LifecycleStateEnabled, Startable, Stoppable, Connectable
Direct Known Subclasses:
AbstractMessageDispatcher, AbstractMessageReceiver, AbstractMessageRequester

public abstract class AbstractTransportMessageHandler<O>
extends Object
implements Connectable, LifecycleStateEnabled

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


Field Summary
protected  AtomicBoolean connected
           
protected  AbstractConnector connector
           
protected  ImmutableEndpoint endpoint
           
protected  ConnectableLifecycleManager<O> lifecycleManager
           
protected  Log logger
           
protected  MuleMessageFactory muleMessageFactory
           
protected  RetryPolicyTemplate retryTemplate
           
 
Fields inherited from interface org.mule.api.lifecycle.Initialisable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Startable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Stoppable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Disposable
PHASE_NAME
 
Constructor Summary
AbstractTransportMessageHandler(ImmutableEndpoint endpoint)
           
 
Method Summary
 void activate()
           
 void connect()
          Make the connection to the underlying transport.
protected  void connectHandler()
           
protected abstract  ConnectableLifecycleManager<O> createLifecycleManager()
           
 MuleMessage createMuleMessage(Object transportMessage)
          Uses this object's MuleMessageFactory to create a new MuleMessage instance.
 MuleMessage createMuleMessage(Object transportMessage, MuleMessage previousMessage, String encoding)
          Uses this object's MuleMessageFactory to create a new MuleMessage instance.
 MuleMessage createMuleMessage(Object transportMessage, String encoding)
          Uses this object's MuleMessageFactory to create a new MuleMessage instance.
protected  MuleMessageFactory createMuleMessageFactory()
          This method uses the connector's createMuleMessageFactory method to create a new MuleMessageFactory.
protected  MuleMessage createNullMuleMessage()
          Uses this object's MuleMessageFactory to create a new MuleMessage instance.
 void disconnect()
          Disconnect the from the underlying transport
 void dispose()
          Template method to destroy any resources held by the Message Dispatcher
protected  void disposeAndLogException()
           
protected  void doConnect()
           
protected  void doDisconnect()
           
protected  void doDispose()
           
protected  void doInitialise()
           
protected  void doStart()
           
protected  void doStartHandler()
           
protected  void doStop()
           
protected  String getConnectEventId(ImmutableEndpoint endpoint)
           
 String getConnectionDescription()
          Returns a string identifying the underlying resource
 Connector getConnector()
           
 ImmutableEndpoint getEndpoint()
           
 LifecycleState getLifecycleState()
           
protected abstract  WorkManager getWorkManager()
           
 void initialise()
          Method used to perform any initialisation work.
protected  void initializeMessageFactory()
          Subclasses can override this method to create a custom MuleMessageFactory instead of re-using the instance from the connector.
protected  void initializeRetryPolicy()
           
 boolean isConnected()
          Determines if this object is connected or not
protected  boolean isDoThreading()
           
 boolean isStarted()
           
 boolean isStarting()
           
 boolean isStopped()
           
 boolean isStopping()
           
 void passivate()
           
 void setEndpoint(ImmutableEndpoint endpoint)
           
 void start()
          This method will start the connectable, calling connect() if it is needed.
 void stop()
           
 String toString()
           
 boolean validate()
           
 RetryContext validateConnection(RetryContext retryContext)
          Test whether the connector is able to connect to its resource(s).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected transient Log logger

endpoint

protected ImmutableEndpoint endpoint

connector

protected final AbstractConnector connector

retryTemplate

protected RetryPolicyTemplate retryTemplate

muleMessageFactory

protected MuleMessageFactory muleMessageFactory

lifecycleManager

protected ConnectableLifecycleManager<O> lifecycleManager

connected

protected final AtomicBoolean connected
Constructor Detail

AbstractTransportMessageHandler

public AbstractTransportMessageHandler(ImmutableEndpoint endpoint)
Method Detail

createLifecycleManager

protected abstract ConnectableLifecycleManager<O> createLifecycleManager()

getLifecycleState

public LifecycleState getLifecycleState()
Specified by:
getLifecycleState in interface LifecycleStateEnabled

disposeAndLogException

protected void disposeAndLogException()

validate

public boolean validate()

activate

public void activate()

passivate

public void passivate()

initialise

public void initialise()
                throws InitialisationException
Description copied from interface: Initialisable
Method used to perform any initialisation work. If a fatal error occurs during initialisation an InitialisationException should be thrown, causing the Mule instance to shutdown. If the error is recoverable, say by retrying to connect, a RecoverableException should be thrown. There is no guarantee that by throwing a Recoverable exception that the Mule instance will not shut down.

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException - if a fatal error occurs causing the Mule instance to shutdown
RecoverableException - if an error occurs that can be recovered from

initializeRetryPolicy

protected void initializeRetryPolicy()

initializeMessageFactory

protected void initializeMessageFactory()
                                 throws InitialisationException
Subclasses can override this method to create a custom MuleMessageFactory instead of re-using the instance from the connector.

Throws:
InitialisationException

dispose

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

Specified by:
dispose in interface Disposable

getConnector

public Connector getConnector()

getEndpoint

public ImmutableEndpoint getEndpoint()

connect

public final void connect()
                   throws Exception
Description copied from interface: Connectable
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 Connectable
Throws:
Exception

connectHandler

protected void connectHandler()
                       throws Exception
Throws:
Exception

validateConnection

public RetryContext validateConnection(RetryContext retryContext)
Description copied from interface: Connectable
Test whether the connector is able to connect to its resource(s). This will allow a retry policy to go into effect in the case of failure. Implementations must call either: Callers should then check for RetryContext.isOk(). The failure, if any, will be provided via the RetryContext.getLastFailure().

Specified by:
validateConnection in interface Connectable
Returns:
same retry context with status info set and any failures populated

disconnect

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

Specified by:
disconnect in interface Connectable
Throws:
Exception

getConnectEventId

protected String getConnectEventId(ImmutableEndpoint endpoint)

isConnected

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

Specified by:
isConnected in interface Connectable

isDoThreading

protected boolean isDoThreading()

getConnectionDescription

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

Specified by:
getConnectionDescription in interface Connectable

start

public final void start()
                 throws MuleException
This method will start the connectable, calling connect() if it is needed.

This method is synchronous or not depending on how the retryTemplate behaves.

This method ensures that doStart() will be called at most one time and will return without error if the component is already started.

Specified by:
start in interface Startable
Throws:
MuleException

doStartHandler

protected void doStartHandler()
                       throws MuleException
Throws:
MuleException

stop

public final void stop()
                throws MuleException
Specified by:
stop in interface Stoppable
Throws:
MuleException

doInitialise

protected void doInitialise()
                     throws InitialisationException
Throws:
InitialisationException

doDispose

protected void doDispose()

doConnect

protected void doConnect()
                  throws Exception
Throws:
Exception

doDisconnect

protected void doDisconnect()
                     throws Exception
Throws:
Exception

doStart

protected void doStart()
                throws MuleException
Throws:
MuleException

doStop

protected void doStop()
               throws MuleException
Throws:
MuleException

toString

public String toString()
Overrides:
toString in class Object

setEndpoint

public void setEndpoint(ImmutableEndpoint endpoint)

getWorkManager

protected abstract WorkManager getWorkManager()
                                       throws MuleException
Throws:
MuleException

isStarted

public boolean isStarted()

isStarting

public boolean isStarting()

isStopped

public boolean isStopped()

isStopping

public boolean isStopping()

createMuleMessageFactory

protected MuleMessageFactory createMuleMessageFactory()
                                               throws CreateException
This method uses the connector's createMuleMessageFactory method to create a new MuleMessageFactory. Subclasses may need to override this method in order to perform additional initialization on the message factory before it's actually used.

Throws:
CreateException

createMuleMessage

public MuleMessage createMuleMessage(Object transportMessage,
                                     MuleMessage previousMessage,
                                     String encoding)
                              throws MuleException
Uses this object's MuleMessageFactory to create a new MuleMessage instance. The payload of the new message will be taken from transportMessage, all message properties will be copied from previousMessage.

Throws:
MuleException

createMuleMessage

public MuleMessage createMuleMessage(Object transportMessage,
                                     String encoding)
                              throws MuleException
Uses this object's MuleMessageFactory to create a new MuleMessage instance. This is the designated way to build MuleMessages from the transport specific message.

Throws:
MuleException

createMuleMessage

public MuleMessage createMuleMessage(Object transportMessage)
                              throws MuleException
Uses this object's MuleMessageFactory to create a new MuleMessage instance. Uses the default encoding.

Throws:
MuleException
See Also:
MuleConfiguration.getDefaultEncoding()

createNullMuleMessage

protected MuleMessage createNullMuleMessage()
                                     throws MuleException
Uses this object's MuleMessageFactory to create a new MuleMessage instance. Rather than passing in a transport message instance, NullPayload is used instead. Uses the default encoding.

Throws:
MuleException


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.