Class AbstractJob
java.lang.Object
com.northconcepts.datapipeline.job.AbstractJob
- Direct Known Subclasses:
RunnableJobAdapter
Used to run, pause, and cancel Runnables.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final List<AbstractJob> protected static final ThreadLocal<AbstractJob> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncancel()Interrupts the run thread and cancels the child job; does nothing unless this job is running and not yet cancelled.protected Objectclone()static List<AbstractJob> getAll()Returns all theAbstractJobs currently running in the JVM/classloader, not includingJobs.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 AbstractJobReturns theAbstractJobcurrently running in this thread ornullif there is none.Returns the last exception thrown while running.Returns the time this job finished running.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.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.protected voidClears the thread's interrupted flag and throwsInterruptedExceptionif this job or its parent was cancelled.protected voidBlocks while this job is paused, callingonPause()before andonResume()after the wait.booleanbooleanReturnstrueif this job was cancelled.booleanisCancelled(Throwable exception) Returnstrueif this exception is due to this job being 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()protected voidCalled on the run thread afterrunImpl()throws; seegetException().protected voidonFinish()Called on the run thread afteronSuccess()oronFailure(), even if they throw.protected voidonPause()Called on the run thread when it pauses inhandlePause().protected voidonResume()Called on the run thread when it resumes inhandlePause().protected voidonStart()Called on the run thread when this job starts, beforerunImpl().protected voidCalled on the run thread afterrunImpl()completes without throwing.pause()Asks this job to pause at its next pause check (between records for aJob) untilIJob.resume()is called.resume()Lets a paused job continue; does nothing if it is not paused.voidrun()Executes this job in the current thread.runAsync()Executes this job in a new thread.protected abstract voidrunImpl()Performs this job's work on the run thread; callhandlePause()andhandleCancel()regularly so pause and cancel requests take effect.setAutoCloseLogWriter(boolean autoCloseLogWriter) setLogWriter(DataWriter logWriter) Assigns a new name to this job.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.
-
Field Details
-
threadLocal
-
jobs
-
-
Constructor Details
-
AbstractJob
public AbstractJob()
-
-
Method Details
-
getCurrent
Returns theAbstractJobcurrently running in this thread ornullif there is none. -
getAll
Returns all theAbstractJobs currently running in the JVM/classloader, not includingJobs. -
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. -
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. -
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
-
isCancelled
Returnstrueif this exception is due to this job being cancelled. -
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
-
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 on the run thread when this job starts, beforerunImpl(). -
onFinish
protected void onFinish()Called on the run thread afteronSuccess()oronFailure(), even if they throw. -
onPause
protected void onPause()Called on the run thread when it pauses inhandlePause(). -
onResume
protected void onResume()Called on the run thread when it resumes inhandlePause(). -
onSuccess
protected void onSuccess()Called on the run thread afterrunImpl()completes without throwing. -
onFailure
protected void onFailure()Called on the run thread afterrunImpl()throws; seegetException(). -
setLogWriter
-
getLogWriter
-
isAutoCloseLogWriter
public boolean isAutoCloseLogWriter() -
setAutoCloseLogWriter
-
log
-
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. -
runImpl
Performs this job's work on the run thread; callhandlePause()andhandleCancel()regularly so pause and cancel requests take effect.- Throws:
Throwable
-
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
-
handlePause
Blocks while this job is paused, callingonPause()before andonResume()after the wait.- Throws:
InterruptedException
-
handleCancel
Clears the thread's interrupted flag and throwsInterruptedExceptionif this job or its parent was cancelled.- Throws:
InterruptedException
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
toDebugString
-