Package org.htmlunit

Class NicelyResynchronizingAjaxController

  • All Implemented Interfaces:
    java.io.Serializable

    public class NicelyResynchronizingAjaxController
    extends AjaxController
    This AjaxController resynchronizes calls calling from the main thread. The idea is that asynchronous AJAX calls performed directly in response to a user action (therefore in the "main" thread and not in the thread of a background task) are directly useful for the user. To easily have a testable state, these calls are performed synchronously.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.apache.commons.logging.Log LOG  
      private java.lang.ref.WeakReference<java.lang.Thread> originatedThread_  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void init()
      Initializes this instance.
      (package private) boolean isInOriginalThread()
      Indicates if the currently executing thread is the one in which this instance has been created.
      boolean processSynchron​(HtmlPage page, WebRequest settings, boolean async)
      Resynchronizes calls performed from the thread where this instance has been created.
      private void readObject​(java.io.ObjectInputStream stream)
      Custom deserialization logic.
      • Methods inherited from class java.lang.Object

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

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • originatedThread_

        private transient java.lang.ref.WeakReference<java.lang.Thread> originatedThread_
    • Constructor Detail

      • NicelyResynchronizingAjaxController

        public NicelyResynchronizingAjaxController()
        Creates an instance.
    • Method Detail

      • init

        private void init()
        Initializes this instance.
      • processSynchron

        public boolean processSynchron​(HtmlPage page,
                                       WebRequest settings,
                                       boolean async)
        Resynchronizes calls performed from the thread where this instance has been created.

        Gets notified of an AJAX call to determine how it should be processed.

        Overrides:
        processSynchron in class AjaxController
        Parameters:
        page - the page the request comes from
        settings - the request that should be performed
        async - indicates if the request should originally be asynchronous
        Returns:
        if the call should be synchronous or not; here just like the original call
      • isInOriginalThread

        boolean isInOriginalThread()
        Indicates if the currently executing thread is the one in which this instance has been created.
        Returns:
        true if it's the same thread
      • readObject

        private void readObject​(java.io.ObjectInputStream stream)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Custom deserialization logic.
        Parameters:
        stream - the stream from which to read the object
        Throws:
        java.io.IOException - if an IO error occurs
        java.lang.ClassNotFoundException - if a class cannot be found