Package com.levigo.jadice.server.core
Class NodeWorker<N extends Node>
- java.lang.Object
-
- com.levigo.jadice.server.core.NodeWorker<N>
-
- Type Parameters:
N
- the type ofNode
used by theNodeWorker
.
- All Implemented Interfaces:
QualifiedLogEventReceiver
,WorkerController<N>
,Runnable
- Direct Known Subclasses:
DemultiplexerWorker
,DynamicPipelineWorker
,EmbedAttachmentsWorker
,ExternalProcessCallWorker
,GhostscriptWorker
,ImageMagickConvertWorker
,JadiceServerInfoWorker
,JavamailInputWorker
,MailBodyCreatorWorker
,MultiplexerWorker
,PDFCompositeWorker
,PDFMergeWorker
,PropertiesLogWorker
,ReshapeWorker
,RouterWorker
,ScriptWorker
,StreamInputWorker
,StreamOutputWorker
,StreamWorker
,TIFFMergeWorker
,URLInputWorker
,XRechnung2PdfWorker
,ZIPWorker
public abstract class NodeWorker<N extends Node> extends Object implements Runnable, WorkerController<N>
-
-
Constructor Summary
Constructors Constructor Description NodeWorker()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 bundlevoid
addOutputBundle(StreamBundle sb)
Set the output stream bundleprotected 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(org.jadice.util.log.qualified.MessageID messageId, Object... args)
Emit a non-fatal error to be ultimately propagated toJobListener
.void
error(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
Emit a non-fatal error to be ultimately propagated toJobListener
.void
error(org.jadice.util.log.qualified.QualifiedLogEvent event)
Emit a non-fatal error to be ultimately propagated toJobListener
.void
fail(org.jadice.util.log.qualified.MessageID messageId, Object... args)
Make the worker (and subsequently the node) fail due to the specified reason.void
fail(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
Make the worker (and subsequently the node) fail due to the specified reason.void
fail(org.jadice.util.log.qualified.QualifiedLogEvent event)
Make the worker (and subsequently the node) fail due to the specified reason.protected WorkerController<N>
getController()
Return aWorkerController
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()
TheLimitSupport
is an easy utility for ensuring thatLimit
s are respected.N
getNode()
Get theNode
.StreamBundle
getOutputBundle()
Returns the output stream bundleList<StreamBundle>
getOutputBundles()
Get the list of output bundles.ServerJob
getServerJob()
Get theServerJob
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 afterwork()
has returned.protected void
preWork()
This method is called immediately beforework()
will be called.void
run()
void
setDescriptor(N wd)
Set theNode
.void
setJob(ServerJob sb)
Set the server job.String
toString()
void
warn(org.jadice.util.log.qualified.MessageID messageId, Object... args)
Emit a warning to be ultimately propagated toJobListener
.void
warn(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
Emit a warning to be ultimately propagated toJobListener
.void
warn(org.jadice.util.log.qualified.QualifiedLogEvent event)
Emit a warning to be ultimately propagated toJobListener
.protected abstract void
work()
Implement this method to let the node perform some useful work.
-
-
-
Method Detail
-
abort
public final void abort()
Indicate that any current work should be aborted. Node implementations may not actually support aborting. In this case, the worker will continue its normal work process to its completion.
-
doAbort
protected void doAbort()
NodeWorker implementations can provide here own logic that shall be performed when an abort is triggered.- Since:
- jadice server 5.5.0.0
-
abortNow
public final void abortNow()
Indicate that any current work should be aborted ASAP. Calling this method will close all input and output bundles and streams, thereby speeding up the termination.
-
doAbortNow
protected void doAbortNow()
NodeWorker implementations can provide here own logic that shall be performed when an immediate abort is triggered.jadice server 5.5.0.0
-
getNode
public final N getNode()
Get theNode
.- Specified by:
getNode
in interfaceWorkerController<N extends Node>
- Returns:
- the associated
Node
-
getInputBundle
public final StreamBundle getInputBundle()
Get the input stream bundle.- Returns:
- the
input bundle
associated with this worker
-
getServerJob
public final ServerJob getServerJob()
Description copied from interface:WorkerController
Get theServerJob
associated with this worker controller.- Specified by:
getServerJob
in interfaceWorkerController<N extends Node>
- Returns:
- The
job
where this worker is part of
-
getJob
public final Job getJob()
-
getOutputBundle
public final StreamBundle getOutputBundle()
Returns the output stream bundle- Returns:
- the
output bundle
associated with this worker
-
initialize
public void initialize() throws JobException
This method may be overridden, in order do perform initialization which is necessary before the actual work is started.
Caveat: this method may be called synchronously by the server master thread. Therefore the work done within this call should be kept to an absolute minimum so as not to stall the job acceptor.- Throws:
JobException
- in case of initialization failure
-
isAbortRequested
public final boolean isAbortRequested()
- Returns:
- whether the Node was asked to abort its work.
-
addInputBundle
public void addInputBundle(StreamBundle inputBundle)
Set the input stream bundle- Parameters:
inputBundle
- aStreamBundle
-
setDescriptor
public final void setDescriptor(N wd)
Set theNode
.- Parameters:
wd
- the associatedNode
-
setJob
public final void setJob(ServerJob sb)
Set the server job.- Parameters:
sb
- the associatedServerJob
-
addOutputBundle
public void addOutputBundle(StreamBundle sb)
Set the output stream bundle- Parameters:
sb
- aStreamBundle
-
work
protected abstract void work() throws Throwable
Implement this method to let the node perform some useful work.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.- Throws:
Throwable
- in case of processing failure
-
preWork
protected void preWork() throws Throwable
This method is called immediately beforework()
will be called.Use this method e.g. to initialize objects on the same
Thread
on whichwork()
is executed in contrast toinitialize()
which is called on a differentThread
.- Throws:
Throwable
- in case of preparation errors- See Also:
initialize()
,work()
,postWork()
-
postWork
protected void postWork() throws Throwable
-
getTransportSender
protected final com.levigo.jadice.server.shared.transport.internal.TransportSender getTransportSender()
-
getStreamTransportFactory
protected final StreamTransportFactory getStreamTransportFactory()
-
fail
public final void fail(org.jadice.util.log.qualified.QualifiedLogEvent event)
Make the worker (and subsequently the node) fail due to the specified reason. This method will always throw a special kind of RuntimeException used to bubble-up the failure information.- Specified by:
fail
in interfaceQualifiedLogEventReceiver
- Parameters:
event
- reason why this worker failed
-
fail
public final void fail(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
Make the worker (and subsequently the node) fail due to the specified reason. This method will always throw a special kind of RuntimeException used to bubble-up the failure information. If you have not defined an appropriateMessageID
, you can use Messages#GENERIC as workaround.- Specified by:
fail
in interfaceQualifiedLogEventReceiver
- Parameters:
messageId
- message ID why this worker failedcause
- the exception that was thrownargs
- further details
-
fail
public final void fail(org.jadice.util.log.qualified.MessageID messageId, Object... args)
Make the worker (and subsequently the node) fail due to the specified reason. This method will always throw a special kind of RuntimeException used to bubble-up the failure information. If you have not defined an appropriateMessageID
, you can use Messages#GENERIC as workaround.- Specified by:
fail
in interfaceQualifiedLogEventReceiver
- Parameters:
messageId
- message ID why this worker failedargs
- further details
-
getInputBundles
public List<StreamBundle> getInputBundles()
Get the list of input stream bundles. Used byNode.Cardinality.MANY
workers only. All other workers may usegetInputBundle()
andgetOutputBundle()
respectively.- Returns:
- The
input bundles
of this worker
-
getOutputBundles
public List<StreamBundle> getOutputBundles()
Get the list of output bundles. Used byNode.Cardinality.MANY
workers only. All other workers may usegetInputBundle()
andgetOutputBundle()
respectively.- Returns:
- The
output bundles
of this worker
-
getState
public ProcessingState getState()
- Returns:
- the current
ProcessingState
of this worker.
-
warn
public void warn(org.jadice.util.log.qualified.QualifiedLogEvent event)
Emit a warning to be ultimately propagated toJobListener
.- Specified by:
warn
in interfaceQualifiedLogEventReceiver
- Parameters:
event
- reason of warning
-
warn
public void warn(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
Emit a warning to be ultimately propagated toJobListener
. If you have not defined an appropriateMessageID
, you can use Messages#GENERIC as workaround.- Specified by:
warn
in interfaceQualifiedLogEventReceiver
- Parameters:
messageId
- message ID why this worker emits a warningcause
- an exception that was thrownargs
- further details
-
warn
public void warn(org.jadice.util.log.qualified.MessageID messageId, Object... args)
Emit a warning to be ultimately propagated toJobListener
.- Specified by:
warn
in interfaceQualifiedLogEventReceiver
- Parameters:
messageId
- message ID why this worker emits a warningargs
- further details
-
error
public void error(org.jadice.util.log.qualified.QualifiedLogEvent event)
Emit a non-fatal error to be ultimately propagated toJobListener
.- Specified by:
error
in interfaceQualifiedLogEventReceiver
- Parameters:
event
- reason of error
-
error
public void error(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)
Emit a non-fatal error to be ultimately propagated toJobListener
. If you have not defined an appropriateMessageID
, you can use Messages#GENERIC as workaround.- Specified by:
error
in interfaceQualifiedLogEventReceiver
- Parameters:
messageId
- message ID why this worker emits an errorcause
- an exception that was thrownargs
- further details
-
error
public void error(org.jadice.util.log.qualified.MessageID messageId, Object... args)
Emit a non-fatal error to be ultimately propagated toJobListener
. If you have not defined an appropriateMessageID
, you can use Messages#GENERIC as workaround.- Specified by:
error
in interfaceQualifiedLogEventReceiver
- Parameters:
messageId
- message ID why this worker emits an errorargs
- further details
-
getController
protected WorkerController<N> getController()
Return aWorkerController
for this worker. TheWorkerController
interface is currently implemented by this class itself, leaving it to the good-will of owners of aWorkerController
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.- Returns:
WorkerController
for this worker
-
getLimitSupport
protected LimitSupport getLimitSupport()
TheLimitSupport
is an easy utility for ensuring thatLimit
s are respected. The method must not be accessed before Worker was fully initialized.- Returns:
- The Limit Test Utility.
-
-