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)
|
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)
|
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 and dependency injection on the object . |
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 |
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)
|
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)
|
public static void initialiseIfNeeded(Object object) throws InitialisationException
object
- the object you're trying to initialiseInitialisationException
public static void initialiseIfNeeded(Object object, MuleContext muleContext) throws InitialisationException
initialiseIfNeeded(Object)
, only that before checking for object
being Initialisable
, it
uses the given muleContext
to perform further initialization and dependency injection on the object
.
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 MuleContext
InitialisationException
IllegalArgumentException
- if MuleContext
is null
public static void initialiseIfNeeded(Object object, boolean inject, MuleContext muleContext) throws 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 MuleContext
InitialisationException
IllegalArgumentException
- if MuleContext
is null
public static void initialiseIfNeeded(Collection<? extends Object> objects) throws InitialisationException
objects
collection, it invokes initialiseIfNeeded(Object)
objects
- the list of objects to be initialisedInitialisationException
public static void initialiseIfNeeded(Collection<? extends Object> objects, MuleContext muleContext) throws InitialisationException
objects
collection, it invokes initialiseIfNeeded(Object, MuleContext)
objects
- the list of objects to be initialisedmuleContext
- a MuleContext
InitialisationException
public static void initialiseIfNeeded(Collection<? extends Object> objects, boolean inject, MuleContext muleContext) throws 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 MuleContext
InitialisationException
public static void startIfNeeded(Object object) throws MuleException
object
- the object you're trying to startMuleException
public static void startIfNeeded(Collection<? extends Object> objects) throws MuleException
objects
collection, it invokes the the Startable.start()
if it implements the
Startable
interface.objects
- the list of objects to be startedMuleException
public static void stopIfNeeded(Collection<? extends Object> objects) throws MuleException
objects
collection, it invokes the Stoppable.stop()
if it implements the
Stoppable
interface.objects
- the list of objects to be stoppedMuleException
public 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 MuleException
object
- the object you're trying to stopMuleException
public 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 logger
object
- 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 stoppedMuleException
public 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 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.InitialisationException
public 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.InitialisationException
Copyright © 2018. All rights reserved.