Class Application

java.lang.Object
com.mastfrog.acteur.Application
All Implemented Interfaces:
Iterable<Page>
Direct Known Subclasses:
GenericApplication

public class Application extends Object implements Iterable<Page>
A web application. Principally, the application is a collection of Page types, which are instantiated per-request and offered the request, in the order they are added, until one accepts it and takes responsibility for responding.
Author:
Tim Boudreau
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    Application(Class<?>... types)
    Create an application, optionally passing in an array of page types (you can also call add() to add them).
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final void
    add(Page page)
     
    protected final void
    add(Class<? extends Page> page)
    Add a subtype of Page which should be instantiated on demand when responding to requests
    create(Class<?>... types)
    Create an application
    protected io.netty.handler.codec.http.HttpResponse
    Create a 404 response
    protected io.netty.handler.codec.http.HttpResponse
    decorateResponse(Event<?> event, Page page, Acteur action, io.netty.handler.codec.http.HttpResponse response)
    Deprecated.
    Use onBeforeSendResponse instead
    protected final void
     
     
    com.mastfrog.giulius.scope.ReentrantScope
    Get the Scope which is holds per-request state.
    boolean
     
    static Class<? extends Page>
    Get the type of the built in help page class, which uses Acteur.describeYourself() and annotations to generate a JSON description of all URLs the application responds to
    final boolean
     
    boolean
    isEarlyPageMatch(io.netty.handler.codec.http.HttpRequest req)
     
    Get the set of page instances, constructing them dynamically.
    protected void
    onAfterRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, Acteur acteur, Page page, State state, io.netty.handler.codec.http.HttpResponseStatus status, io.netty.handler.codec.http.HttpResponse resp)
    Override to do any post-response tasks
    protected void
    onBeforeEvent(com.mastfrog.acteur.util.RequestID id, Event<?> event)
    Called before an event is processed
    protected void
    onBeforeRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, io.netty.handler.codec.http.HttpResponseStatus status)
    Called before the response is sent RequestID
    protected void
    onBeforeSendResponse(io.netty.handler.codec.http.HttpResponseStatus status, Event<?> event, Response response, Acteur acteur, Page page)
     
    void
    Deprecated.
    Implement ErrorHandler and bind it as an eager singleton
    protected void
    send404(com.mastfrog.acteur.util.RequestID id, Event<?> event, io.netty.channel.Channel channel)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • Application

      protected Application(Class<?>... types)
      Create an application, optionally passing in an array of page types (you can also call add() to add them).
      Parameters:
      types -
    • Application

      protected Application()
  • Method Details

    • hasEarlyPages

      public boolean hasEarlyPages()
    • isEarlyPageMatch

      public boolean isEarlyPageMatch(io.netty.handler.codec.http.HttpRequest req)
    • helpPageType

      public static Class<? extends Page> helpPageType()
      Get the type of the built in help page class, which uses Acteur.describeYourself() and annotations to generate a JSON description of all URLs the application responds to
      Returns:
      A page type
    • isDefaultCorsHandlingEnabled

      public final boolean isDefaultCorsHandlingEnabled()
    • enableDefaultCorsHandling

      protected final void enableDefaultCorsHandling()
    • create

      public static Application create(Class<?>... types)
      Create an application
      Parameters:
      types -
      Returns:
    • getRequestScope

      public com.mastfrog.giulius.scope.ReentrantScope getRequestScope()
      Get the Scope which is holds per-request state.
      Returns:
    • add

      protected final void add(Class<? extends Page> page)
      Add a subtype of Page which should be instantiated on demand when responding to requests
      Parameters:
      page - A page
    • add

      protected final void add(Page page)
    • getName

      public String getName()
    • decorateResponse

      @Deprecated protected io.netty.handler.codec.http.HttpResponse decorateResponse(Event<?> event, Page page, Acteur action, io.netty.handler.codec.http.HttpResponse response)
      Deprecated.
      Use onBeforeSendResponse instead
      Add any custom headers or other attributes - override to intercept all requests.
      Parameters:
      event -
      page -
      action -
      response -
      Returns:
    • createNotFoundResponse

      protected io.netty.handler.codec.http.HttpResponse createNotFoundResponse(Event<?> event)
      Create a 404 response
      Parameters:
      event -
      Returns:
    • onAfterRespond

      protected void onAfterRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, Acteur acteur, Page page, State state, io.netty.handler.codec.http.HttpResponseStatus status, io.netty.handler.codec.http.HttpResponse resp)
      Override to do any post-response tasks
      Parameters:
      id - The incrementing ID of the request, for logging purposes
      event - The event, usually HttpEvent
      acteur - The final acteur in the chain
      page - The page which took responsibility for answering the request
      state - The state produced by the last acteur
      status - The status code for the HTTP response
      resp - The HTTP response, from Netty's HTTP codec
    • onBeforeRespond

      protected void onBeforeRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, io.netty.handler.codec.http.HttpResponseStatus status)
      Called before the response is sent RequestID
      Parameters:
      id -
      event -
      status -
    • onBeforeEvent

      protected void onBeforeEvent(com.mastfrog.acteur.util.RequestID id, Event<?> event)
      Called before an event is processed
      Parameters:
      id - The request id
      event - The event
    • onError

      public void onError(Throwable err)
      Deprecated.
      Implement ErrorHandler and bind it as an eager singleton
      Called when an exception is thrown
      Parameters:
      err -
    • iterator

      public Iterator<Page> iterator()
      Get the set of page instances, constructing them dynamically. Note that this should be called inside the application scope, with any objects which need to be available for injection available in the scope.
      Specified by:
      iterator in interface Iterable<Page>
      Returns:
      An iterator
    • send404

      protected void send404(com.mastfrog.acteur.util.RequestID id, Event<?> event, io.netty.channel.Channel channel)
    • onBeforeSendResponse

      protected void onBeforeSendResponse(io.netty.handler.codec.http.HttpResponseStatus status, Event<?> event, Response response, Acteur acteur, Page page)