Package com.epimorphics.tasks
Class SimpleProgressMonitor
- java.lang.Object
-
- com.epimorphics.tasks.SimpleProgressMonitor
-
- All Implemented Interfaces:
JSONWritable,ProgressMonitor,ProgressMonitorReporter,ProgressReporter
- Direct Known Subclasses:
LiveProgressMonitor
public class SimpleProgressMonitor extends Object implements ProgressMonitorReporter, JSONWritable
Simple implementation of progress monitor/reporter for in-process reporting.- Author:
- Dave Reynolds
-
-
Field Summary
Fields Modifier and Type Field Description protected Stringidstatic StringID_FIELDprotected List<ProgressMessage>messagesstatic StringMESSAGES_FIELDprotected intprogressstatic StringPROGRESS_FIELDprotected TaskStatestatestatic StringSTATE_FIELDprotected booleansucceededstatic StringSUCEEDED_FIELDprotected longtimestampstatic StringTYPE_ERRORstatic StringTYPE_MAIN
-
Constructor Summary
Constructors Constructor Description SimpleProgressMonitor()SimpleProgressMonitor(String id)SimpleProgressMonitor(org.apache.jena.atlas.json.JsonObject stored)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetId()Return an ID string for this monitor/reporter.List<ProgressMessage>getMessages()Return all progress messages logged so far.List<ProgressMessage>getMessagesSince(int offset)Return all progress messages since the given message number.intgetProgress()Get the progress of the task as a percentage.TaskStategetState()Return the state of the task.longgetTimestamp()booleanmoreMessagesSince(int offset)Return true if there are more progress messages available since the given message number.voidreport(String message)Log a progress message, this may be timestamped by the reporter implementation.voidreport(String message, int lineNumber)Log a progress message with an associated line number, this may be timestamped by the reporter implementation.voidreport(String message, int lineNumber, String type)Log a progress message with an associated line number, this may be timestamped by the reporter implementation.voidreport(String message, String type)Log a progress message, this may be timestamped by the reporter implementation.voidreportError(String message)Report an error as a progress message of type "error" and set the status to failedvoidreportError(String message, int lineNumber)Report an error as a progress message of type "error" and set the status to failedprotected voidreportNewMessage(ProgressMessage message)protected voidreportStateChange()voidsetFailed()Record that a task has completed but with an error.voidsetProgress(int progress)Set the progress percentage.voidsetState(TaskState state)Change the state of the progress report.voidsetSucceeded()Record that a task has completed but successfullyvoidsetSuccess(boolean wasSuccessful)Record whether the task was successful or not.booleansucceeded()Return true if the task has Terminated and was successful.StringtoString()SimpleProgressMonitortruncate(int offset)Return a truncated version of the monitor only containing message since a given offset pointJSONWritableviewUpdatesSince(int offset)Return a JSON view onto the status of the monitor including any messages since the given offset.protected voidwriteIncrement(JSFullWriter out, int offset)voidwriteTo(JSFullWriter out)
-
-
-
Field Detail
-
ID_FIELD
public static final String ID_FIELD
- See Also:
- Constant Field Values
-
PROGRESS_FIELD
public static final String PROGRESS_FIELD
- See Also:
- Constant Field Values
-
STATE_FIELD
public static final String STATE_FIELD
- See Also:
- Constant Field Values
-
SUCEEDED_FIELD
public static final String SUCEEDED_FIELD
- See Also:
- Constant Field Values
-
MESSAGES_FIELD
public static final String MESSAGES_FIELD
- See Also:
- Constant Field Values
-
TYPE_ERROR
public static final String TYPE_ERROR
- See Also:
- Constant Field Values
-
TYPE_MAIN
public static final String TYPE_MAIN
- See Also:
- Constant Field Values
-
id
protected String id
-
state
protected TaskState state
-
progress
protected int progress
-
succeeded
protected boolean succeeded
-
messages
protected List<ProgressMessage> messages
-
timestamp
protected long timestamp
-
-
Constructor Detail
-
SimpleProgressMonitor
public SimpleProgressMonitor()
-
SimpleProgressMonitor
public SimpleProgressMonitor(String id)
-
SimpleProgressMonitor
public SimpleProgressMonitor(org.apache.jena.atlas.json.JsonObject stored)
-
-
Method Detail
-
getTimestamp
public long getTimestamp()
-
setState
public void setState(TaskState state)
Description copied from interface:ProgressReporterChange the state of the progress report.- Specified by:
setStatein interfaceProgressReporter
-
getId
public String getId()
Description copied from interface:ProgressReporterReturn an ID string for this monitor/reporter. Useful when managing a pool of persistent status reports.- Specified by:
getIdin interfaceProgressReporter
-
setProgress
public void setProgress(int progress)
Description copied from interface:ProgressReporterSet the progress percentage.- Specified by:
setProgressin interfaceProgressReporter
-
setSuccess
public void setSuccess(boolean wasSuccessful)
Description copied from interface:ProgressReporterRecord whether the task was successful or not.- Specified by:
setSuccessin interfaceProgressReporter
-
setFailed
public void setFailed()
Description copied from interface:ProgressReporterRecord that a task has completed but with an error.- Specified by:
setFailedin interfaceProgressReporter
-
report
public void report(String message)
Description copied from interface:ProgressReporterLog a progress message, this may be timestamped by the reporter implementation.- Specified by:
reportin interfaceProgressReporter
-
report
public void report(String message, int lineNumber)
Description copied from interface:ProgressReporterLog a progress message with an associated line number, this may be timestamped by the reporter implementation.- Specified by:
reportin interfaceProgressReporter- Parameters:
message- the message textlineNumber- the number in some input file corresponding the the message
-
report
public void report(String message, String type)
Description copied from interface:ProgressReporterLog a progress message, this may be timestamped by the reporter implementation.- Specified by:
reportin interfaceProgressReporter- Parameters:
message- the message texttype- the nature of the message e.g. "error", application dependent what types are supported
-
report
public void report(String message, int lineNumber, String type)
Description copied from interface:ProgressReporterLog a progress message with an associated line number, this may be timestamped by the reporter implementation.- Specified by:
reportin interfaceProgressReporter- Parameters:
message- the message textlineNumber- the number in some input file corresponding the the messagetype- the nature of the message e.g. "error", application dependent what types are supported
-
reportError
public void reportError(String message)
Description copied from interface:ProgressReporterReport an error as a progress message of type "error" and set the status to failed- Specified by:
reportErrorin interfaceProgressReporter
-
reportError
public void reportError(String message, int lineNumber)
Description copied from interface:ProgressReporterReport an error as a progress message of type "error" and set the status to failed- Specified by:
reportErrorin interfaceProgressReporter
-
reportStateChange
protected void reportStateChange()
-
reportNewMessage
protected void reportNewMessage(ProgressMessage message)
-
getState
public TaskState getState()
Description copied from interface:ProgressMonitorReturn the state of the task. It may be Waiting to start, Running or Terminated.- Specified by:
getStatein interfaceProgressMonitor- Specified by:
getStatein interfaceProgressReporter
-
getProgress
public int getProgress()
Description copied from interface:ProgressMonitorGet the progress of the task as a percentage. Not all monitors will offer fine grained progress but the progress will always be 0 for Waiting tasks, >= 1 for running tasks and 100 for Terminated tasks (even for unsuccessful termination).- Specified by:
getProgressin interfaceProgressMonitor
-
succeeded
public boolean succeeded()
Description copied from interface:ProgressMonitorReturn true if the task has Terminated and was successful.- Specified by:
succeededin interfaceProgressMonitor
-
getMessages
public List<ProgressMessage> getMessages()
Description copied from interface:ProgressMonitorReturn all progress messages logged so far.- Specified by:
getMessagesin interfaceProgressMonitor
-
getMessagesSince
public List<ProgressMessage> getMessagesSince(int offset)
Description copied from interface:ProgressMonitorReturn all progress messages since the given message number.- Specified by:
getMessagesSincein interfaceProgressMonitor
-
moreMessagesSince
public boolean moreMessagesSince(int offset)
Description copied from interface:ProgressMonitorReturn true if there are more progress messages available since the given message number.- Specified by:
moreMessagesSincein interfaceProgressMonitor
-
truncate
public SimpleProgressMonitor truncate(int offset)
Return a truncated version of the monitor only containing message since a given offset point
-
writeTo
public void writeTo(JSFullWriter out)
- Specified by:
writeToin interfaceJSONWritable
-
writeIncrement
protected void writeIncrement(JSFullWriter out, int offset)
-
viewUpdatesSince
public JSONWritable viewUpdatesSince(int offset)
Return a JSON view onto the status of the monitor including any messages since the given offset.- Specified by:
viewUpdatesSincein interfaceProgressMonitor
-
setSucceeded
public void setSucceeded()
Description copied from interface:ProgressReporterRecord that a task has completed but successfully- Specified by:
setSucceededin interfaceProgressReporter
-
-