Class NativeApp

java.lang.Object
rife.nativeapp.NativeApp
All Implemented Interfaces:
AutoCloseable

public class NativeApp extends Object implements AutoCloseable
Runs the RIFE2 site of an app in the app's own process, without a server: each request of the app's web view is handed to a SiteRunner and its response is handed back while it's written.

The site is the one that the app names in META-INF/services/rife.engine.Site, or that the SiteProvider makes which it names in META-INF/services/rife.nativeapp.SiteProvider, which is used when both are named, unless one is given to the constructor. What the app tells the site, before its first request, are properties that the site can read in its setup(), like DATA_PROPERTY for the directory where it keeps what should last.

The C functions of EntryPoints call one instance of this class, which runs on the JVM as well, for tests and for checks before the native build.

Since:
1.11.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The build number of the app.
    static final int
    A request that the app cancelled.
    static final int
    A request that ended with all of its answer, as EntryPoints tells it.
    static final String
    The directory where the app keeps what should last, the cookies of the site among them.
    static final String
    The host that the site is at when the app doesn't give one.
    static final String
    The scheme that the site is at when the app doesn't give one.
    static final int
    A request that failed before all of its answer was given.
    static final String
    The host of the address that the web view has the site at.
    static final String
    The platform that the app runs on, like ios, mac or android.
    static final String
    The scheme of the address that the web view has the site at.
    static final String
    The classpath directory of the script that the pages need inside an app, which a site runner only serves when PLATFORM_PROPERTY is set.
    static final String
    The classpath directory that the static files of the site are served from, which is where an app puts its src/main/webapp.
    static final String
    The directory for temporary files, uploads among them, when the one of Java isn't one that the app may write in.
    static final String
    The version of the app.
    static final String
    true when the app takes each answer all at once, on the thread that asked, like a web view of Android does.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an app whose site is named in META-INF/services/rife.engine.Site, or made by the SiteProvider named in META-INF/services/rife.nativeapp.SiteProvider.
    Creates an app with the site that's given.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    cancel(long id)
    Tells the site that nobody waits for the response of a request anymore.
    void
    Stops the site, when it was started, like stop().
    void
    handle(long id, String url, String method, String headers, byte[] body, SiteResponseListener listener)
    Handles a request of the app.
    static String
    The headers of a response as lines of a name, a colon and a value, without its cookies, which the site's cookie jar keeps.
    static void
    main(String[] arguments)
    Asks the site for addresses on the JVM and says what it answered, to see what's wrong in seconds rather than after a native build.
    property(String name, String value)
    Sets a property of the site, before its first request.
    Retrieves the runner of the site, which is started by the first call.
    void
    Stops the site, when it was started.

    Methods inherited from class java.lang.Object

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

    • PLATFORM_PROPERTY

      public static final String PLATFORM_PROPERTY
      The platform that the app runs on, like ios, mac or android. When it's set, the context:nativeAppScript value of a template includes the script that does in a page what the app's web view doesn't do by itself.
      Since:
      1.11.0
      See Also:
    • DATA_PROPERTY

      public static final String DATA_PROPERTY
      The directory where the app keeps what should last, the cookies of the site among them.
      Since:
      1.11.0
      See Also:
    • SCHEME_PROPERTY

      public static final String SCHEME_PROPERTY
      The scheme of the address that the web view has the site at.
      Since:
      1.11.0
      See Also:
    • HOST_PROPERTY

      public static final String HOST_PROPERTY
      The host of the address that the web view has the site at.
      Since:
      1.11.0
      See Also:
    • TEMP_PROPERTY

      public static final String TEMP_PROPERTY
      The directory for temporary files, uploads among them, when the one of Java isn't one that the app may write in.
      Since:
      1.11.0
      See Also:
    • VERSION_PROPERTY

      public static final String VERSION_PROPERTY
      The version of the app.
      Since:
      1.11.0
      See Also:
    • WHOLE_RESPONSES_PROPERTY

      public static final String WHOLE_RESPONSES_PROPERTY
      true when the app takes each answer all at once, on the thread that asked, like a web view of Android does. A response that goes on after the request returns, like an event stream, is then cancelled when it returns, and nothing is told from another thread.
      Since:
      1.11.0
      See Also:
    • BUILD_NUMBER_PROPERTY

      public static final String BUILD_NUMBER_PROPERTY
      The build number of the app.
      Since:
      1.11.0
      See Also:
    • DEFAULT_SCHEME

      public static final String DEFAULT_SCHEME
      The scheme that the site is at when the app doesn't give one.
      Since:
      1.11.0
      See Also:
    • DEFAULT_HOST

      public static final String DEFAULT_HOST
      The host that the site is at when the app doesn't give one.
      Since:
      1.11.0
      See Also:
    • STATIC_RESOURCE_BASE

      public static final String STATIC_RESOURCE_BASE
      The classpath directory that the static files of the site are served from, which is where an app puts its src/main/webapp.
      Since:
      1.11.0
      See Also:
    • SCRIPT_RESOURCE_BASE

      public static final String SCRIPT_RESOURCE_BASE
      The classpath directory of the script that the pages need inside an app, which a site runner only serves when PLATFORM_PROPERTY is set. It's no package, so that it's also found when RIFE2 is a module.
      Since:
      1.11.0
      See Also:
    • COMPLETED

      public static final int COMPLETED
      A request that ended with all of its answer, as EntryPoints tells it.
      Since:
      1.11.0
      See Also:
    • FAILED

      public static final int FAILED
      A request that failed before all of its answer was given.
      Since:
      1.11.0
      See Also:
    • CANCELLED

      public static final int CANCELLED
      A request that the app cancelled.
      Since:
      1.11.0
      See Also:
  • Constructor Details

    • NativeApp

      public NativeApp()
      Creates an app whose site is named in META-INF/services/rife.engine.Site, or made by the SiteProvider named in META-INF/services/rife.nativeapp.SiteProvider. The system properties that start with rife.nativeapp. are its first properties.
      Since:
      1.11.0
    • NativeApp

      public NativeApp(Site site)
      Creates an app with the site that's given. The system properties that start with rife.nativeapp. are its first properties.
      Parameters:
      site - the site
      Since:
      1.11.0
  • Method Details

    • property

      public NativeApp property(String name, String value)
      Sets a property of the site, before its first request.
      Parameters:
      name - the name of the property
      value - its value
      Returns:
      this app
      Throws:
      IllegalStateException - when the site already started
      Since:
      1.11.0
    • runner

      public SiteRunner runner()
      Retrieves the runner of the site, which is started by the first call.
      Returns:
      the site runner
      Throws:
      RuntimeException - why the site couldn't start, every time
      Since:
      1.11.0
    • handle

      public void handle(long id, String url, String method, String headers, byte[] body, SiteResponseListener listener)
      Handles a request of the app. The listener is told the status and the headers once, the content as it's written, and once how the request ended. A request that the site couldn't handle at all is only told that it failed. Nothing is told after the end.
      Parameters:
      id - a number that no other request had before, to cancel(long) it by
      url - the address, either a path or an absolute address of the site, with its query string
      method - the request method, like GET
      headers - lines of a name, a colon and a value
      body - what was posted; or null
      listener - what's told of the response
      Since:
      1.11.0
    • cancel

      public void cancel(long id)
      Tells the site that nobody waits for the response of a request anymore.
      Parameters:
      id - the number that the request was handled with
      Since:
      1.11.0
    • stop

      public void stop()
      Stops the site, when it was started.
      Since:
      1.11.0
    • close

      public void close()
      Stops the site, when it was started, like stop().
      Specified by:
      close in interface AutoCloseable
      Since:
      1.11.0
    • headerLines

      public static String headerLines(SiteResponse response)
      The headers of a response as lines of a name, a colon and a value, without its cookies, which the site's cookie jar keeps.
      Parameters:
      response - the response
      Returns:
      the lines
      Since:
      1.11.0
    • main

      public static void main(String[] arguments)
      Asks the site for addresses on the JVM and says what it answered, to see what's wrong in seconds rather than after a native build. An argument -Dname=value sets a property of the site first, as the ask check of rife2-native-app does for a native library; so do the system properties that start with rife.nativeapp.. The system property rife.nativeapp.saved names a directory that gets every answer as a file.
      Parameters:
      arguments - the properties and the addresses
      Since:
      1.11.0