Class 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) of Nodes 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.StreamInputNodecom.levigo.jadice.server.libreoffice.server.LibreOfficeConversionNodecom.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 the com.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 a JobListener.

    • Constructor Detail

      • Job

        public Job()
    • Method Detail

      • getJobListeners

        protected JobListener[] getJobListeners()
        Get the registered listeners.
        Returns:
        the registered listeners
      • attach

        public abstract void attach​(Node node)
        Attach a Node. The attached node can be any node within the node graph (pipeline). At most one node (and therefore pipeline) may be attached.
        Parameters:
        node - the Node to attach
      • 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
      • 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 the NodeTraversal 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 be null.
        Returns:
        true iff this method returned due to a timeout and this job has not terminated yet
        Throws:
        NullPointerException - if unit is null.
        Since:
        jadice server 5.1.5.0
        See Also:
        Job.State.isTerminalState()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • 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 key
        defaultValue - 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
      • remove

        public boolean remove​(Limit limit)
        Remove a previously applied Limit. This call will have no effect, if the limit has not been applied previously.
        Parameters:
        limit - the Limit to remove.
        Returns:
        true iff 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()
      • setClientLocale

        public void setClientLocale​(Locale clientLocale)
        Set the client's Locale as some conversion produce local-specific results (e.g. dates, messages...). Default: Client's Locale.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 in Job.State.NEW and Job.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 the Jobs have a differnt purpose.

        Parameters:
        type - The type of this job