public class LifecycleUtils extends Object
Initialisable, Startable, Stoppable, Disposable or even MuleContextAware.
The Optional object container is also supported, in which case the operation will be evaluated on the value it holds or
not at all if the value is not present.
| Modifier and Type | Method and Description |
|---|---|
static void |
assertNotStopping(MuleContext muleContext,
String errorMessage)
Verifies that the given
muleContext is not stopped or in the process of stopping |
static void |
disposeIfNeeded(Collection<? extends Object> objects,
org.slf4j.Logger logger)
For each item in the
objects collection, it invokes Disposable.dispose() if it implements the
Disposable interface. |
static void |
disposeIfNeeded(Object object,
org.slf4j.Logger logger)
Invokes
Disposable.dispose() on object if it implements the Disposable interface. |
static void |
initialiseIfNeeded(Collection<? extends Object> objects)
For each item in the
objects collection, it invokes initialiseIfNeeded(Object) |
static void |
initialiseIfNeeded(Collection<? extends Object> objects,
boolean inject,
MuleContext muleContext)
For each item in the
objects collection, it invokes initialiseIfNeeded(Object, MuleContext) |
static void |
initialiseIfNeeded(Collection<? extends Object> objects,
MuleContext muleContext)
For each item in the
objects collection, it invokes initialiseIfNeeded(Object, MuleContext) |
static void |
initialiseIfNeeded(Object object)
Invokes
Initialisable.initialise() on object if it implements the Initialisable interface. |
static void |
initialiseIfNeeded(Object object,
boolean inject,
MuleContext muleContext)
The same as
initialiseIfNeeded(Object), only that before checking for object being Initialisable, it
uses the given muleContext to perform further initialization. |
static void |
initialiseIfNeeded(Object object,
MuleContext muleContext)
The same as
initialiseIfNeeded(Object), only that before checking for object being Initialisable, it
uses the given muleContext to perform further initialization. |
static void |
initialiseIfNeeded(Object object,
MuleContext muleContext,
FlowConstruct flowConstruct)
The same as
initialiseIfNeeded(Object, MuleContext), only that it also checks if it implements
FlowConstructAware, in which case it will invoke FlowConstructAware.setFlowConstruct(FlowConstruct) with the
given flowConstruct |
static void |
safeStopIfNeeded(Collection<? extends Object> objects,
org.slf4j.Logger logger)
For each item in the
objects collection, it invokes the Stoppable.stop() if it implements the
Stoppable interface. |
static void |
setFlowConstructIfNeeded(Collection<? extends Object> objects,
FlowConstruct flowConstruct)
Sets an objects
FlowConstruct if it implements FlowConstructAware. |
static void |
setFlowConstructIfNeeded(Object object,
FlowConstruct flowConstruct)
Sets an objects
FlowConstruct if it implements FlowConstructAware. |
static void |
setMuleContextIfNeeded(Collection<? extends Object> objects,
MuleContext muleContext)
Sets an objects
MuleContext if it implements MuleContextAware. |
static void |
setMuleContextIfNeeded(Object object,
MuleContext muleContext)
Sets an objects
MuleContext if it implements MuleContextAware. |
static void |
startIfNeeded(Collection<? extends Object> objects)
For each item in the
objects collection, it invokes the the Startable.start() if it implements the
Startable interface. |
static void |
startIfNeeded(Object object)
Invokes
Startable.start() on object if it implements the Startable interface |
static void |
stopIfNeeded(Collection<? extends Object> objects)
For each item in the
objects collection, it invokes the Stoppable.stop() if it implements the
Stoppable interface. |
static void |
stopIfNeeded(Object object)
Invokes the
Stoppable.stop() on object if it implements the Stoppable interface. |
public static void initialiseIfNeeded(Object object) throws org.mule.runtime.api.lifecycle.InitialisationException
Initialisable.initialise() on object if it implements the Initialisable interface.object - the object you're trying to initialiseorg.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void initialiseIfNeeded(Object object, MuleContext muleContext, FlowConstruct flowConstruct) throws org.mule.runtime.api.lifecycle.InitialisationException
initialiseIfNeeded(Object, MuleContext), only that it also checks if it implements
FlowConstructAware, in which case it will invoke FlowConstructAware.setFlowConstruct(FlowConstruct) with the
given flowConstructobject - the object you're trying to initialisemuleContext - a MuleContextflowConstruct - the FlowConstruct in which the object is defined.org.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void initialiseIfNeeded(Object object, MuleContext muleContext) throws org.mule.runtime.api.lifecycle.InitialisationException
initialiseIfNeeded(Object), only that before checking for object being Initialisable, it
uses the given muleContext to perform further initialization.
It checks if the object implements MuleContextAware, in which case it will invoke
MuleContextAware.setMuleContext(MuleContext) with the given muleContext.
object - the object you're trying to initialisemuleContext - a MuleContextorg.mule.runtime.api.lifecycle.InitialisationExceptionIllegalArgumentException - if MuleContext is nullpublic static void initialiseIfNeeded(Object object, boolean inject, MuleContext muleContext) throws org.mule.runtime.api.lifecycle.InitialisationException
initialiseIfNeeded(Object), only that before checking for object being Initialisable, it
uses the given muleContext to perform further initialization.
It checks if the object implements MuleContextAware, in which case it will invoke
MuleContextAware.setMuleContext(MuleContext) with the given muleContext.
Also depending on the value of the inject argument, it will perform dependency injection on the object
object - the object you're trying to initialiseinject - whether it should perform dependency injection on the object before actually initialising itmuleContext - a MuleContextorg.mule.runtime.api.lifecycle.InitialisationExceptionIllegalArgumentException - if MuleContext is nullpublic static void initialiseIfNeeded(Collection<? extends Object> objects) throws org.mule.runtime.api.lifecycle.InitialisationException
objects collection, it invokes initialiseIfNeeded(Object)objects - the list of objects to be initialisedorg.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void initialiseIfNeeded(Collection<? extends Object> objects, MuleContext muleContext) throws org.mule.runtime.api.lifecycle.InitialisationException
objects collection, it invokes initialiseIfNeeded(Object, MuleContext)objects - the list of objects to be initialisedmuleContext - a MuleContextorg.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void initialiseIfNeeded(Collection<? extends Object> objects, boolean inject, MuleContext muleContext) throws org.mule.runtime.api.lifecycle.InitialisationException
objects collection, it invokes initialiseIfNeeded(Object, MuleContext)
Also depending on the value of the inject argument, it will perform dependency injection on the objects
objects - the list of objects to be initialisedinject - whether it should perform dependency injection on the object before actually initialising itmuleContext - a MuleContextorg.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void startIfNeeded(Object object) throws org.mule.runtime.api.exception.MuleException
Startable.start() on object if it implements the Startable interfaceobject - the object you're trying to startorg.mule.runtime.api.exception.MuleExceptionpublic static void startIfNeeded(Collection<? extends Object> objects) throws org.mule.runtime.api.exception.MuleException
objects collection, it invokes the the Startable.start() if it implements the
Startable interface.objects - the list of objects to be startedorg.mule.runtime.api.exception.MuleExceptionpublic static void stopIfNeeded(Collection<? extends Object> objects) throws org.mule.runtime.api.exception.MuleException
objects collection, it invokes the Stoppable.stop() if it implements the
Stoppable interface.objects - the list of objects to be stoppedorg.mule.runtime.api.exception.MuleExceptionpublic static void safeStopIfNeeded(Collection<? extends Object> objects, org.slf4j.Logger logger)
objects collection, it invokes the Stoppable.stop() if it implements the
Stoppable interface.
This method is considered safe because it will not throw exception and the Stoppable.stop() method will be called on
all the objects regarding on any (or all) of them throwing exceptions. Any exceptions generated will be logged using
the provided logger and processing will continue
objects - the list of objects to be stoppedlogger - the Logger in which any exception found is to be loggedpublic static void stopIfNeeded(Object object) throws org.mule.runtime.api.exception.MuleException
Stoppable.stop() on object if it implements the Stoppable interface.object - the object you're trying to stoporg.mule.runtime.api.exception.MuleExceptionpublic static void disposeIfNeeded(Object object, org.slf4j.Logger logger)
Disposable.dispose() on object if it implements the Disposable interface. If the dispose
operation fails, then the exception will be silently logged using the provided loggerobject - the object you're trying to disposepublic static void disposeIfNeeded(Collection<? extends Object> objects, org.slf4j.Logger logger)
objects collection, it invokes Disposable.dispose() if it implements the
Disposable interface.
Per each dispose operation that fails, the exception will be silently logged using the provided logger
objects - the list of objects to be stoppedorg.mule.runtime.api.exception.MuleExceptionpublic static void assertNotStopping(MuleContext muleContext, String errorMessage)
muleContext is not stopped or in the process of stoppingmuleContext - the MuleContext to testerrorMessage - the message of the Exception to be thrown if the assertion failsIllegalStateException - if the muleContext is stopped or stoppingpublic static void setFlowConstructIfNeeded(Object object, FlowConstruct flowConstruct)
FlowConstruct if it implements FlowConstructAware.object - the object to inject the FlowConstruct into.flowConstruct - the FlowConstruct in which the object is defined.org.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void setFlowConstructIfNeeded(Collection<? extends Object> objects, FlowConstruct flowConstruct)
FlowConstruct if it implements FlowConstructAware.objects - the objects to inject the FlowConstruct into.flowConstruct - the FlowConstruct in which the object is defined.org.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void setMuleContextIfNeeded(Object object, MuleContext muleContext)
MuleContext if it implements MuleContextAware.object - the object to inject the MuleContext into.muleContext - the MuleContext in which the object is defined.org.mule.runtime.api.lifecycle.InitialisationExceptionpublic static void setMuleContextIfNeeded(Collection<? extends Object> objects, MuleContext muleContext)
MuleContext if it implements MuleContextAware.objects - the objects to inject the MuleContext into.muleContext - the MuleContext in which the object is defined.org.mule.runtime.api.lifecycle.InitialisationExceptionCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.