public abstract class AbstractJob extends Object implements IJob
Modifier and Type | Field and Description |
---|---|
protected static List<AbstractJob> |
jobs |
protected static ThreadLocal<AbstractJob> |
threadLocal |
Constructor and Description |
---|
AbstractJob() |
Modifier and Type | Method and Description |
---|---|
AbstractJob |
cancel() |
protected Object |
clone() |
static List<AbstractJob> |
getAll() |
Date |
getCancelledOn()
Returns the time this job instance was cancelled.
|
AbstractJob |
getChild()
Returns the thread-local child job of this one while this job is running.
|
Date |
getCreatedOn()
Returns the time this job instance was created.
|
static AbstractJob |
getCurrent() |
DataException |
getException()
Returns the last exception thrown while running.
|
Date |
getFinishedOn()
Returns the time this job finished running.
|
DataWriter |
getLogWriter() |
String |
getName()
Returns the name assigned to this job or its default name if one was not assigned.
|
AbstractJob |
getParent()
Returns the thread-local job that ran this one while this job is running.
|
Date |
getPausedOn()
Returns the time this job was paused or
null if this job is not currently paused. |
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.
|
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. |
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. |
Thread |
getRunThread()
Returns the thread currently executing this job or
null if the job is not running. |
Date |
getStartedOn()
Returns the time this job instance started running.
|
UUID |
getUuid()
Returns the universally unique identifier (UUID) for this job.
|
protected void |
handleCancel() |
protected void |
handlePause() |
boolean |
isAutoCloseLogWriter() |
boolean |
isCancelled()
Returns
true if this job was cancelled. |
boolean |
isCancelled(Throwable exception)
Returns
true if this exception is due to this job being cancelled. |
boolean |
isFailed()
Returns
true if this job has completed unsuccessfully. |
boolean |
isFinished()
Returns
true if this job has finished running. |
boolean |
isPaused()
Returns
true if this job is currently paused. |
boolean |
isRunning()
Returns
true if this job is currently running. |
AbstractJob |
log() |
protected void |
onFailure() |
protected void |
onFinish() |
protected void |
onPause() |
protected void |
onResume() |
protected void |
onStart() |
protected void |
onSuccess() |
AbstractJob |
pause() |
AbstractJob |
resume() |
void |
run()
Executes this job in the current thread.
|
AbstractJob |
runAsync()
Executes this job in a new thread.
|
protected abstract void |
runImpl() |
AbstractJob |
setAutoCloseLogWriter(boolean autoCloseLogWriter) |
AbstractJob |
setLogWriter(DataWriter logWriter) |
AbstractJob |
setName(String name)
Assigns a new name to this job.
|
String |
toDebugString() |
AbstractJob |
waitUntilFinished()
Waits for this job to complete.
|
AbstractJob |
waitUntilFinished(long timeout)
Waits up to
timeout milliseconds for this job to complete or throws InterruptedException . |
AbstractJob |
waitUntilStarted()
Waits for this job to start.
|
AbstractJob |
waitUntilStarted(long timeout)
Waits up to
timeout milliseconds for this job to start or throws InterruptedException . |
protected static final ThreadLocal<AbstractJob> threadLocal
protected static final List<AbstractJob> jobs
public static AbstractJob getCurrent()
public static List<AbstractJob> getAll()
public AbstractJob getParent()
public AbstractJob getChild()
public UUID getUuid()
public String getName()
public AbstractJob setName(String name)
public Date getCreatedOn()
getCreatedOn
in interface IJob
public Date getStartedOn()
getStartedOn
in interface IJob
public Date getCancelledOn()
getCancelledOn
in interface IJob
public boolean isCancelled()
true
if this job was cancelled.isCancelled
in interface IJob
public boolean isCancelled(Throwable exception)
true
if this exception is due to this job being cancelled.public Date getPausedOn()
null
if this job is not currently paused.getPausedOn
in interface IJob
public boolean isPaused()
true
if this job is currently paused.public Date getFinishedOn()
getFinishedOn
in interface IJob
public boolean isFinished()
true
if this job has finished running.isFinished
in interface IJob
public DataException getException()
getException
in interface IJob
public boolean isFailed()
true
if this job has completed unsuccessfully.public Thread getRunThread()
null
if the job is not running.getRunThread
in interface IJob
public boolean isRunning()
true
if this job is currently running.public long getRunningTime()
getRunningTime
in interface IJob
public String getRunningTimeAsString()
null
if it hasn't yet started running.getRunningTimeAsString
in interface IJob
public String getRunningTimeAsString(boolean shortForm)
null
if it hasn't yet started running.getRunningTimeAsString
in interface IJob
public AbstractJob pause()
public AbstractJob resume()
public AbstractJob cancel()
protected void onStart()
protected void onFinish()
protected void onPause()
protected void onResume()
protected void onSuccess()
protected void onFailure()
public AbstractJob setLogWriter(DataWriter logWriter)
public DataWriter getLogWriter()
public boolean isAutoCloseLogWriter()
public AbstractJob setAutoCloseLogWriter(boolean autoCloseLogWriter)
public AbstractJob log()
public void run()
public AbstractJob runAsync()
public AbstractJob waitUntilStarted() throws InterruptedException
waitUntilStarted
in interface IJob
InterruptedException
public AbstractJob waitUntilStarted(long timeout) throws InterruptedException
timeout
milliseconds for this job to start or throws InterruptedException
.waitUntilStarted
in interface IJob
InterruptedException
public AbstractJob waitUntilFinished() throws InterruptedException
waitUntilFinished
in interface IJob
InterruptedException
public AbstractJob waitUntilFinished(long timeout) throws InterruptedException
timeout
milliseconds for this job to complete or throws InterruptedException
.waitUntilFinished
in interface IJob
InterruptedException
protected void handlePause() throws InterruptedException
InterruptedException
protected void handleCancel() throws InterruptedException
InterruptedException
protected Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public String toDebugString()
Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.