|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object xsmeral.pipe.AbstractObjectProcessor
public abstract class AbstractObjectProcessor
Implements basic functionality common for all object processors.
Provides default (however, overloadable) implementation of the run
method, which defines a specific life-cycle of the processor, with multiple
initialization phases and life-cycle stages.
The complete cycle is as follows:
initialize
method
ParamInitializer
initializeInternal()
initializeInternal
the processor can access the initialization
parameters but not yet the context parameters.
setContext()
, which assigns
the processor a context and in turn calls:
initWithContext()
which can be used to access
context parameters already set by an external entity (not those set by
other processors)
initContextSet()
which sets context parameter
values from ToContext
fields
initContext()
, which initializes fields annotated
with FromContext
with values from context and in turn calls:
initPostContext()
at which time all context
parameters and all context-dependent fields can be accessedrun()
method. The default run cycle is as
follows:
NOT_STARTED
state
preRun()
is called, where the processor
can perform any preparatory operationsRUNNING
process()
is called in loop, while the status is
RUNNING
. If a neighboring processor stops, this processor
stop
s.postRun()
is called, which can be used for cleanup
and releasing resources
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface xsmeral.pipe.interfaces.ObjectProcessor |
---|
ObjectProcessor.Status |
Field Summary | |
---|---|
protected boolean |
canStart
Starting condition indicator ( true by default) |
protected ProcessingContext |
context
Associated context (might be null) |
protected ObjectProcessor.Status |
status
Current status |
Constructor Summary | |
---|---|
AbstractObjectProcessor()
Sets the status to NOT_STARTED . |
Method Summary | |
---|---|
boolean |
canStart()
Indicates whether the processor is ready to start (is correctly initialized). |
protected void |
failStart()
Called by the processor itself, indicates negative starting conditions. |
void |
failStart(String message)
In addition to failStart() , logs a message
indicating the reason for the inability to start |
void |
failStart(String message,
Throwable thrown)
In addition to failStart(String) ,
logs a Throwable |
ProcessingContext |
getContext()
Returns the associated processing context. |
Class |
getInType()
Returns the input type of this processor. |
Class |
getOutType()
Returns the output type of this processor. |
Map<String,String> |
getParams()
Returns the parameter map that was used to initialize this processor. |
ObjectProcessor.Status |
getStatus()
Returns current status of this processor. |
void |
initContext()
Initializes (reflectively) the values of all fields annotated with FromContext
with values taken from the context. |
protected void |
initContextSet()
Initializes (reflectively) context parameters from fields annotated with ToContext . |
ObjectProcessor |
initialize(Map<String,String> params)
Initializes the processor. |
protected void |
initializeInternal()
Should initialize the processor for running, analogically to constructor. |
protected void |
initPostContext()
Called after context-dependencies ( FromContext fields) are resolved. |
protected void |
initWithContext()
Called after a context is assigned. |
protected void |
postRun()
Called as the last statement in run() . |
protected void |
preRun()
Called after initialization, as the first statement in run() . |
protected abstract void |
process()
Called by the processor itself from run() . |
void |
requestStop()
Requests the processor to stop and sets its status to STOPPING . |
void |
run()
Starts the processing, putting the processor into running state . |
void |
setContext(ProcessingContext context)
Associates the processor with the given context. |
protected void |
stop()
Called by the processor itself, sets the status to STOPPED |
String |
toString()
Returns simple class name of this processor. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected ObjectProcessor.Status status
protected ProcessingContext context
protected boolean canStart
true
by default)
Constructor Detail |
---|
public AbstractObjectProcessor()
NOT_STARTED
.
Method Detail |
---|
public final ObjectProcessor.Status getStatus()
ObjectProcessor
getStatus
in interface ObjectProcessor
public Map<String,String> getParams()
public boolean canStart()
ObjectProcessor
canStart
in interface ObjectProcessor
protected final void failStart()
public final void failStart(String message)
failStart()
, logs a message
indicating the reason for the inability to start
public final void failStart(String message, Throwable thrown)
failStart(String)
,
logs a Throwable
public void requestStop()
ObjectProcessor
STOPPING
.
There is no limit to the time it takes the processor to stop, it should
however stop as soon as possible.
requestStop
in interface ObjectProcessor
public void run()
running state
.
More information in description of AbstractObjectProcessor
class, section "Running".
run
in interface Runnable
run
in interface ObjectProcessor
public final Class getOutType()
ObjectProcessor
getOutType
in interface ObjectProcessor
public final Class getInType()
ObjectProcessor
getInType
in interface ObjectProcessor
protected void stop()
STOPPED
public final ProcessingContext getContext()
getContext
in interface ContextAware
public final void setContext(ProcessingContext context) throws ObjectProcessorException
ToContext
.
setContext
in interface ContextAware
ObjectProcessorException
protected final void initContextSet() throws ObjectProcessorException
ToContext
.
ObjectProcessorException
- If a parameter already exists in the context.public final void initContext() throws ObjectProcessorException
ContextAware
FromContext
with values taken from the context. The context parameter name is either
the field name or a name specified as an argument of FromContext
.
initContext
in interface ContextAware
ObjectProcessorException
public final ObjectProcessor initialize(Map<String,String> params)
canStart
).
AbstractObjectProcessor
class, section "Initialization".
initialize
in interface ObjectProcessor
params
- Initialization parameters, substitute for constructor arguments
this
, so that the processor can be instantiated
and initialized in one command:new SomeProcessor().initialize(params);
public String toString()
toString
in class Object
getClass().getSimpleName()
protected void initializeInternal()
AbstractObjectProcessor
class, section "Initialization".
protected void initWithContext()
AbstractObjectProcessor
class, section "Context initialization".
protected void initPostContext()
FromContext
fields) are resolved.
More information in description of AbstractObjectProcessor
class, section "Context initialization".
protected void preRun() throws ProcessorStoppedException
run()
.
More information in description of AbstractObjectProcessor
class, section "Running".
ProcessorStoppedException
protected void postRun()
run()
.
More information in description of AbstractObjectProcessor
class, section "Running".
ProcessorStoppedException
protected abstract void process() throws ProcessorStoppedException
run()
.
Should process one object and return.
More information in description of AbstractObjectProcessor
class, section "Running".
ProcessorStoppedException
- If a neighboring processor has stopped.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |