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 ofNodeused 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 voidabort()Indicate that any current work should be aborted.voidabortNow()Indicate that any current work should be aborted ASAP.voidaddInputBundle(StreamBundle inputBundle)Set the input stream bundlevoidaddOutputBundle(StreamBundle sb)Set the output stream bundleprotected voiddoAbort()NodeWorker implementations can provide here own logic that shall be performed when an abort is triggered.protected voiddoAbortNow()NodeWorker implementations can provide here own logic that shall be performed when an immediate abort is triggered.voiderror(org.jadice.util.log.qualified.MessageID messageId, Object... args)Emit a non-fatal error to be ultimately propagated toJobListener.voiderror(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)Emit a non-fatal error to be ultimately propagated toJobListener.voiderror(org.jadice.util.log.qualified.QualifiedLogEvent event)Emit a non-fatal error to be ultimately propagated toJobListener.voidfail(org.jadice.util.log.qualified.MessageID messageId, Object... args)Make the worker (and subsequently the node) fail due to the specified reason.voidfail(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)Make the worker (and subsequently the node) fail due to the specified reason.voidfail(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 aWorkerControllerfor this worker.StreamBundlegetInputBundle()Get the input stream bundle.List<StreamBundle>getInputBundles()Get the list of input stream bundles.JobgetJob()protected LimitSupportgetLimitSupport()TheLimitSupportis an easy utility for ensuring thatLimits are respected.NgetNode()Get theNode.StreamBundlegetOutputBundle()Returns the output stream bundleList<StreamBundle>getOutputBundles()Get the list of output bundles.ServerJobgetServerJob()Get theServerJobassociated with this worker controller.ProcessingStategetState()protected StreamTransportFactorygetStreamTransportFactory()protected com.levigo.jadice.server.shared.transport.internal.TransportSendergetTransportSender()voidinitialize()This method may be overridden, in order do perform initialization which is necessary before the actual work is started.booleanisAbortRequested()protected voidpostWork()This method is called immediately afterwork()has returned.protected voidpreWork()This method is called immediately beforework()will be called.voidrun()voidsetDescriptor(N wd)Set theNode.voidsetJob(ServerJob sb)Set the server job.StringtoString()voidwarn(org.jadice.util.log.qualified.MessageID messageId, Object... args)Emit a warning to be ultimately propagated toJobListener.voidwarn(org.jadice.util.log.qualified.MessageID messageId, Throwable cause, Object... args)Emit a warning to be ultimately propagated toJobListener.voidwarn(org.jadice.util.log.qualified.QualifiedLogEvent event)Emit a warning to be ultimately propagated toJobListener.protected abstract voidwork()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:
getNodein interfaceWorkerController<N extends Node>- Returns:
- the associated
Node
-
getInputBundle
public final StreamBundle getInputBundle()
Get the input stream bundle.- Returns:
- the
input bundleassociated with this worker
-
getServerJob
public final ServerJob getServerJob()
Description copied from interface:WorkerControllerGet theServerJobassociated with this worker controller.- Specified by:
getServerJobin interfaceWorkerController<N extends Node>- Returns:
- The
jobwhere this worker is part of
-
getJob
public final Job getJob()
-
getOutputBundle
public final StreamBundle getOutputBundle()
Returns the output stream bundle- Returns:
- the
output bundleassociated with this worker
-
initialize
public void initialize() throws JobExceptionThis 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 ThrowableImplement this method to let the node perform some useful work.Implementors are free to throw whatever exception they see fit. If any
Throwableis 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 ThrowableThis method is called immediately beforework()will be called.Use this method e.g. to initialize objects on the same
Threadon 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:
failin 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:
failin 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:
failin 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.MANYworkers only. All other workers may usegetInputBundle()andgetOutputBundle()respectively.- Returns:
- The
input bundlesof this worker
-
getOutputBundles
public List<StreamBundle> getOutputBundles()
Get the list of output bundles. Used byNode.Cardinality.MANYworkers only. All other workers may usegetInputBundle()andgetOutputBundle()respectively.- Returns:
- The
output bundlesof this worker
-
getState
public ProcessingState getState()
- Returns:
- the current
ProcessingStateof this worker.
-
warn
public void warn(org.jadice.util.log.qualified.QualifiedLogEvent event)
Emit a warning to be ultimately propagated toJobListener.- Specified by:
warnin 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:
warnin 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:
warnin 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:
errorin 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:
errorin 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:
errorin interfaceQualifiedLogEventReceiver- Parameters:
messageId- message ID why this worker emits an errorargs- further details
-
getController
protected WorkerController<N> getController()
Return aWorkerControllerfor this worker. TheWorkerControllerinterface is currently implemented by this class itself, leaving it to the good-will of owners of aWorkerControllerreference 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:
WorkerControllerfor this worker
-
getLimitSupport
protected LimitSupport getLimitSupport()
TheLimitSupportis an easy utility for ensuring thatLimits are respected. The method must not be accessed before Worker was fully initialized.- Returns:
- The Limit Test Utility.
-
-