Class Job
java.lang.Object
com.northconcepts.datapipeline.job.Job
Used to run, manage, and track pipelines.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddJobLifecycleListener(JobLifecycleListener listener) cancel()Interrupts the run thread and cancels the child job; does nothing unless this job is running and not yet cancelled.protected Objectclone()getAll()Returns all the live jobs in the JVM/classloader.Returns the callback notified of this job's progress and outcome (defaults toJobCallback.NULL).Returns the time this job instance was cancelled.getChild()Returns the thread-local child job of this one while this job is running.Returns the time this job instance was created.static JobReturns the job currently running in this thread.Returns the last exception thrown while running.Returns the time this job finished running.longgetId()Returns the unique (sequential) ID of this job (within this JVM/classloader).static intReturns the current number of live jobs in the JVM/classloader.Returns the most recent record seen by this job while it is running ornull.Returns the writer that receives this job's statistics records ornullif none was set.getName()Returns the name assigned to this job or its default name if one was not assigned.Returns the thread-local job that ran this one while this job is running.Returns the time this job was paused ornullif this job is not currently paused.Returns the reader supplied to this job.<T extends DataReader>
TReturns the first reader of the supplied type from the read pipeline.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 bygetReader()).longReturns the number of records sent from the supplied reader to the supplied writer.longReturns the number of milliseconds this job was (or has been) running for or zero (0) if it hasn't yet started running.Returns the time this job was (or has been) running in long form as a human readable string (2 Years, 1 Second, 12 Millisecond) ornullif it hasn't yet started running.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) ornullif it hasn't yet started running.Returns the thread currently executing this job ornullif the job is not running.Returns the time this job instance started running.getUuid()Returns the universally unique identifier (UUID) for this job.Returns the writer supplied to this job.<T extends DataWriter>
TReturns the first writer of the supplied type from the write pipeline.Returns the write pipeline — the chain of writers records pass through, starting with the writer passed to this job and returned bygetWriter()and ending with the root instance.booleanReturns true if a callback other than the defaultJobCallback.NULLwas assigned.booleanbooleanReturnstrueif this job was cancelled.booleanisFailed()Returnstrueif this job has completed unsuccessfully.booleanReturnstrueif this job has finished running.booleanisPaused()Returnstrueif this job is currently paused.booleanReturnstrueif this job is currently running.log()Requests that this job's statistics be written to the log writer after the next record is transferred.protected voidonFinish()Called when this job finishes.protected voidonPause()Called when this job is paused.protected voidonStart()Called when this job starts.pause()Asks this job to pause at its next pause check (between records for aJob) untilIJob.resume()is called.static voidresume()Lets a paused job continue; does nothing if it is not paused.voidrun()Executes this job in the current thread.static Jobrun(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 aDataException.static Jobrun(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'sonFailurerethrows it.runAsync()Executes this job in a new thread.static JobrunAsync(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.static JobrunAsync(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.setAutoCloseLogWriter(boolean autoCloseLogWriter) setCallback(JobCallback<DataReader, DataWriter> callback) Sets the callback notified of this job's progress and outcome (nullrestoresJobCallback.NULL).setLogWriter(DataWriter logWriter) Sets the writer that receives this job's statistics, one record per pipeline endpoint, when the job finishes and after eachlog()request; the job opens and closes it.Assigns a new name to this job.toString()Waits for this job to complete.waitUntilFinished(long timeout) Waits up totimeoutmilliseconds for this job to complete or throwsInterruptedException.Waits for this job to start.waitUntilStarted(long timeout) Waits up totimeoutmilliseconds for this job to start or throwsInterruptedException.
-
Constructor Details
-
Job
-
-
Method Details
-
addJobLifecycleListener
-
removeJobLifecycleListener
-
run
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 aDataException. -
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'sonFailurerethrows it. -
runAsync
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
Returns the job currently running in this thread. -
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
Returns the thread-local job that ran this one while this job is running. -
getChild
Returns the thread-local child job of this one while this job is running. -
getId
public long getId()Returns the unique (sequential) ID of this job (within this JVM/classloader). -
getUuid
Returns the universally unique identifier (UUID) for this job. -
getName
Returns the name assigned to this job or its default name if one was not assigned. -
setName
Assigns a new name to this job. -
getReader
Returns the reader supplied to this job. -
getReader
Returns the first reader of the supplied type from the read pipeline. -
getWriter
Returns the writer supplied to this job. -
getWriter
Returns the first writer of the supplied type from the write pipeline. -
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 bygetReader()). -
getWriters
Returns the write pipeline — the chain of writers records pass through, starting with the writer passed to this job and returned bygetWriter()and ending with the root instance. -
getCreatedOn
Returns the time this job instance was created.- Specified by:
getCreatedOnin interfaceIJob
-
getStartedOn
Returns the time this job instance started running.- Specified by:
getStartedOnin interfaceIJob
-
getCancelledOn
Returns the time this job instance was cancelled.- Specified by:
getCancelledOnin interfaceIJob
-
isCancelled
public boolean isCancelled()Returnstrueif this job was cancelled.- Specified by:
isCancelledin interfaceIJob
-
getPausedOn
Returns the time this job was paused ornullif this job is not currently paused.- Specified by:
getPausedOnin interfaceIJob
-
isPaused
public boolean isPaused()Returnstrueif this job is currently paused. -
getFinishedOn
Returns the time this job finished running.- Specified by:
getFinishedOnin interfaceIJob
-
isFinished
public boolean isFinished()Returnstrueif this job has finished running.- Specified by:
isFinishedin interfaceIJob
-
getException
Returns the last exception thrown while running.- Specified by:
getExceptionin interfaceIJob
-
isFailed
public boolean isFailed()Returnstrueif this job has completed unsuccessfully. -
getRunThread
Returns the thread currently executing this job ornullif the job is not running.- Specified by:
getRunThreadin interfaceIJob
-
isRunning
public boolean isRunning()Returnstrueif this job is currently running. -
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:
getRunningTimein interfaceIJob
-
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) ornullif it hasn't yet started running.- Specified by:
getRunningTimeAsStringin interfaceIJob
-
getRunningTimeAsString
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) ornullif it hasn't yet started running.- Specified by:
getRunningTimeAsStringin interfaceIJob
-
getRecordsTransferred
public long getRecordsTransferred()Returns the number of records sent from the supplied reader to the supplied writer. -
getLastRecord
Returns the most recent record seen by this job while it is running ornull. -
getCallback
Returns the callback notified of this job's progress and outcome (defaults toJobCallback.NULL). -
hasCallback
public boolean hasCallback()Returns true if a callback other than the defaultJobCallback.NULLwas assigned. -
setCallback
Sets the callback notified of this job's progress and outcome (nullrestoresJobCallback.NULL). -
pause
Description copied from interface:IJobAsks this job to pause at its next pause check (between records for aJob) untilIJob.resume()is called. -
resume
Description copied from interface:IJobLets a paused job continue; does nothing if it is not paused. -
cancel
Description copied from interface:IJobInterrupts the run thread and cancels the child job; does nothing unless this job is running and not yet cancelled. -
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
Sets the writer that receives this job's statistics, one record per pipeline endpoint, when the job finishes and after eachlog()request; the job opens and closes it. -
getLogWriter
Returns the writer that receives this job's statistics records ornullif none was set. -
isAutoCloseLogWriter
public boolean isAutoCloseLogWriter() -
setAutoCloseLogWriter
-
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. -
runAsync
Executes this job in a new thread. This method does not block. -
waitUntilStarted
Waits for this job to start.- Specified by:
waitUntilStartedin interfaceIJob- Returns:
- Throws:
InterruptedException
-
waitUntilStarted
Waits up totimeoutmilliseconds for this job to start or throwsInterruptedException.- Specified by:
waitUntilStartedin interfaceIJob- Returns:
- Throws:
InterruptedException
-
waitUntilFinished
Waits for this job to complete.- Specified by:
waitUntilFinishedin interfaceIJob- Returns:
- Throws:
InterruptedException
-
waitUntilFinished
Waits up totimeoutmilliseconds for this job to complete or throwsInterruptedException.- Specified by:
waitUntilFinishedin interfaceIJob- Returns:
- Throws:
InterruptedException
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
toDebugString
-
toString
-