Class Job
- java.lang.Object
-
- com.levigo.jadice.server.Job
-
- All Implemented Interfaces:
AutoCloseable
public abstract class Job extends Object implements AutoCloseable
A job represents the unit-of-work for the jadice server system. It is assembled and configured by the client and subsequently submitted to the server for execution where the actually data processing occurs. Each job has an associated acyclic graph (also called a pipeline) ofNodes which defines the necessary steps for a chosen processing goal.For example, a job for a data conversion of a file from one format into another (here: OpenOffice Writer to PDF) might consist of the following pipeline:
com.levigo.jadice.server.nodes.StreamInputNode⇒com.levigo.jadice.server.libreoffice.server.LibreOfficeConversionNode⇒com.levigo.jadice.server.nodes.StreamOutputNodeThis pipeline accepts a data stream (in OpenOffice Writer format) presented via the
com.levigo.jadice.server.nodes.StreamInputNode, applies the conversion and makes the result accessible through thecom.levigo.jadice.server.nodes.StreamOutputNode.Job instances must not be created directly but instantiated by a
JobFactory.As jobs have a life cycle, they must not be reused. The different states are reflected in the
Job.Stateenumeration. Clients may (and should!) take notice of the job life-cycle and other job-related events by registering aJobListener.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJob.StateThe different states a job can have.
-
Field Summary
Fields Modifier and Type Field Description static StringCOMPONENT_IDThe default component ID for Nodes.protected NodenodeThe attached node.static StringPRODUCT_IDThe default product ID for jadice server.protected Map<String,Serializable>propertiesprotected StringserverInstanceNameprotected Job.StatestateThe current state.
-
Constructor Summary
Constructors Constructor Description Job()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract voidabort()Abort the job, i.e.voidaddJobListener(JobListener listener)Add aJobListenerto be notified of the job's progress and other job-related events.voidapply(Limit limit)Apply aLimitto this Job.abstract voidattach(Node node)Attach aNode.abstract voidclose()Close the job and free up any resources held by it.booleanequals(Object obj)protected voidfinalize()Deprecated.LocalegetClientLocale()StringgetClientVersion()protected JobListener[]getJobListeners()Get the registered listeners.LimitsgetLimits()NodegetNode()Return the attached node.Map<String,Serializable>getProperties()Get an immutable view of the job properties.SerializablegetProperty(String key)Get a job property by key.longgetProperty(String key, long defaultValue)Get a job property by key and convert it to a long value.CredentialsgetServerCredentials()StringgetServerInstanceName()Return a common name of the server instance that has accepted this job for execution.Job.StategetState()Return the job's life-cycle state.StringgetType()StringgetUUID()Return the job's UUID.inthashCode()SerializableputProperty(String key, Serializable value)Put a job property.booleanremove(Limit limit)Remove a previously appliedLimit.voidremoveJobListener(JobListener listener)Remove aJobListener.SerializableremoveProperty(String key)Remove a job property.voidsetClientLocale(Locale clientLocale)Set the client'sLocaleas some conversion produce local-specific results (e.g.voidsetServerCredentials(Credentials serverCredentials)Set credentials that jadice server uses to determine restrictions while executing a job.voidsetType(String type)Set the type of this job.abstract voidsubmit()Submit the job for execution at the server.StringtoString()protected abstract voidvalidateConfiguration()Validate the job and node graph configuration.booleanwaitForTermination(long timeout, TimeUnit unit)Wait and block until the job terminated or the given amount of time has passed.
-
-
-
Field Detail
-
PRODUCT_ID
public static final String PRODUCT_ID
The default product ID for jadice server.- See Also:
- Constant Field Values
-
COMPONENT_ID
public static final String COMPONENT_ID
The default component ID for Nodes.- See Also:
- Constant Field Values
-
node
protected Node node
The attached node.
-
state
protected transient Job.State state
The current state.
-
properties
protected Map<String,Serializable> properties
-
serverInstanceName
protected String serverInstanceName
-
-
Method Detail
-
addJobListener
public void addJobListener(JobListener listener)
Add aJobListenerto be notified of the job's progress and other job-related events.- Parameters:
listener- theJobListenerto be registered- See Also:
JobListener,JobListenerAdapter
-
removeJobListener
public void removeJobListener(JobListener listener)
Remove aJobListener.- Parameters:
listener- theJobListenerto be unregistered
-
getJobListeners
protected JobListener[] getJobListeners()
Get the registered listeners.- Returns:
- the registered listeners
-
attach
public abstract void attach(Node node)
Attach aNode. The attached node can be any node within the node graph (pipeline). At most one node (and therefore pipeline) may be attached.- Parameters:
node- theNodeto attach
-
finalize
@Deprecated protected void finalize() throws Throwable
Deprecated.
-
abort
public abstract void abort() throws JobExceptionAbort the job, i.e. cancel its execution.- Throws:
JobException- if the abortion failed
-
submit
public abstract void submit() throws JobExceptionSubmit the job for execution at the server.Caveat: If the thread which calls this methods gets interrupted it will remain in the "interrupted" state even though we don't throw an
InterruptedException.- Throws:
JobException- if the job could not be submitted
-
close
public abstract void close() throws JobExceptionClose the job and free up any resources held by it.- Specified by:
closein interfaceAutoCloseable- Throws:
JobException- if closing theJobfailed
-
validateConfiguration
protected abstract void validateConfiguration() throws ConfigurationExceptionValidate the job and node graph configuration.- Throws:
ConfigurationException- if some part of the configuration is invalid.
-
getNode
public Node getNode()
Return the attached node. Use theNodeTraversalto access more than this one node.- Returns:
- one of the nodes attached with this job
-
getUUID
public String getUUID()
Return the job's UUID.- Returns:
- the job's UUID
-
getState
public Job.State getState()
Return the job's life-cycle state.- Returns:
- the current state
-
waitForTermination
public boolean waitForTermination(long timeout, TimeUnit unit)Wait and block until the job terminated or the given amount of time has passed.- Parameters:
timeout- wait for at max that period. Wait indefinitely, if timeout ≤ 0.unit- the unit of the timeout. Must not benull.- Returns:
trueiff this method returned due to a timeout and this job has not terminated yet- Throws:
NullPointerException- ifunitisnull.- Since:
- jadice server 5.1.5.0
- See Also:
Job.State.isTerminalState()
-
getProperty
public Serializable getProperty(String key)
Get a job property by key.- Parameters:
key- property key- Returns:
- the property or null if the key was not found
-
getProperty
public long getProperty(String key, long defaultValue)
Get a job property by key and convert it to a long value. If the property isn't set or invalid, the specified default is used.- Parameters:
key- property keydefaultValue- default value to use if no property has been set- Returns:
- the property as long or the default value if the key was not registered before
-
putProperty
public Serializable putProperty(String key, Serializable value)
Put a job property.- Parameters:
key- property key.value- property value (caveat: must be serializable!)- Returns:
- previous value associated with specified key, or null if there was no mapping for key.
-
removeProperty
public Serializable removeProperty(String key)
Remove a job property.- Parameters:
key- property key- Returns:
- true iff the key was registered before
-
getProperties
public Map<String,Serializable> getProperties()
Get an immutable view of the job properties.- Returns:
- an unmodifiable view of the job properties
-
apply
public void apply(Limit limit)
Apply aLimitto this Job.This Limit will also be considered on all the individual
Nodes of this job, except to those nodes where:- This limit has the Action
Limit.WhenExceedAction.ABORT, - and another limit with the Action
Limit.WhenExceedAction.ABORTis applied on those particularNodes
- Parameters:
limit- theLimitto apply
- This limit has the Action
-
remove
public boolean remove(Limit limit)
Remove a previously appliedLimit. This call will have no effect, if the limit has not been applied previously.- Parameters:
limit- theLimitto remove.- Returns:
trueiff this limit was registered before.
-
getLimits
public Limits getLimits()
- Returns:
- All
Limits that have previously been applied to this job - Since:
- jadice server 5.5.0.0
-
getClientLocale
public Locale getClientLocale()
-
getClientVersion
public String getClientVersion()
- Returns:
- The version of the client side library
- See Also:
Package.getImplementationVersion()
-
setClientLocale
public void setClientLocale(Locale clientLocale)
Set the client'sLocaleas some conversion produce local-specific results (e.g. dates, messages...). Default: Client'sLocale.getDefault()- Parameters:
clientLocale-Localefor the client- Since:
- jadice server 4.1.1.0
-
getServerInstanceName
public String getServerInstanceName()
Return a common name of the server instance that has accepted this job for execution. This value is not reliable for jobs inJob.State.NEWandJob.State.SUBMITTED.- Returns:
- The server's instance name.
-
getServerCredentials
public Credentials getServerCredentials()
- Returns:
- Credentials that are used on server side
- Since:
- jadice server 4.3.1.0
-
setServerCredentials
public void setServerCredentials(Credentials serverCredentials)
Set credentials that jadice server uses to determine restrictions while executing a job.- Parameters:
serverCredentials- username and password- Since:
- jadice server 4.3.1.0
-
getType
public String getType()
- Returns:
- The type of this job
-
setType
public void setType(String type)
Set the type of this job. Job types are intended to distinguish between the types of different jobs, e.g. "email-conversion", "office-conversion" or other operational aspects.This parameter is intended to be equal among different instances of
Jobwhich have the same configuration but should be different if theJobs have a differnt purpose.- Parameters:
type- The type of this job
-
-