|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.staccatocommons.io.internal.lifecycle.Lifecycle<ResourceType,ResultType>
ResourceType - the type of resource handled by this lifecycleResultType - the type of result returned by this lifecyclepublic abstract class Lifecycle<ResourceType,ResultType>
A Lifecycle is a logic of initialization, use and dispose of a
resource , that can be executed as a single unit of work. It can be executed
in different fashions - using value(), call() ,
#run() or value()
Lifecycles are abstract, so in order to use them, client code must implement
the following methods
initialize(): this method will be invoked in order to create an
initialize the handled resource. It may throw any exception.
Typical example of such initialization is instantiating the resource or
sending an initmessage.
doWork(Object): this method uses the resource. It will be invoked to
produce the result of the lifecycle, passing the handled resource returned by
the initialize() method. It may throw any
exception.
Lifecycles parameterized to have a result of type Void
must return null; for those cases, client code,
instead of overriding doWork(Object), should
override doVoidWork(Object)
dispose(Object): this method release the handled resource, freeing
any system resources associated to it. It may throw any
exception. Typical example of such disposal is sending a close
message.
This method will be invoked even if the usage of the resource - that is
doWork(Object) or doVoidWork(Object) execution - failed
throwin and exception.
| Constructor Summary | |
|---|---|
Lifecycle()
|
|
| Method Summary | ||
|---|---|---|
ResultType |
call()
Executes this Lifecycle, initializing the resource it handles,
doing some work with it, disposing the resource and returning the work
result. |
|
protected void |
dispose(ResourceType resource)
Disposes the resource. |
|
protected void |
doVoidWork(ResourceType resource)
Makes usage of a resource, without returning a result. |
|
protected ResultType |
doWork(ResourceType resource)
Makes usage of a resource, and returns a result Lifecycles parameterized to have a Void result
should not override this method, but
doVoidWork(Object) instead |
|
protected abstract ResourceType |
initialize()
Initializes and gets a resource of ResourceType |
|
|
throwing(Class<E> exceptionClass)
Handles exceptions of type exceptionClass that may occur when
sending call(). |
|
|
throwing(Class<E1> exceptionClass1,
Class<E2> exceptionClass2)
Handles exceptions of type exceptionClass1 and
exceptionClass2 that may occur when sending call(). |
|
ResultType |
value()
Sends the call() message, softening any exception that may occur. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Lifecycle()
| Method Detail |
|---|
public ResultType call()
throws Exception
Lifecycle, initializing the resource it handles,
doing some work with it, disposing the resource and returning the work
result.
Any checked or unchecked exception produced during the flow execution will
be catch, soften and rethrown.
call in interface Callable<ResultType>RuntimeException - if any exception is thrown during the flow execution
ExceptionSoftException#soften(Exception)public ResultType value()
call() message, softening any exception that may occur.
value in interface net.sf.staccatocommons.defs.Thunk<ResultType>SoftException.callOrSoften(Callable)
public final <E extends Exception> ResultType throwing(Class<E> exceptionClass)
throws E extends Exception
exceptionClass that may occur when
sending call().
This method is just a shortcut for
Handle.throwing(this, exceptionClass)
E extends ExceptionHandle.throwing(Callable, Class)
public final <E1 extends Exception,E2 extends Exception> ResultType throwing(Class<E1> exceptionClass1,
Class<E2> exceptionClass2)
throws E1 extends Exception,
E2 extends Exception
exceptionClass1 and
exceptionClass2 that may occur when sending call().
This method is just a shortcut for
Handle.throwing(this, exceptionClass1, exceptionClass2)
E1 extends ExceptionHandle.throwing(Callable, Class, Class)
protected abstract ResourceType initialize()
throws Exception
Exception - if any error occurs
protected ResultType doWork(@NonNull
ResourceType resource)
throws Exception
Lifecycles parameterized to have a Void result
should not override this method, but
doVoidWork(Object) instead
resource - the resource to use
Void
Exception - if any error occurs
protected void doVoidWork(@NonNull
ResourceType resource)
throws Exception
Lifecycles
parameterized to have a Void result. If it is not the case,
override doWork(Object) instead.
resource - the resource to use
Exception - is any error occurs
protected void dispose(@NonNull
ResourceType resource)
throws Exception
resource -
Exception - if any error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||