Class PushPage

java.lang.Object
com.machinezoo.pushmode.PushPage

public abstract class PushPage extends Object
Root of server-side object graph corresponding to some currently viewed page. PushMode is a stateful web framework. All currently open pages in browsers of all users have corresponding server-side state. This state is stored in multiple server-side objects and PushPage is the root of page's server-side object graph.

The recommended practice is to define one derived class for every distinct page on the site. It is often desirable to create one or more "master" pages and then derive specialized pages from them. Every derived class must at the very minimum define document() method.

Whenever the user visits some page, corresponding PushPage instance is created. Instances of PushPage live for as long as the user keeps the page open (i.e. while keepalive messages keep coming) and some time after that to account for temporary connection loss.

Every PushPage has an associated PageExecutor that can be obtained from executor() method. All page renders (executions of document()), DOM events, and DOM bindings are scheduled on the PageExecutor.

  • Constructor Details

    • PushPage

      protected PushPage()
      Creates new PushPage. PushPage is an abstract class. You have to derive from it in order to instantiate it.
  • Method Details

    • request

      public ReactiveServletRequest request()
      Initial request that opened this page.

      This method only reads immutable data.

      Returns:
      Page's initial HTTP request.
    • pageId

      public String pageId()
      Globally unique page ID. Page IDs are produced by secure cryptographic random number generator. They never repeat.

      This method only reads immutable data.

      Returns:
      Page ID as a string matching regex [a-zA-Z0-9]+.
    • executor

      @DraftApi("some way to specify the underlying thread pool") public ExecutorService executor()
      Page's event loop. All page renders and all DOM events and bindings run in this event loop.

      This method only reads immutable data.

      Returns:
      Page's event loop.
    • document

      public abstract DomElement document()
      Renders the page, i.e. generates DOM tree of the page. Override this method to define HTML content of the page.

      This method is called as part of page's reactive computation, i.e. its dependencies are tracked and it is re-run every time its dependencies change.

      This method is run by page's executor().

      Returns:
      Page's DOM tree with <html> root tag.
    • serve

      @NoDocs public void serve(ReactiveServletRequest request)
    • serve

      @NoDocs public void serve(ReactiveServletResponse response)
    • poster

      public boolean poster()
      Checks whether currently rendered frame is a poster frame.

      Poster frame is sent as vanilla HTML to the browser in response to initial HTTP request. Usually only the first frame of the page is a poster frame, but draft frames may cause the poster frame to be rendered several times.

      Application code can call this method from within document() method. It is useful for rendering slightly different content in the poster frame, perhaps to deal with bots or to enable events in a more controlled fashion.

      This method accesses reactive data. It will cause reactive computations to re-evaluate when the reactive data changes.

      This method is safe to call from any thread.

      Returns:
      True if rendering poster frame.
    • toString

      @NoDocs public String toString()
      Overrides:
      toString in class Object
    • start

      @NoDocs public void start()
    • frame

      @NoDocs @DraftApi("mind testability") public PageFrame frame(long requestSeq)
    • current

      @NoDocs public static PushPage current()