N
- the type of Node
used by the NodeWorker
.public abstract class NodeWorker<N extends Node> extends Object implements Runnable, WorkerController<N>
Constructor and Description |
---|
NodeWorker() |
Modifier and Type | Method and Description |
---|---|
void |
abort()
Indicate that any current work should be aborted.
|
void |
abortNow()
Indicate that any current work should be aborted ASAP.
|
void |
addInputBundle(StreamBundle inputBundle)
Set the input stream bundle
|
void |
addOutputBundle(StreamBundle sb)
Set the output stream bundle
|
protected void |
doAbort()
NodeWorker implementations can provide here own logic that shall be
performed when an abort is triggered.
|
protected void |
doAbortNow()
NodeWorker implementations can provide here own logic that shall be
performed when an immediate abort is triggered.
|
void |
error(com.levigo.util.log.qualified.MessageID messageId,
Object... args)
Emit a non-fatal error to be ultimately propagated to
JobListener . |
void |
error(com.levigo.util.log.qualified.MessageID messageId,
Throwable cause,
Object... args)
Emit a non-fatal error to be ultimately propagated to
JobListener . |
void |
error(com.levigo.util.log.qualified.QualifiedLogEvent event)
Emit a non-fatal error to be ultimately propagated to
JobListener . |
void |
fail(com.levigo.util.log.qualified.MessageID messageId,
Object... args)
Make the worker (and subsequently the node) fail due to the specified reason.
|
void |
fail(com.levigo.util.log.qualified.MessageID messageId,
Throwable cause,
Object... args)
Make the worker (and subsequently the node) fail due to the specified reason.
|
void |
fail(com.levigo.util.log.qualified.QualifiedLogEvent event)
Make the worker (and subsequently the node) fail due to the specified reason.
|
protected WorkerController<N> |
getController()
Return a
WorkerController for this worker. |
StreamBundle |
getInputBundle()
Get the input stream bundle.
|
List<StreamBundle> |
getInputBundles()
Get the list of input stream bundles.
|
Job |
getJob() |
protected LimitSupport |
getLimitSupport()
The
LimitSupport is an easy utility for ensuring that Limit s are respected. |
N |
getNode()
Get the
Node . |
StreamBundle |
getOutputBundle()
Returns the output stream bundle
|
List<StreamBundle> |
getOutputBundles()
Get the list of output bundles.
|
ServerJob |
getServerJob()
Get the
ServerJob associated with this worker controller. |
ProcessingState |
getState() |
protected StreamTransportFactory |
getStreamTransportFactory() |
protected com.levigo.jadice.server.shared.transport.internal.TransportSender |
getTransportSender() |
void |
initialize()
This method may be overridden, in order do perform initialization which is necessary before the
actual work is started.
|
boolean |
isAbortRequested() |
protected void |
postWork()
This method is called immediately after
work() has returned. |
protected void |
preWork()
This method is called immediately before
work() will be called. |
void |
run() |
void |
setDescriptor(N wd)
Set the
Node . |
void |
setJob(ServerJob sb)
Set the server job.
|
String |
toString() |
void |
warn(com.levigo.util.log.qualified.MessageID messageId,
Object... args)
Emit a warning to be ultimately propagated to
JobListener . |
void |
warn(com.levigo.util.log.qualified.MessageID messageId,
Throwable cause,
Object... args)
Emit a warning to be ultimately propagated to
JobListener . |
void |
warn(com.levigo.util.log.qualified.QualifiedLogEvent event)
Emit a warning to be ultimately propagated to
JobListener . |
protected abstract void |
work()
Implement this method to let the node perform some useful work.
|
public final void abort()
protected void doAbort()
public final void abortNow()
protected void doAbortNow()
public final N getNode()
Node
.getNode
in interface WorkerController<N extends Node>
public final StreamBundle getInputBundle()
input bundle
associated with this workerpublic final ServerJob getServerJob()
WorkerController
ServerJob
associated with this worker controller.getServerJob
in interface WorkerController<N extends Node>
job
where this worker is part ofpublic final Job getJob()
public final StreamBundle getOutputBundle()
output bundle
associated with this workerpublic void initialize() throws JobException
JobException
public final boolean isAbortRequested()
public void addInputBundle(StreamBundle inputBundle)
inputBundle
- public final void setJob(ServerJob sb)
public void addOutputBundle(StreamBundle sb)
sb
- protected abstract void work() throws Throwable
Implementors are free to throw whatever exception they see fit. If any Throwable
is
thrown from this method, the failure manager is notified about the fatal failure of the whole
pipeline.
Throwable
protected void preWork() throws Throwable
This method is called immediately before work()
will be called.
Use this method e.g. to initialize objects on the same Thread
on which work()
is executed in contrast to initialize()
which is called on a different Thread
.
Throwable
initialize()
,
#work()}
,
postWork()
protected void postWork() throws Throwable
protected final com.levigo.jadice.server.shared.transport.internal.TransportSender getTransportSender()
protected final StreamTransportFactory getStreamTransportFactory()
public final void fail(com.levigo.util.log.qualified.QualifiedLogEvent event)
fail
in interface WorkerController<N extends Node>
event
- reason why this worker failedpublic final void fail(com.levigo.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
MessageID
, you can use Messages#GENERIC as
workaround.fail
in interface WorkerController<N extends Node>
messageId
- message ID why this worker failedcause
- the exception that was thrownargs
- further detailspublic final void fail(com.levigo.util.log.qualified.MessageID messageId, Object... args)
MessageID
, you can use Messages#GENERIC as
workaround.fail
in interface WorkerController<N extends Node>
messageId
- message ID why this worker failedargs
- further detailspublic List<StreamBundle> getInputBundles()
Node.Cardinality.MANY
workers only. All other
workers may use getInputBundle()
and getOutputBundle()
respectively.input bundles
of this workerpublic List<StreamBundle> getOutputBundles()
Node.Cardinality.MANY
workers only. All other
workers may use getInputBundle()
and getOutputBundle()
respectively.output bundles
of this workerpublic ProcessingState getState()
ProcessingState
of this worker.public void warn(com.levigo.util.log.qualified.QualifiedLogEvent event)
JobListener
.warn
in interface WorkerController<N extends Node>
event
- reason of warningpublic void warn(com.levigo.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
JobListener
. If you have not defined an
appropriate MessageID
, you can use Messages#GENERIC as workaround.warn
in interface WorkerController<N extends Node>
messageId
- message ID why this worker emits a warningcause
- an exception that was thrownargs
- further detailspublic void warn(com.levigo.util.log.qualified.MessageID messageId, Object... args)
JobListener
. If you have not defined an
appropriate MessageID
, you can use CoreMessages#GENERIC
as workaround.warn
in interface WorkerController<N extends Node>
messageId
- message ID why this worker emits a warningargs
- further detailspublic void error(com.levigo.util.log.qualified.QualifiedLogEvent event)
JobListener
.error
in interface WorkerController<N extends Node>
event
- reason of errorpublic void error(com.levigo.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
JobListener
. If you have not
defined an appropriate MessageID
, you can use Messages#GENERIC as workaround.error
in interface WorkerController<N extends Node>
messageId
- message ID why this worker emits an errorcause
- an exception that was thrownargs
- further detailspublic void error(com.levigo.util.log.qualified.MessageID messageId, Object... args)
JobListener
. If you have not
defined an appropriate MessageID
, you can use Messages#GENERIC as workaround.error
in interface WorkerController<N extends Node>
messageId
- message ID why this worker emits an errorargs
- further detailsprotected WorkerController<N> getController()
WorkerController
for this worker.
The WorkerController
interface is currently implemented by this class itself, leaving
it to the good-will of owners of a WorkerController
reference not to cast it to
NodeWorker and abuse this power. This could conceivably be remedied by letting the node hand
out an implementation of this interface which only delegates the methods clients are supposed
to call.WorkerController
for this workerprotected LimitSupport getLimitSupport()
LimitSupport
is an easy utility for ensuring that Limit
s are respected. The
method must not be accessed before Worker was fully initialized.Copyright © 2017 levigo holding gmbh. All rights reserved.