Class AssertionErrorJobContext
- All Implemented Interfaces:
JobContext
JobContext
where
all methods do fail with a
AssertionError
.
You may want to subclass this class instead of
implementing JobContext
directly
to make your subclass cope with new methods
in JobContext
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Indicates, that the job has proceeded.void
incrementProgress
(int delta) Indicates, that the job has proceeded.Returns the duration the job has been requested to defer by its context.void
setCompleteness
(double completeness) Indicates the current completeness of the job.void
setMessage
(String message) Indicates a message describing the current status of the job.void
sleepAndStopIfRequested
(Duration duration) Sleeps for the specified duration.void
Checks, whether the job has been requested to stop.boolean
Returns whether this context can process information transferred byJobContext.setCompleteness(double)
.boolean
Returns whether this context can process information transferred byJobContext.setMessage(String)
.boolean
Returns whether this context can process information transferred byJobContext.incrementProgress()
andJobContext.incrementProgress(int)
.
-
Constructor Details
-
AssertionErrorJobContext
public AssertionErrorJobContext()
-
-
Method Details
-
stopIfRequested
public void stopIfRequested()Description copied from interface:JobContext
Checks, whether the job has been requested to stop. The job should call this method in reasonably short intervals. If throws aJobStop
, the job should stop gracefully as soon as possible, but all resources held should be released.The job may call
JobContext.deferOrStopIfRequested(JobContext)
instead.- Specified by:
stopIfRequested
in interfaceJobContext
-
requestsDeferral
Description copied from interface:JobContext
Returns the duration the job has been requested to defer by its context. This method is considered bydeferOrStopIfRequested
.In general the job should not call this method, but
deferOrStopIfRequested
.The default implementation returns
zero
.- Specified by:
requestsDeferral
in interfaceJobContext
-
sleepAndStopIfRequested
Description copied from interface:JobContext
Sleeps for the specified duration. In contrast toJobContext.deferOrStopIfRequested(JobContext)
this method actually waits for the specified amount of time. In contrast toThread.sleep
it aborts prematurely by throwing aJobStop
, if the the job has been requested to stop or becomes requested to stop while sleeping.In general the job should not call this method directly, but only
JobContext.sleepAndStopIfRequested(JobContext, Duration)
. Override this method for affecting (potentially long) sleeps. For instance the job might temporarily release resources.Calling this method with
duration
zero or negative is equivalent to a call toJobContext.stopIfRequested()
.The default implementation polls
JobContext.stopIfRequested()
every 100 milliseconds. Implementers are encouraged to provide a more efficient implementation. The default implementation fails forduration
s too large forDuration.toNanos()
, which is approximately 292 years.- Specified by:
sleepAndStopIfRequested
in interfaceJobContext
-
supportsMessage
public boolean supportsMessage()Description copied from interface:JobContext
Returns whether this context can process information transferred byJobContext.setMessage(String)
.- Specified by:
supportsMessage
in interfaceJobContext
-
setMessage
Description copied from interface:JobContext
Indicates a message describing the current status of the job. Should be called only, ifJobContext.supportsMessage()
returns true. Otherwise calls are ignored.- Specified by:
setMessage
in interfaceJobContext
-
supportsProgress
public boolean supportsProgress()Description copied from interface:JobContext
Returns whether this context can process information transferred byJobContext.incrementProgress()
andJobContext.incrementProgress(int)
.- Specified by:
supportsProgress
in interfaceJobContext
-
incrementProgress
public void incrementProgress()Description copied from interface:JobContext
Indicates, that the job has proceeded. There is no information available, when the job will return. Calling this method is equivalent to callingincrementProgress
(1). Should be called only, ifJobContext.supportsProgress()
returns true. Otherwise calls are ignored.- Specified by:
incrementProgress
in interfaceJobContext
-
incrementProgress
public void incrementProgress(int delta) Description copied from interface:JobContext
Indicates, that the job has proceeded. There is no information available, when the job will return. Calling this method is equivalent to callingJobContext.incrementProgress()
for the number of delta times. Parameter delta should be greater or equal 0. Values out of range are accepted as well, thus no exception is thrown in that case. Calling this method with delta of 0 is equivalent to not calling this method at all. Should be called only, ifJobContext.supportsProgress()
returns true. Otherwise calls are ignored.- Specified by:
incrementProgress
in interfaceJobContext
-
supportsCompleteness
public boolean supportsCompleteness()Description copied from interface:JobContext
Returns whether this context can process information transferred byJobContext.setCompleteness(double)
.- Specified by:
supportsCompleteness
in interfaceJobContext
-
setCompleteness
public void setCompleteness(double completeness) Description copied from interface:JobContext
Indicates the current completeness of the job. Parameter completeness should be between 0 and 1. Values out of range are accepted as well, thus no exception is thrown in that case. Should be called only, ifJobContext.supportsCompleteness()
returns true. Otherwise calls are ignored.- Specified by:
setCompleteness
in interfaceJobContext
-