org.mule.service
Class AbstractService

java.lang.Object
  extended by org.mule.service.AbstractService
All Implemented Interfaces:
Serializable, MuleContextAware, Disposable, Initialisable, Lifecycle, Startable, Stoppable, NamedObject, Service
Direct Known Subclasses:
DirectService, SedaService

public abstract class AbstractService
extends Object
implements Service

A base implementation for all UMOComponents in Mule

See Also:
Serialized Form

Field Summary
protected  EntryPointResolverSet entryPointResolverSet
           
protected  ExceptionListener exceptionListener
          The exception strategy used by the service.
protected  InboundRouterCollection inboundRouter
           
static String INITIAL_STATE_PAUSED
           
static String INITIAL_STATE_STARTED
           
static String INITIAL_STATE_STOPPED
          The initial states that the service can be started in
protected  List initialisationCallbacks
           
protected  edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean initialised
          Determines if the service has been initilised
protected  String initialState
          Determines the initial state of this service when the model starts.
protected  Log logger
          logger used by this class
protected  Model model
          The model in which this service is registered
protected  MuleContext muleContext
           
protected  String name
          The service's name
protected  NestedRouterCollection nestedRouter
           
protected  OutboundRouterCollection outboundRouter
           
protected  WaitableBoolean paused
          Determines if the service has been paused
protected  Map properties
          Deprecated. MULE-1933 Properties for the underlying service should be set on the ServiceFactory instead.
protected  ResponseRouterCollection responseRouter
           
protected  ObjectFactory serviceFactory
          Factory which creates an instance of the actual service object.
protected  ServiceStatistics stats
           
protected  edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean stopped
          Determines if the service has been stopped
protected  WaitableBoolean stopping
          Determines whether stop has been called and is still in progress
 
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
AbstractService()
          For Spring only
 
Method Summary
 void addInitialisationCallback(InitialisationCallback callback)
          Register a custom initialiser
protected  void connectListeners()
           
protected  MuleProxy createComponentProxy(Object pojoService)
           
protected  ServiceStatistics createStatistics()
           
protected  void disconnectListeners()
           
 void dispatchEvent(MuleEvent event)
          Makes an asynhronous event call to the service.
 void dispose()
          A lifecycle method where implementor should free up any resources.
protected abstract  void doDispatch(MuleEvent event)
           
protected  void doDispose()
           
protected  void doForceStop()
           
protected  void doInitialise()
           
protected  void doPause()
          Custom components can execute code necessary to put the service in a paused state here.
protected  void doResume()
          Custom components can execute code necessary to resume a service once it has been paused If a developer overloads this method the doPause() method MUST also be overloaded to avoid inconsistent state in the service
protected abstract  MuleMessage doSend(MuleEvent event)
           
protected  void doStart()
           
protected  void doStop()
           
protected  void fireComponentNotification(int action)
           
 void fireInitialisationCallbacks(Object component)
           
 void forceStop()
           
 EntryPointResolverSet getEntryPointResolverSet()
          A descriptor can have a custom entrypoint resolver for its own object.
 ExceptionListener getExceptionListener()
          The exception strategy to use to handle exceptions in the Mule UMO.
 InboundRouterCollection getInboundRouter()
          Inbound Routers control how events are received by a service.
protected  List getIncomingEndpoints()
          Returns a list of all incoming endpoints on a service.
 String getInitialState()
          Returns the initial state of this service
 Model getModel()
          Returns the name of the model that this descriptor is registered with.
 String getName()
          Gts the name of the object
 NestedRouterCollection getNestedRouter()
           
protected  Object getOrCreateService()
           
 OutboundRouterCollection getOutboundRouter()
          Outbound Routers control how events are published by a service once.
 Map getProperties()
          The properties for the Mule UMO.
 ResponseRouterCollection getResponseRouter()
          Response Routers control how events are returned in a request/response call.
 ObjectFactory getServiceFactory()
           
 ServiceStatistics getStatistics()
           
protected  void handleException(Exception e)
           
 void initialise()
          Initialise the service.
 boolean isPaused()
          Determines if the service is in a paused state
 boolean isStarted()
          Determines whether this service has been started
 boolean isStopped()
           
 boolean isStopping()
           
 void pause()
          Pauses event processing for a single Mule Service.
protected  void registerListeners()
           
 void resume()
          Resumes a single Mule Service that has been paused.
 MuleMessage sendEvent(MuleEvent event)
          Makes a synhronous event call to the service.
 void setEntryPointResolvers(Collection entryPointResolvers)
          Allow for incremental addition of resolvers
 void setEntryPointResolverSet(EntryPointResolverSet resolverSet)
          A descriptor can have a custom entrypoint resolver for its own object.
 void setExceptionListener(ExceptionListener exceptionListener)
          The exception strategy to use to handle exceptions in the Mule UMO.
 void setInboundRouter(InboundRouterCollection inboundRouter)
          Inbound Routers control how events are received by a service.
 void setInitialState(String initialState)
          Sets the initial state of this service
 void setModel(Model model)
          Sets the Model name that this descriptor is registered within.
 void setMuleContext(MuleContext context)
           
 void setName(String name)
          Sets the name of the object
 void setNestedRouter(NestedRouterCollection nestedRouter)
           
 void setOutboundRouter(OutboundRouterCollection outboundRouter)
          Outbound Routers control how events are published by a service once.
 void setProperties(Map properties)
          The properties for the Mule UMO.
 void setResponseRouter(ResponseRouterCollection responseRouter)
          Response Routers control how events are returned in a request/response call.
 void setServiceFactory(ObjectFactory serviceFactory)
          Factory which creates an instance of the actual service object.
 void start()
           
protected  void start(boolean startPaused)
          Starts a Mule Service.
protected  void startListeners()
           
 void stop()
           
protected  void stopListeners()
           
 String toString()
           
protected  void unregisterListeners()
           
protected  void waitIfPaused(MuleEvent event)
          Called before an event is sent or dispatched to a service, it will block until resume() is called.
 
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


stats

protected ServiceStatistics stats

stopped

protected edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean stopped
Determines if the service has been stopped


stopping

protected WaitableBoolean stopping
Determines whether stop has been called and is still in progress


initialised

protected edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean initialised
Determines if the service has been initilised


model

protected Model model
The model in which this service is registered


paused

protected WaitableBoolean paused
Determines if the service has been paused


muleContext

protected MuleContext muleContext

entryPointResolverSet

protected EntryPointResolverSet entryPointResolverSet

INITIAL_STATE_STOPPED

public static final String INITIAL_STATE_STOPPED
The initial states that the service can be started in

See Also:
Constant Field Values

INITIAL_STATE_STARTED

public static final String INITIAL_STATE_STARTED
See Also:
Constant Field Values

INITIAL_STATE_PAUSED

public static final String INITIAL_STATE_PAUSED
See Also:
Constant Field Values

exceptionListener

protected ExceptionListener exceptionListener
The exception strategy used by the service.


serviceFactory

protected ObjectFactory serviceFactory
Factory which creates an instance of the actual service object. By default a singleton object factory with the PassThroughComponent is used


name

protected String name
The service's name


inboundRouter

protected InboundRouterCollection inboundRouter

outboundRouter

protected OutboundRouterCollection outboundRouter

nestedRouter

protected NestedRouterCollection nestedRouter

responseRouter

protected ResponseRouterCollection responseRouter

initialState

protected String initialState
Determines the initial state of this service when the model starts. Can be 'stopped' or 'started' (default)


initialisationCallbacks

protected List initialisationCallbacks

properties

protected Map properties
Deprecated. MULE-1933 Properties for the underlying service should be set on the ServiceFactory instead.
The properties for the Mule UMO.

Constructor Detail

AbstractService

public AbstractService()
For Spring only

Method Detail

initialise

public final void initialise()
                      throws InitialisationException
Initialise the service. The service will first create a Mule UMO from the UMODescriptor and then initialise a pool based on the attributes in the UMODescriptor.

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException - if the service fails to initialise
RecoverableException - if an error occurs that can be recovered from

createStatistics

protected ServiceStatistics createStatistics()

fireComponentNotification

protected void fireComponentNotification(int action)

forceStop

public void forceStop()
               throws MuleException
Throws:
MuleException

stop

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

start

public void start()
           throws MuleException
Specified by:
start in interface Startable
Throws:
MuleException

start

protected void start(boolean startPaused)
              throws MuleException
Starts a Mule Service.

Parameters:
startPaused - - Start service in a "paused" state (messages are received but not processed).
Throws:
MuleException

pause

public final void pause()
                 throws MuleException
Pauses event processing for a single Mule Service. Unlike stop(), a paused service will still consume messages from the underlying transport, but those messages will be queued until the service is resumed.

Specified by:
pause in interface Service
Throws:
MuleException

resume

public final void resume()
                  throws MuleException
Resumes a single Mule Service that has been paused. If the service is not paused nothing is executed.

Specified by:
resume in interface Service
Throws:
MuleException

isPaused

public boolean isPaused()
Determines if the service is in a paused state

Specified by:
isPaused in interface Service
Returns:
True if the service is in a paused state, false otherwise

doPause

protected void doPause()
                throws MuleException
Custom components can execute code necessary to put the service in a paused state here. If a developer overloads this method the doResume() method MUST also be overloaded to avoid inconsistent state in the service

Throws:
MuleException

doResume

protected void doResume()
                 throws MuleException
Custom components can execute code necessary to resume a service once it has been paused If a developer overloads this method the doPause() method MUST also be overloaded to avoid inconsistent state in the service

Throws:
MuleException

dispose

public final void dispose()
Description copied from interface: Disposable
A lifecycle method where implementor should free up any resources. If an exception is thrown it should just be logged and processing should continue. This method should not throw Runtime exceptions.

Specified by:
dispose in interface Disposable

getStatistics

public ServiceStatistics getStatistics()

dispatchEvent

public void dispatchEvent(MuleEvent event)
                   throws MuleException
Description copied from interface: Service
Makes an asynhronous event call to the service.

Specified by:
dispatchEvent in interface Service
Parameters:
event - the event to consume
Throws:
MuleException - if the event fails to be processed

sendEvent

public MuleMessage sendEvent(MuleEvent event)
                      throws MuleException
Description copied from interface: Service
Makes a synhronous event call to the service. This event will be consumed by the service and a result returned.

Specified by:
sendEvent in interface Service
Parameters:
event - the event to consume
Returns:
a MuleMessage containing the resulting message and properties
Throws:
MuleException - if the event fails to be processed

waitIfPaused

protected void waitIfPaused(MuleEvent event)
                     throws InterruptedException
Called before an event is sent or dispatched to a service, it will block until resume() is called. Users can override this method if they want to handle pausing differently e.g. implement a store and forward policy

Parameters:
event - the current event being passed to the service
Throws:
InterruptedException - if the thread is interrupted

getName

public String getName()
Description copied from interface: NamedObject
Gts the name of the object

Specified by:
getName in interface NamedObject
Returns:
the Mule descriptor name which is associated with the service

toString

public String toString()
Overrides:
toString in class Object

isStopped

public boolean isStopped()

isStopping

public boolean isStopping()

handleException

protected void handleException(Exception e)

doForceStop

protected void doForceStop()
                    throws MuleException
Throws:
MuleException

doStop

protected void doStop()
               throws MuleException
Throws:
MuleException

doStart

protected void doStart()
                throws MuleException
Throws:
MuleException

doDispose

protected void doDispose()

doInitialise

protected void doInitialise()
                     throws InitialisationException
Throws:
InitialisationException

isStarted

public boolean isStarted()
Description copied from interface: Service
Determines whether this service has been started

Specified by:
isStarted in interface Service
Returns:
true is the service is started andready to receive events

doSend

protected abstract MuleMessage doSend(MuleEvent event)
                               throws MuleException
Throws:
MuleException

doDispatch

protected abstract void doDispatch(MuleEvent event)
                            throws MuleException
Throws:
MuleException

registerListeners

protected void registerListeners()
                          throws MuleException
Throws:
MuleException

unregisterListeners

protected void unregisterListeners()
                            throws MuleException
Throws:
MuleException

startListeners

protected void startListeners()
                       throws MuleException
Throws:
MuleException

stopListeners

protected void stopListeners()
                      throws MuleException
Throws:
MuleException

connectListeners

protected void connectListeners()
                         throws MuleException
Throws:
MuleException

disconnectListeners

protected void disconnectListeners()
                            throws MuleException
Throws:
MuleException

getIncomingEndpoints

protected List getIncomingEndpoints()
Returns a list of all incoming endpoints on a service.


setMuleContext

public void setMuleContext(MuleContext context)
Specified by:
setMuleContext in interface MuleContextAware

createComponentProxy

protected MuleProxy createComponentProxy(Object pojoService)
                                  throws MuleException
Throws:
MuleException

getOrCreateService

protected Object getOrCreateService()
                             throws MuleException
Throws:
MuleException

fireInitialisationCallbacks

public void fireInitialisationCallbacks(Object component)
                                 throws InitialisationException
Throws:
InitialisationException

addInitialisationCallback

public void addInitialisationCallback(InitialisationCallback callback)
Description copied from interface: Service
Register a custom initialiser

Specified by:
addInitialisationCallback in interface Service

getModel

public Model getModel()
Description copied from interface: Service
Returns the name of the model that this descriptor is registered with.

Specified by:
getModel in interface Service
Returns:
the name of the model that this descriptor is registered with or null if this descriptor has not been registered with a model yet

setModel

public void setModel(Model model)
Description copied from interface: Service
Sets the Model name that this descriptor is registered within.

Specified by:
setModel in interface Service

getServiceFactory

public ObjectFactory getServiceFactory()
Specified by:
getServiceFactory in interface Service
Returns:
Factory which creates an instance of the actual service object.

setServiceFactory

public void setServiceFactory(ObjectFactory serviceFactory)
Description copied from interface: Service
Factory which creates an instance of the actual service object.

Specified by:
setServiceFactory in interface Service

getExceptionListener

public ExceptionListener getExceptionListener()
Description copied from interface: Service
The exception strategy to use to handle exceptions in the Mule UMO.

Specified by:
getExceptionListener in interface Service
Returns:
the exception strategy to use. If none has been set a default will be used.

setExceptionListener

public void setExceptionListener(ExceptionListener exceptionListener)
Description copied from interface: Service
The exception strategy to use to handle exceptions in the Mule UMO.

Specified by:
setExceptionListener in interface Service
Parameters:
exceptionListener - the exception strategy to use. If none has been set or argument is null a default

getInboundRouter

public InboundRouterCollection getInboundRouter()
Description copied from interface: Service
Inbound Routers control how events are received by a service. If no router is set. A default will be used that uses the inboundProvider set on his descriptor.

Specified by:
getInboundRouter in interface Service
Returns:
the inbound router for this service. This will always return a valid router.
See Also:
InboundRouterCollection

setInboundRouter

public void setInboundRouter(InboundRouterCollection inboundRouter)
Description copied from interface: Service
Inbound Routers control how events are received by a service. If no router is set. A default will be used that uses the inboundProvider set on his descriptor.

Specified by:
setInboundRouter in interface Service
Parameters:
inboundRouter - the inbound router for this service
See Also:
InboundRouterCollection

getNestedRouter

public NestedRouterCollection getNestedRouter()
Specified by:
getNestedRouter in interface Service

setNestedRouter

public void setNestedRouter(NestedRouterCollection nestedRouter)
Specified by:
setNestedRouter in interface Service

getOutboundRouter

public OutboundRouterCollection getOutboundRouter()
Description copied from interface: Service
Outbound Routers control how events are published by a service once. the event has been processed. If no router is set. A default will be used that uses the outboundProvider set on his descriptor to route the event.

Specified by:
getOutboundRouter in interface Service
Returns:
the outbound router for this service
See Also:
OutboundRouterCollection

setOutboundRouter

public void setOutboundRouter(OutboundRouterCollection outboundRouter)
Description copied from interface: Service
Outbound Routers control how events are published by a service once. the event has been processed. If no router is set. A default will be used that uses the outboundProvider set on his descriptor to route the event.

Specified by:
setOutboundRouter in interface Service
Parameters:
outboundRouter - the outbound router for this service
See Also:
OutboundRouterCollection

getResponseRouter

public ResponseRouterCollection getResponseRouter()
Description copied from interface: Service
Response Routers control how events are returned in a request/response call. It cn be use to aggregate response events before returning, thus acting as a Join in a forked process. This can be used to make request/response calls a lot more efficient as independent tasks can be forked, execute concurrently and then join before the request completes

Specified by:
getResponseRouter in interface Service
Returns:
the response router for this service
See Also:
ResponseRouterCollection

setResponseRouter

public void setResponseRouter(ResponseRouterCollection responseRouter)
Description copied from interface: Service
Response Routers control how events are returned in a request/response call. It cn be use to aggregate response events before returning, thus acting as a Join in a forked process. This can be used to make request/response calls a lot more efficient as independent tasks can be forked, execute concurrently and then join before the request completes

Specified by:
setResponseRouter in interface Service
Parameters:
responseRouter - the response router for this service
See Also:
ResponseRouterCollection

getInitialState

public String getInitialState()
Description copied from interface: Service
Returns the initial state of this service

Specified by:
getInitialState in interface Service
Returns:
the initial state of this service

setInitialState

public void setInitialState(String initialState)
Description copied from interface: Service
Sets the initial state of this service

Specified by:
setInitialState in interface Service
Parameters:
initialState - the initial state of this service
See Also:
org.mule.ImmutableMuleDescriptor#INITIAL_STATE_STARTED, org.mule.ImmutableMuleDescriptor#INITIAL_STATE_STOPPED, org.mule.ImmutableMuleDescriptor#INITIAL_STATE_PAUSED

setName

public void setName(String name)
Description copied from interface: NamedObject
Sets the name of the object

Specified by:
setName in interface NamedObject
Parameters:
name - the name of the object

getProperties

public Map getProperties()
Description copied from interface: Service
The properties for the Mule UMO.

Specified by:
getProperties in interface Service

setProperties

public void setProperties(Map properties)
Description copied from interface: Service
The properties for the Mule UMO.

Specified by:
setProperties in interface Service

getEntryPointResolverSet

public EntryPointResolverSet getEntryPointResolverSet()
A descriptor can have a custom entrypoint resolver for its own object. By default this is null. When set this resolver will override the resolver on the model

Specified by:
getEntryPointResolverSet in interface Service
Returns:
Null is a resolver set has not been set otherwise the resolver to use on this service

setEntryPointResolverSet

public void setEntryPointResolverSet(EntryPointResolverSet resolverSet)
A descriptor can have a custom entrypoint resolver for its own object. By default this is null. When set this resolver will override the resolver on the model

Specified by:
setEntryPointResolverSet in interface Service
Parameters:
resolverSet - theresolver set to use when resolving entry points on this service

setEntryPointResolvers

public void setEntryPointResolvers(Collection entryPointResolvers)
Allow for incremental addition of resolvers

Parameters:
entryPointResolvers - Resolvers to add


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