java.lang.Object
com.northconcepts.datapipeline.job.Job
All Implemented Interfaces:
IJob, Runnable

public class Job extends Object implements IJob
Used to run, manage, and track pipelines.
  • Constructor Details

  • Method Details

    • addJobLifecycleListener

      public static void addJobLifecycleListener(JobLifecycleListener listener)
    • removeJobLifecycleListener

      public static void removeJobLifecycleListener(JobLifecycleListener listener)
    • run

      public static Job run(DataReader reader, DataWriter writer)
      Transfers all records from the reader to the writer in a new job on the current thread and returns the finished job; a failure is thrown as a DataException.
    • run

      public static Job run(DataReader reader, DataWriter writer, JobCallback<DataReader,DataWriter> callback)
      Runs a new transfer job on the current thread, reporting progress and the outcome to the callback; a failure is only thrown if the callback's onFailure rethrows it.
    • runAsync

      public static Job runAsync(DataReader reader, DataWriter writer)
      Starts a job on a new thread that transfers all records from the reader to the writer; returns the job immediately.
    • runAsync

      public static Job runAsync(DataReader reader, DataWriter writer, JobCallback<DataReader,DataWriter> callback)
      Starts a transfer job on a new thread that reports its progress and outcome to the callback; returns the job immediately.
    • getCurrent

      public static Job getCurrent()
      Returns the job currently running in this thread.
    • getAll

      public static List<Job> getAll()
      Returns all the live jobs in the JVM/classloader.
    • getJobCount

      public static int getJobCount()
      Returns the current number of live jobs in the JVM/classloader.
    • getParent

      public Job getParent()
      Returns the thread-local job that ran this one while this job is running.
      Specified by:
      getParent in interface IJob
    • getChild

      public Job getChild()
      Returns the thread-local child job of this one while this job is running.
      Specified by:
      getChild in interface IJob
    • getId

      public long getId()
      Returns the unique (sequential) ID of this job (within this JVM/classloader).
    • getUuid

      public UUID getUuid()
      Returns the universally unique identifier (UUID) for this job.
      Specified by:
      getUuid in interface IJob
    • getName

      public String getName()
      Returns the name assigned to this job or its default name if one was not assigned.
      Specified by:
      getName in interface IJob
    • setName

      public Job setName(String name)
      Assigns a new name to this job.
      Specified by:
      setName in interface IJob
    • getReader

      public DataReader getReader()
      Returns the reader supplied to this job.
    • getReader

      public <T extends DataReader> T getReader(Class<T> type)
      Returns the first reader of the supplied type from the read pipeline.
    • getWriter

      public DataWriter getWriter()
      Returns the writer supplied to this job.
    • getWriter

      public <T extends DataWriter> T getWriter(Class<T> type)
      Returns the first writer of the supplied type from the write pipeline.
    • getReaders

      public List<DataReader> getReaders()
      Returns the read pipeline — the chain of readers records pass through, starting with the root instance and ending with the reader passed to this job (and returned by getReader()).
    • getWriters

      public List<DataWriter> getWriters()
      Returns the write pipeline — the chain of writers records pass through, starting with the writer passed to this job and returned by getWriter() and ending with the root instance.
    • getCreatedOn

      public Date getCreatedOn()
      Returns the time this job instance was created.
      Specified by:
      getCreatedOn in interface IJob
    • getStartedOn

      public Date getStartedOn()
      Returns the time this job instance started running.
      Specified by:
      getStartedOn in interface IJob
    • getCancelledOn

      public Date getCancelledOn()
      Returns the time this job instance was cancelled.
      Specified by:
      getCancelledOn in interface IJob
    • isCancelled

      public boolean isCancelled()
      Returns true if this job was cancelled.
      Specified by:
      isCancelled in interface IJob
    • getPausedOn

      public Date getPausedOn()
      Returns the time this job was paused or null if this job is not currently paused.
      Specified by:
      getPausedOn in interface IJob
    • isPaused

      public boolean isPaused()
      Returns true if this job is currently paused.
      Specified by:
      isPaused in interface IJob
    • getFinishedOn

      public Date getFinishedOn()
      Returns the time this job finished running.
      Specified by:
      getFinishedOn in interface IJob
    • isFinished

      public boolean isFinished()
      Returns true if this job has finished running.
      Specified by:
      isFinished in interface IJob
    • getException

      public DataException getException()
      Returns the last exception thrown while running.
      Specified by:
      getException in interface IJob
    • isFailed

      public boolean isFailed()
      Returns true if this job has completed unsuccessfully.
      Specified by:
      isFailed in interface IJob
    • getRunThread

      public Thread getRunThread()
      Returns the thread currently executing this job or null if the job is not running.
      Specified by:
      getRunThread in interface IJob
    • isRunning

      public boolean isRunning()
      Returns true if this job is currently running.
      Specified by:
      isRunning in interface IJob
    • getRunningTime

      public long getRunningTime()
      Returns the number of milliseconds this job was (or has been) running for or zero (0) if it hasn't yet started running.
      Specified by:
      getRunningTime in interface IJob
    • getRunningTimeAsString

      public String getRunningTimeAsString()
      Returns the time this job was (or has been) running in long form as a human readable string (2 Years, 1 Second, 12 Millisecond) or null if it hasn't yet started running.
      Specified by:
      getRunningTimeAsString in interface IJob
    • getRunningTimeAsString

      public String getRunningTimeAsString(boolean shortForm)
      Returns the time this job was (or has been) running as a human readable string in long form (2 Years, 1 Second, 12 Millisecond) or short form (2y 1s 12ms) or null if it hasn't yet started running.
      Specified by:
      getRunningTimeAsString in interface IJob
    • getRecordsTransferred

      public long getRecordsTransferred()
      Returns the number of records sent from the supplied reader to the supplied writer.
    • getLastRecord

      public Record getLastRecord()
      Returns the most recent record seen by this job while it is running or null.
    • getCallback

      public JobCallback<DataReader,DataWriter> getCallback()
      Returns the callback notified of this job's progress and outcome (defaults to JobCallback.NULL).
    • hasCallback

      public boolean hasCallback()
      Returns true if a callback other than the default JobCallback.NULL was assigned.
    • setCallback

      public Job setCallback(JobCallback<DataReader,DataWriter> callback)
      Sets the callback notified of this job's progress and outcome (null restores JobCallback.NULL).
    • pause

      public Job pause()
      Description copied from interface: IJob
      Asks this job to pause at its next pause check (between records for a Job) until IJob.resume() is called.
      Specified by:
      pause in interface IJob
    • resume

      public Job resume()
      Description copied from interface: IJob
      Lets a paused job continue; does nothing if it is not paused.
      Specified by:
      resume in interface IJob
    • cancel

      public Job cancel()
      Description copied from interface: IJob
      Interrupts the run thread and cancels the child job; does nothing unless this job is running and not yet cancelled.
      Specified by:
      cancel in interface IJob
    • onStart

      protected void onStart()
      Called when this job starts.
    • onFinish

      protected void onFinish()
      Called when this job finishes.
    • onPause

      protected void onPause()
      Called when this job is paused.
    • setLogWriter

      public Job setLogWriter(DataWriter logWriter)
      Sets the writer that receives this job's statistics, one record per pipeline endpoint, when the job finishes and after each log() request; the job opens and closes it.
    • getLogWriter

      public DataWriter getLogWriter()
      Returns the writer that receives this job's statistics records or null if none was set.
    • isAutoCloseLogWriter

      public boolean isAutoCloseLogWriter()
    • setAutoCloseLogWriter

      public Job setAutoCloseLogWriter(boolean autoCloseLogWriter)
    • log

      public Job log()
      Requests that this job's statistics be written to the log writer after the next record is transferred.
    • run

      public void run()
      Executes this job in the current thread. This method blocks until the transfer either completes successfully or fails for any reason.
      Specified by:
      run in interface IJob
      Specified by:
      run in interface Runnable
    • runAsync

      public Job runAsync()
      Executes this job in a new thread. This method does not block.
      Specified by:
      runAsync in interface IJob
    • waitUntilStarted

      public Job waitUntilStarted() throws InterruptedException
      Waits for this job to start.
      Specified by:
      waitUntilStarted in interface IJob
      Returns:
      Throws:
      InterruptedException
    • waitUntilStarted

      public Job waitUntilStarted(long timeout) throws InterruptedException
      Waits up to timeout milliseconds for this job to start or throws InterruptedException.
      Specified by:
      waitUntilStarted in interface IJob
      Returns:
      Throws:
      InterruptedException
    • waitUntilFinished

      public Job waitUntilFinished() throws InterruptedException
      Waits for this job to complete.
      Specified by:
      waitUntilFinished in interface IJob
      Returns:
      Throws:
      InterruptedException
    • waitUntilFinished

      public Job waitUntilFinished(long timeout) throws InterruptedException
      Waits up to timeout milliseconds for this job to complete or throws InterruptedException.
      Specified by:
      waitUntilFinished in interface IJob
      Returns:
      Throws:
      InterruptedException
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • toDebugString

      public String toDebugString()
    • toString

      public String toString()
      Overrides:
      toString in class Object