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) ofNode
s 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.StreamOutputNode
This 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.State
enumeration. 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 class
Job.State
The different states a job can have.
-
Field Summary
Fields Modifier and Type Field Description static String
COMPONENT_ID
The default component ID for Nodes.protected Node
node
The attached node.static String
PRODUCT_ID
The default product ID for jadice server.protected Map<String,Serializable>
properties
protected String
serverInstanceName
protected Job.State
state
The 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 void
abort()
Abort the job, i.e.void
addJobListener(JobListener listener)
Add aJobListener
to be notified of the job's progress and other job-related events.void
apply(Limit limit)
Apply aLimit
to this Job.abstract void
attach(Node node)
Attach aNode
.abstract void
close()
Close the job and free up any resources held by it.boolean
equals(Object obj)
protected void
finalize()
Deprecated.Locale
getClientLocale()
String
getClientVersion()
protected JobListener[]
getJobListeners()
Get the registered listeners.Limits
getLimits()
Node
getNode()
Return the attached node.Map<String,Serializable>
getProperties()
Get an immutable view of the job properties.Serializable
getProperty(String key)
Get a job property by key.long
getProperty(String key, long defaultValue)
Get a job property by key and convert it to a long value.Credentials
getServerCredentials()
String
getServerInstanceName()
Return a common name of the server instance that has accepted this job for execution.Job.State
getState()
Return the job's life-cycle state.String
getType()
String
getUUID()
Return the job's UUID.int
hashCode()
Serializable
putProperty(String key, Serializable value)
Put a job property.boolean
remove(Limit limit)
Remove a previously appliedLimit
.void
removeJobListener(JobListener listener)
Remove aJobListener
.Serializable
removeProperty(String key)
Remove a job property.void
setClientLocale(Locale clientLocale)
Set the client'sLocale
as some conversion produce local-specific results (e.g.void
setServerCredentials(Credentials serverCredentials)
Set credentials that jadice server uses to determine restrictions while executing a job.void
setType(String type)
Set the type of this job.abstract void
submit()
Submit the job for execution at the server.String
toString()
protected abstract void
validateConfiguration()
Validate the job and node graph configuration.boolean
waitForTermination(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 aJobListener
to be notified of the job's progress and other job-related events.- Parameters:
listener
- theJobListener
to be registered- See Also:
JobListener
,JobListenerAdapter
-
removeJobListener
public void removeJobListener(JobListener listener)
Remove aJobListener
.- Parameters:
listener
- theJobListener
to 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
- theNode
to attach
-
finalize
@Deprecated protected void finalize() throws Throwable
Deprecated.
-
abort
public abstract void abort() throws JobException
Abort the job, i.e. cancel its execution.- Throws:
JobException
- if the abortion failed
-
submit
public abstract void submit() throws JobException
Submit 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 JobException
Close the job and free up any resources held by it.- Specified by:
close
in interfaceAutoCloseable
- Throws:
JobException
- if closing theJob
failed
-
validateConfiguration
protected abstract void validateConfiguration() throws ConfigurationException
Validate 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 theNodeTraversal
to 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:
true
iff this method returned due to a timeout and this job has not terminated yet- Throws:
NullPointerException
- ifunit
isnull
.- 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 aLimit
to this Job.This Limit will also be considered on all the individual
Node
s of this job, except to those nodes where:- This limit has the Action
Limit.WhenExceedAction.ABORT
, - and another limit with the Action
Limit.WhenExceedAction.ABORT
is applied on those particularNode
s
- Parameters:
limit
- theLimit
to 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
- theLimit
to remove.- Returns:
true
iff this limit was registered before.
-
getLimits
public Limits getLimits()
- Returns:
- All
Limit
s 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'sLocale
as some conversion produce local-specific results (e.g. dates, messages...). Default: Client'sLocale.getDefault()
- Parameters:
clientLocale
-Locale
for 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.NEW
andJob.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
Job
which have the same configuration but should be different if theJob
s have a differnt purpose.- Parameters:
type
- The type of this job
-
-