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) of
Node
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:
StreamInputNode
⇒
LibreOfficeConversionNode
⇒
StreamOutputNode
This pipeline accepts a data stream (in OpenOffice Writer format) presented via the
StreamInputNode
, applies the conversion and makes the
result accessible through the 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 a JobListener
.
Modifier and Type | Class and Description |
---|---|
static class |
Job.State
The different states a job can have.
|
Modifier and Type | Field and 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 and Description |
---|
Job() |
Modifier and Type | Method and Description |
---|---|
abstract void |
abort()
Abort the job, i.e.
|
void |
addJobListener(JobListener listener)
Add a
JobListener to be notified of the job's progress and other job-related events. |
void |
apply(Limit limit)
Apply a
Limit to this Job. |
abstract void |
attach(Node node)
Attach a
Node . |
abstract void |
close()
Close the job and free up any resources held by it.
|
boolean |
equals(Object obj) |
protected void |
finalize() |
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 applied
Limit . |
void |
removeJobListener(JobListener listener)
Remove a
JobListener . |
Serializable |
removeProperty(String key)
Remove a job property.
|
void |
setClientLocale(Locale clientLocale)
Set the client's
Locale 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)
Deprecated.
Use
waitForTermination(long, TimeUnit) instead |
boolean |
waitForTermination(long timeout,
TimeUnit unit)
Wait and block until the job terminated or the given amount of time has passed.
|
public static final String PRODUCT_ID
public static final String COMPONENT_ID
protected Node node
protected transient Job.State state
protected Map<String,Serializable> properties
protected String serverInstanceName
public void addJobListener(JobListener listener)
JobListener
to be notified of the job's progress and other job-related events.listener
- JobListener
,
JobListenerAdapter
public void removeJobListener(JobListener listener)
JobListener
.listener
- protected JobListener[] getJobListeners()
public abstract void attach(Node node)
Node
. The attached node can be any node within the node graph (pipeline). At
most one node (and therefore pipeline) may be attached.node
- protected void finalize() throws Throwable
public abstract void abort() throws JobException
JobException
public abstract void submit() throws JobException
Caveat: If the thread which calls this methods gets interrupted
it will remain in the "interrupted"e; even though we don't thrown an
InterruptedException
.
JobException
- if the job could not be submittedpublic abstract void close() throws JobException
close
in interface AutoCloseable
JobException
protected abstract void validateConfiguration() throws ConfigurationException
ConfigurationException
- if some part of the configuration is invalid.public Node getNode()
NodeTraversal
to access more than this one node.public String getUUID()
public Job.State getState()
@Deprecated public boolean waitForTermination(long timeout)
waitForTermination(long, TimeUnit)
insteadtimeout
- wait for at max timeout ms. Wait indefinitely, if timeout ≤ 0.true
iff this method returned due to a timeout and this job has not terminated yetJob.State.isTerminalState()
public boolean waitForTermination(long timeout, TimeUnit unit)
timeout
- wait for at max that period. Wait indefinitely, if timeout ≤ 0.unit
- the unit of the timeout. Must not be null
.true
iff this method returned due to a timeout and this job has not terminated yetNullPointerException
- if unit
is null
.Job.State.isTerminalState()
public Serializable getProperty(String key)
key
- public long getProperty(String key, long defaultValue)
key
- public Serializable putProperty(String key, Serializable value)
key
- property key.value
- property value (caveat: must be serializable!)public Serializable removeProperty(String key)
key
- public Map<String,Serializable> getProperties()
public void apply(Limit limit)
Apply a Limit
to this Job.
This Limit will also be considered on all the individual Node
s of this job, except to
those nodes where:
Limit.WhenExceedAction.ABORT
,Limit.WhenExceedAction.ABORT
is applied on those
particular Node
slimit
- the Limit
to applypublic boolean remove(Limit limit)
Limit
. This call will have no effect, if the limit has not
been applied previously.limit
- the Limit
to remove.true
iff this limit was registered before.public Limits getLimits()
Limit
s that have previously been applied to this jobpublic Locale getClientLocale()
public String getClientVersion()
Package.getImplementationVersion()
public void setClientLocale(Locale clientLocale)
Locale
as some conversion produce local-specific results (e.g. dates,
messages...). Default: Client's Locale.getDefault()
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 in Job.State.NEW
and Job.State.SUBMITTED
.
public Credentials getServerCredentials()
public void setServerCredentials(Credentials serverCredentials)
serverCredentials
- username and passwordpublic String getType()
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 the Job
s have a differnt purpose.
type
- The type of this jobCopyright © 2017 levigo holding gmbh. All rights reserved.