Package org.openpdf.renderer
Class BaseWatchable
java.lang.Object
org.openpdf.renderer.BaseWatchable
- Direct Known Subclasses:
PDFParser,PDFRenderer
An abstract implementation of the watchable interface, that is extended
by the parser and renderer to do their thing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classA class that lets us give it a target time or number of steps, and will tell us to stop after that much time or that many steps -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static PDFErrorHandlerprivate Exceptionprivate BaseWatchable.Gatewhen to stopprivate final Objecta lock for parsing operationsprivate intthe current status, from the list in Watchableprivate final Objecta lock for status-related operationsprivate static booleansuppress local stack trace on setError.private Threadthe thread we are running inFields inherited from interface org.openpdf.renderer.Watchable
COMPLETED, ERROR, NEEDS_DATA, NOT_STARTED, PAUSED, RUNNING, STOPPED, UNKNOWN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcleanup()Clean up after a set of iterations.protected voidexecute(boolean synchronous) Start executing this watchablestatic PDFErrorHandlerintGet the status of this watchablevoidgo()Start this watchable and run in a new thread until it is finished or stopped.voidgo(boolean synchronous) Start this watchable and run until it is finished or stopped.voidgo(int steps) Start this watchable and run for the given number of steps or until finished or stopped.voidgo(long millis) Start this watchable and run for the given amount of time, or until finished or stopped.booleanreturn true if this watchable is ready to be executedbooleanReturn whether this watchable has finished.static booleanreturn true if we would be suppressing setError stack traces.protected abstract intiterate()Perform a single iteration of this watchable.voidrun()protected voidSet an error on this watchablestatic voidprotected voidsetStatus(int status) Set the status of this watchablestatic voidsetSuppressSetErrorStackTrace(boolean suppressTrace) set suppression of stack traces from setError.protected voidsetup()Prepare for a set of iterations.voidstop()Stop this watchable if it is not already finished.voidWait for this watchable to finish
-
Field Details
-
status
private int statusthe current status, from the list in Watchable -
statusLock
a lock for status-related operations -
parserLock
a lock for parsing operations -
gate
when to stop -
SuppressSetErrorStackTrace
private static boolean SuppressSetErrorStackTracesuppress local stack trace on setError. -
thread
the thread we are running in -
exception
-
errorHandler
-
-
Constructor Details
-
BaseWatchable
protected BaseWatchable()Creates a new instance of BaseWatchable
-
-
Method Details
-
iterate
Perform a single iteration of this watchable. This is the minimum granularity which the go() commands operate over.- Returns:
- one of three values:
- Watchable.RUNNING if there is still data to be processed
- Watchable.NEEDS_DATA if there is no data to be processed but the execution is not yet complete
- Watchable.COMPLETED if the execution is complete
- Throws:
Exception
-
setup
protected void setup()Prepare for a set of iterations. Called before the first iterate() call in a sequence. Subclasses should extend this method if they need to do anything to setup. -
cleanup
protected void cleanup()Clean up after a set of iterations. Called after iteration has stopped due to completion, manual stopping, or error. -
run
public void run() -
getStatus
public int getStatus()Get the status of this watchable -
isFinished
public boolean isFinished()Return whether this watchable has finished. A watchable is finished when its status is either COMPLETED, STOPPED or ERROR -
isExecutable
public boolean isExecutable()return true if this watchable is ready to be executed -
stop
public void stop()Stop this watchable if it is not already finished. Stop will cause all processing to cease, and the watchable to be destroyed. -
go
public void go()Start this watchable and run in a new thread until it is finished or stopped. Note the watchable may be stopped if go() with a different time is called during execution. -
go
public void go(boolean synchronous) Start this watchable and run until it is finished or stopped. Note the watchable may be stopped if go() with a different time is called during execution.- Parameters:
synchronous- if true, run in this thread
-
go
public void go(int steps) Start this watchable and run for the given number of steps or until finished or stopped. -
go
public void go(long millis) Start this watchable and run for the given amount of time, or until finished or stopped. -
waitForFinish
public void waitForFinish()Wait for this watchable to finish -
execute
protected void execute(boolean synchronous) Start executing this watchable- Parameters:
synchronous- if true, run in this thread
-
setStatus
protected void setStatus(int status) Set the status of this watchable -
isSuppressSetErrorStackTrace
public static boolean isSuppressSetErrorStackTrace()return true if we would be suppressing setError stack traces.- Returns:
- boolean
-
setSuppressSetErrorStackTrace
public static void setSuppressSetErrorStackTrace(boolean suppressTrace) set suppression of stack traces from setError.- Parameters:
suppressTrace-
-
setError
Set an error on this watchable -
getException
-
setErrorHandler
-
getErrorHandler
-