Package rife.nativeapp
Class NativeApp
java.lang.Object
rife.nativeapp.NativeApp
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionstatic final StringThe build number of the app.static final intA request that the app cancelled.static final intA request that ended with all of its answer, asEntryPointstells it.static final StringThe directory where the app keeps what should last, the cookies of the site among them.static final StringThe host that the site is at when the app doesn't give one.static final StringThe scheme that the site is at when the app doesn't give one.static final intA request that failed before all of its answer was given.static final StringThe host of the address that the web view has the site at.static final StringThe platform that the app runs on, likeios,macorandroid.static final StringThe scheme of the address that the web view has the site at.static final StringThe classpath directory of the script that the pages need inside an app, which a site runner only serves whenPLATFORM_PROPERTYis set.static final StringThe classpath directory that the static files of the site are served from, which is where an app puts itssrc/main/webapp.static final StringThe directory for temporary files, uploads among them, when the one of Java isn't one that the app may write in.static final StringThe version of the app.static final Stringtruewhen the app takes each answer all at once, on the thread that asked, like a web view of Android does. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an app whose site is named inMETA-INF/services/rife.engine.Site, or made by theSiteProvidernamed inMETA-INF/services/rife.nativeapp.SiteProvider.Creates an app with the site that's given. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel(long id) Tells the site that nobody waits for the response of a request anymore.voidclose()Stops the site, when it was started, likestop().voidhandle(long id, String url, String method, String headers, byte[] body, SiteResponseListener listener) Handles a request of the app.static StringheaderLines(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.static voidAsks 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.Sets a property of the site, before its first request.runner()Retrieves the runner of the site, which is started by the first call.voidstop()Stops the site, when it was started.
-
Field Details
-
PLATFORM_PROPERTY
The platform that the app runs on, likeios,macorandroid. When it's set, thecontext:nativeAppScriptvalue 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
The directory where the app keeps what should last, the cookies of the site among them.- Since:
- 1.11.0
- See Also:
-
SCHEME_PROPERTY
The scheme of the address that the web view has the site at.- Since:
- 1.11.0
- See Also:
-
HOST_PROPERTY
The host of the address that the web view has the site at.- Since:
- 1.11.0
- See Also:
-
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
The version of the app.- Since:
- 1.11.0
- See Also:
-
WHOLE_RESPONSES_PROPERTY
truewhen 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
The build number of the app.- Since:
- 1.11.0
- See Also:
-
DEFAULT_SCHEME
The scheme that the site is at when the app doesn't give one.- Since:
- 1.11.0
- See Also:
-
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
The classpath directory that the static files of the site are served from, which is where an app puts itssrc/main/webapp.- Since:
- 1.11.0
- See Also:
-
SCRIPT_RESOURCE_BASE
The classpath directory of the script that the pages need inside an app, which a site runner only serves whenPLATFORM_PROPERTYis 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 COMPLETEDA request that ended with all of its answer, asEntryPointstells it.- Since:
- 1.11.0
- See Also:
-
FAILED
public static final int FAILEDA request that failed before all of its answer was given.- Since:
- 1.11.0
- See Also:
-
CANCELLED
public static final int CANCELLEDA request that the app cancelled.- Since:
- 1.11.0
- See Also:
-
-
Constructor Details
-
NativeApp
public NativeApp()Creates an app whose site is named inMETA-INF/services/rife.engine.Site, or made by theSiteProvidernamed inMETA-INF/services/rife.nativeapp.SiteProvider. The system properties that start withrife.nativeapp.are its first properties.- Since:
- 1.11.0
-
NativeApp
Creates an app with the site that's given. The system properties that start withrife.nativeapp.are its first properties.- Parameters:
site- the site- Since:
- 1.11.0
-
-
Method Details
-
property
Sets a property of the site, before its first request.- Parameters:
name- the name of the propertyvalue- its value- Returns:
- this app
- Throws:
IllegalStateException- when the site already started- Since:
- 1.11.0
-
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, tocancel(long)it byurl- the address, either a path or an absolute address of the site, with its query stringmethod- the request method, likeGETheaders- lines of a name, a colon and a valuebody- what was posted; ornulllistener- 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, likestop().- Specified by:
closein interfaceAutoCloseable- Since:
- 1.11.0
-
headerLines
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
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=valuesets a property of the site first, as theaskcheck of rife2-native-app does for a native library; so do the system properties that start withrife.nativeapp.. The system propertyrife.nativeapp.savednames a directory that gets every answer as a file.- Parameters:
arguments- the properties and the addresses- Since:
- 1.11.0
-