Class QueueTool

  • All Implemented Interfaces:
    Outputable, Timeoutable

    public class QueueTool
    extends java.lang.Object
    implements Outputable, Timeoutable
    Provides functionality to work with java.awt.EventQueue empty.

    Timeouts used:
    QueueTool.WaitQueueEmptyTimeout - timeout to wait queue emptied
    QueueTool.QueueCheckingDelta - time delta to check result
    QueueTool.LockTimeout - time to wait queue locked after lock action has been put there
    QueueTool.InvocationTimeout - time for action was put into queue to be started
    QueueTool.MaximumLockingTime - maximum time to lock queue.
    Author:
    Alexandre Iline (alexandre.iline@sun.com)
    See Also:
    Timeouts
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  QueueTool.QueueAction
      Action to be excuted through event queue.
    • Constructor Summary

      Constructors 
      Constructor Description
      QueueTool()
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean checkEmpty()
      Checks if system event queue is empty.
      TestOut getOutput()
      Returns print output streams or writers.
      static java.awt.EventQueue getQueue()
      Returns system EventQueue.
      Timeouts getTimeouts()
      Return current timeouts.
      static void installQueue()
      Installs own Jemmy EventQueue implementation.
      QueueTool.QueueAction invoke​(java.lang.Runnable runnable)
      Invokes runnable through EventQueue.
      QueueTool.QueueAction invoke​(Action action, java.lang.Object param)
      Invokes action through EventQueue.
      void invoke​(QueueTool.QueueAction action)
      Invokes action through EventQueue.
      void invokeAndWait​(java.lang.Runnable runnable)
      Invokes runnable through EventQueue.
      java.lang.Object invokeAndWait​(Action action, java.lang.Object param)
      Invokes action through EventQueue.
      java.lang.Object invokeAndWait​(QueueTool.QueueAction action)
      Invokes action through EventQueue.
      void invokeSmoothly​(java.lang.Runnable runnable)
      Being executed outside of AWT dispatching thread, invokes a runnable through the event queue.
      java.lang.Object invokeSmoothly​(Action action, java.lang.Object param)
      Being executed outside of AWT dispatching thread, invokes an action through the event queue.
      java.lang.Object invokeSmoothly​(QueueTool.QueueAction action)
      Being executed outside of AWT dispatching thread, invokes an action through the event queue.
      static boolean isDispatchThread()
      Map to EventQueue.isDispatchThread().
      void lock()
      Locks EventQueue.
      void lock​(long time)
      Locks event queue for "time" milliseconds.
      static void postEvent​(java.awt.AWTEvent event)
      Simply posts events into the system event queue.
      static void processEvent​(java.awt.AWTEvent event)
      Shortcuts event if ((JemmyProperties.getCurrentDispatchingModel() & JemmyProperties.SHORTCUT_MODEL_MASK) != 0) and if executed in the dispatch thread.
      void setOutput​(TestOut out)
      Defines print output streams or writers.
      void setTimeouts​(Timeouts ts)
      Defines current timeouts.
      static void shortcutEvent​(java.awt.AWTEvent event)
      Dispatches event ahead of all events staying in the event queue.
      static void uninstallQueue()
      Uninstalls own Jemmy EventQueue implementation.
      void unlock()
      Unlocks EventQueue.
      void waitEmpty()
      Waits for system event queue empty.
      void waitEmpty​(long emptyTime)
      Waits for system event queue be empty for emptyTime milliseconds.
      boolean wasLockingExpired()
      Sais if last locking was expired.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • QueueTool

        public QueueTool()
        Constructor.
    • Method Detail

      • getQueue

        public static java.awt.EventQueue getQueue()
        Returns system EventQueue.
        Returns:
        system EventQueue.
      • isDispatchThread

        public static boolean isDispatchThread()
        Map to EventQueue.isDispatchThread().
        Returns:
        true if this thread is the AWT dispatching thread.
      • checkEmpty

        public static boolean checkEmpty()
        Checks if system event queue is empty.
        Returns:
        true if EventQueue is empty.
      • processEvent

        public static void processEvent​(java.awt.AWTEvent event)
        Shortcuts event if ((JemmyProperties.getCurrentDispatchingModel() & JemmyProperties.SHORTCUT_MODEL_MASK) != 0) and if executed in the dispatch thread. Otherwise posts event.
        Parameters:
        event - Event to dispatch.
      • postEvent

        public static void postEvent​(java.awt.AWTEvent event)
        Simply posts events into the system event queue.
        Parameters:
        event - Event to dispatch.
      • shortcutEvent

        public static void shortcutEvent​(java.awt.AWTEvent event)
        Dispatches event ahead of all events staying in the event queue.
        Parameters:
        event - an event to be shortcut.
      • installQueue

        public static void installQueue()
        Installs own Jemmy EventQueue implementation. The method is executed in dispatchmode only.
        See Also:
        uninstallQueue()
      • uninstallQueue

        public static void uninstallQueue()
        Uninstalls own Jemmy EventQueue implementation.
        See Also:
        installQueue()
      • waitEmpty

        public void waitEmpty()
        Waits for system event queue empty. Uses "QueueTool.WaitQueueEmptyTimeout" milliseconds to wait.
        Throws:
        TimeoutExpiredException
      • waitEmpty

        public void waitEmpty​(long emptyTime)
        Waits for system event queue be empty for emptyTime milliseconds. Uses "QueueTool.WaitQueueEmptyTimeout" milliseconds to wait.
        Parameters:
        emptyTime - time for the queue to stay empty.
        Throws:
        TimeoutExpiredException
      • invoke

        public void invoke​(QueueTool.QueueAction action)
        Invokes action through EventQueue. Does not wait for it execution.
        Parameters:
        action - an action to be invoked.
      • invoke

        public QueueTool.QueueAction invoke​(java.lang.Runnable runnable)
        Invokes runnable through EventQueue. Does not wait for it execution.
        Parameters:
        runnable - a runnable to be invoked.
        Returns:
        QueueAction instance which can be use for execution monitoring.
        See Also:
        QueueTool.QueueAction
      • invoke

        public QueueTool.QueueAction invoke​(Action action,
                                            java.lang.Object param)
        Invokes action through EventQueue. Does not wait for it execution.
        Parameters:
        action - an action to be invoked.
        param - action.launch(Object) method parameter.
        Returns:
        QueueAction instance which can be use for execution monitoring.
        See Also:
        QueueTool.QueueAction
      • invokeSmoothly

        public java.lang.Object invokeSmoothly​(QueueTool.QueueAction action)
        Being executed outside of AWT dispatching thread, invokes an action through the event queue. Otherwise executes action.launch() method directly.
        Parameters:
        action - anaction to be executed.
        Returns:
        Action result.
      • invokeSmoothly

        public void invokeSmoothly​(java.lang.Runnable runnable)
        Being executed outside of AWT dispatching thread, invokes a runnable through the event queue. Otherwise executes runnable.run() method directly.
        Parameters:
        runnable - a runnable to be executed.
      • invokeSmoothly

        public java.lang.Object invokeSmoothly​(Action action,
                                               java.lang.Object param)
        Being executed outside of AWT dispatching thread, invokes an action through the event queue. Otherwise executes action.launch(Object) method directly.
        Parameters:
        action - anaction to be executed.
        param - an action parameter
        Returns:
        Action result.
      • invokeAndWait

        public java.lang.Object invokeAndWait​(QueueTool.QueueAction action)
        Invokes action through EventQueue. Waits for it execution.
        Parameters:
        action - an action to be invoked.
        Returns:
        a result of action
        Throws:
        TimeoutExpiredException - if action was not executed in "QueueTool.InvocationTimeout" milliseconds.
      • invokeAndWait

        public void invokeAndWait​(java.lang.Runnable runnable)
        Invokes runnable through EventQueue. Waits for it execution.
        Parameters:
        runnable - a runnable to be invoked.
        Throws:
        TimeoutExpiredException - if runnable was not executed in "QueueTool.InvocationTimeout" milliseconds.
      • invokeAndWait

        public java.lang.Object invokeAndWait​(Action action,
                                              java.lang.Object param)
        Invokes action through EventQueue. Waits for it execution. May throw TimeoutExpiredException if action was not executed in "QueueTool.InvocationTimeout" milliseconds.
        Parameters:
        action - an action to be invoked.
        param - action.launch(Object method parameter.
        Returns:
        a result of action
        Throws:
        TimeoutExpiredException - if action was not executed in "QueueTool.InvocationTimeout" milliseconds.
      • lock

        public void lock()
        Locks EventQueue. Locking will be automatically aborted after "QueueTool.MaximumLockingTime" milliseconds.
        Throws:
        TimeoutExpiredException
        See Also:
        unlock()
      • unlock

        public void unlock()
        Unlocks EventQueue.
        See Also:
        lock()
      • lock

        public void lock​(long time)
        Locks event queue for "time" milliseconds. Returns immediately after locking.
        Parameters:
        time - a time to lock the queue for.
      • wasLockingExpired

        public boolean wasLockingExpired()
        Sais if last locking was expired.
        Returns:
        true if last locking had beed expired.