@Beta public class ConsolePO extends Object implements SubProgressObserver
Note that this implementation is incomplete, subtasks are not supported. Also API contracts are not enforced, thus a client code which works with this implementation might fail with a stricter implementation.
Please note that this class is marked with Beta
annotation, so it can be subject of incompatible changes
or removal in later releases.
Modifier and Type | Class and Description |
---|---|
static interface |
ConsolePO.Callback
Callback handle.
|
Constructor and Description |
---|
ConsolePO(PrintStream ps,
String name)
Construct a new instance printing to a specific stream with a default delay (5s).
|
ConsolePO(PrintStream ps,
String name,
long targetDelayInMs)
Construct a new instance printing to a s[ecofoc stream.
|
ConsolePO(String name)
Construct a new instance printing to
System.err with a default delay (5s). |
ConsolePO(String name,
long targetDelayInMs)
Construct a new instance printing to
System.err . |
Modifier and Type | Method and Description |
---|---|
void |
done()
Notifies that the represented task is done and no further work will be done.
|
Supplier<TimerStatistics> |
getAsyncStatSnapshotSupplier()
Create an asynchronous statistics snapshot supplier.
|
TimerStatistics |
getStatistics()
Get timer statistic of this observer.
|
boolean |
isCancelled()
Returns whether cancellation of current operation has been requested.
|
void |
onDone(ConsolePO.Callback callback)
Register a callback to be called when done.
|
SubProgressObserver |
subTask(String name,
long work)
Follow the processing of a specific amount of work units by a separate observer.
|
void |
switchToDeterminate(long totalWork)
Notifies that the remaining amount of work units to complete this task is known.
|
String |
toString() |
void |
worked(long work)
Notifies that a given number of work units has been completed.
|
void |
worked(long work,
boolean force)
Report work unit completion.
|
void |
workUnit(String workUnit)
Notifies the measure unit of work (such as 'pc', 'file', 'percent', etc).
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
from
close
public ConsolePO(String name)
System.err
with a default delay (5s).name
- Name to displaypublic ConsolePO(PrintStream ps, String name)
ps
- PrintStream to print toname
- Name to displaypublic ConsolePO(String name, long targetDelayInMs)
System.err
.name
- Name to displaytargetDelayInMs
- Delay for console updatepublic ConsolePO(PrintStream ps, String name, long targetDelayInMs)
ps
- PrintStream to print toname
- Name to displaytargetDelayInMs
- Delay for console updatepublic Supplier<TimerStatistics> getAsyncStatSnapshotSupplier()
This method can only be invoked from the main thread. The returned Supplier
is thread safe.
public void onDone(ConsolePO.Callback callback)
done()
.callback
- Callback to be invoked when donepublic void switchToDeterminate(long totalWork)
ProgressObserver
switchToDeterminate
in interface ProgressObserver
totalWork
- The total amount of work represented by this task.public void workUnit(String workUnit)
ProgressObserver
workUnit
in interface ProgressObserver
workUnit
- the measure unit of work.public void worked(long work, boolean force)
work
- Work units completedforce
- If true then printout is forced regardless of underlying autothrottle statuspublic void worked(long work)
ProgressObserver
Note that this amount represents an installment, as opposed to a cumulative amount of work done to date.
worked
in interface ProgressObserver
work
- Amount of work reportedpublic SubProgressObserver subTask(String name, long work)
ProgressObserver
The given amount of work on the level of the current observer is considered completed upon
ProgressObserver.done()
called on the returned subtask's observer.
Cancel propagation is expected to be transparent.
The strict contract regarding the state when ProgressObserver.worked(long)
can be called is relaxed in
the context of subtask observers: implicitly logging work on the upper level by calling
ProgressObserver.done()
on the subtask level after the upper level is closed will no cause
problem on either level.
subTask
in interface ProgressObserver
name
- Name of the represented sub task (for example to display)work
- A non-negative number of work units considered to be completed upon finishing
the associated subtask.public boolean isCancelled()
CancelObserver
Long running/memory intensive operations should poll to see if cancelation has been requested. Since time-out based cancelations might be implemented polling should not be done too often.
It is expected that implementations wont return false
after a true
value returned.
It is also expected that implementations tolerate multiple calls regardless of the cancallation state.
Please note that test cases might check for too frequent invocations, so the propagation of any
AssertionError
thrown by this method should not be obstructed.
It is usually expected that the cancelled task should throw
CancellationException
and this behavior should be documented in their APIdocs.
isCancelled
in interface CancelObserver
public void done()
ProgressObserver
NOTE: Cancellation has no effect to the progress state, so this method must be invoked when done, either due normal completion; cancellation or error
done
in interface ProgressObserver
public TimerStatistics getStatistics() throws IllegalStateException
IllegalStateException
- when not done()
or no work units are reported.