Class BaseWatchable

java.lang.Object
com.sun.pdfview.BaseWatchable
All Implemented Interfaces:
Watchable, Runnable
Direct Known Subclasses:
PDFParser, PDFRenderer

public abstract class BaseWatchable extends Object implements Watchable, Runnable
An abstract implementation of the watchable interface, that is extended by the parser and renderer to do their thing.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) class 
    A 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

    Fields
    Modifier and Type
    Field
    Description
    when to stop
    private Object
    a lock for parsing operations
    private int
    the current status, from the list in Watchable
    private Object
    a lock for status-related operations
    private static boolean
    suppress local stack trace on setError.
    private Thread
    the thread we are running in

    Fields inherited from interface com.sun.pdfview.Watchable

    COMPLETED, ERROR, NEEDS_DATA, NOT_STARTED, PAUSED, RUNNING, STOPPED, UNKNOWN
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new instance of BaseWatchable
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Clean up after a set of iterations.
    protected void
    execute(boolean synchronous)
    Start executing this watchable
    int
    Get the status of this watchable
    private String
     
    void
    go()
    Start this watchable and run in a new thread until it is finished or stopped.
    void
    go(boolean synchronous)
    Start this watchable and run until it is finished or stopped.
    void
    go(int steps)
    Start this watchable and run for the given number of steps or until finished or stopped.
    void
    go(long millis)
    Start this watchable and run for the given amount of time, or until finished or stopped.
    boolean
    return true if this watchable is ready to be executed
    boolean
    Return whether this watchable has finished.
    static boolean
    return true if we would be suppressing setError stack traces.
    protected abstract int
    Perform a single iteration of this watchable.
    void
    run()
     
    protected void
    Set an error on this watchable
    protected void
    setStatus(int status)
    Set the status of this watchable
    static void
    setSuppressSetErrorStackTrace(boolean suppressTrace)
    set suppression of stack traces from setError.
    protected void
    Prepare for a set of iterations.
    void
    Stop this watchable.
    void
    Wait for this watchable to finish

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • status

      private int status
      the current status, from the list in Watchable
    • statusLock

      private Object statusLock
      a lock for status-related operations
    • parserLock

      private Object parserLock
      a lock for parsing operations
    • gate

      private BaseWatchable.Gate gate
      when to stop
    • SuppressSetErrorStackTrace

      private static boolean SuppressSetErrorStackTrace
      suppress local stack trace on setError.
    • thread

      private Thread thread
      the thread we are running in
  • Constructor Details

    • BaseWatchable

      protected BaseWatchable()
      Creates a new instance of BaseWatchable
  • Method Details

    • iterate

      protected abstract int iterate() throws Exception
      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()
      Specified by:
      run in interface Runnable
    • getStatus

      public int getStatus()
      Get the status of this watchable
      Specified by:
      getStatus in interface Watchable
      Returns:
      one of the well-known statuses
    • 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. Stop will cause all processing to cease, and the watchable to be destroyed.
      Specified by:
      stop in interface Watchable
    • 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.
      Specified by:
      go in interface Watchable
    • 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.
      Specified by:
      go in interface Watchable
      Parameters:
      steps - the number of steps to run for
    • go

      public void go(long millis)
      Start this watchable and run for the given amount of time, or until finished or stopped.
      Specified by:
      go in interface Watchable
      Parameters:
      millis - the number of milliseconds to run for
    • 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

      protected void setError(Exception error)
      Set an error on this watchable
    • getStatusString

      private String getStatusString()