Class Application<T extends BaseAppConfig>
- All Implemented Interfaces:
ConfigAware<T>
,ContextHandleAware
,HandleAware
,JsonDescriptorAware
,Loadable
- Direct Known Subclasses:
SystemApplication
- Since:
- 1.0
- Version:
- 2023-05-22
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLocalization
(ResolvedManifestSection section) Add all kabs in the section with a type ofkos.localization
to the associated localization context.void
Add a bean to the application context.Returns the base directory of the application.getAppFile
(String path) Adds the specified path to the base application directory and returns it as a File.getAppId()
Returns the ID of this application, which comes from the kos.app.appId field of the descriptor.json file.Retrieves the configuration bean.Returns the base directory of the application's core storage area.getCoreFile
(String path) Adds the specified path to the base application core directory and returns it as a File.getCtx()
Returns this applicaton's bean context.Returns the base directory of the application's local storage area.getDataFile
(String path) Adds the specified path to the base application data directory and returns it as a File.Returns the descriptor from this application's KAB file (descriptor.json).Returns the handle for this bean.Returns the prefix for the object to be used when the handle is allocated by the context.getKab()
Returns theKabFile
for the application KAB.Return theKeyValNameSpace
associated with the application.Return the loader that loaded the application.Return localization context for the app.Return the currently active node manifest for this node.Returns theResolvedManifestSection
associated with the application.getSection
(String name) Returns theResolvedManifestSection
with the specified name.getSectionsByNamePrefix
(String prefix) Return allResolvedManifestSection
with the specified name prefix.getVfs()
Returns the root VFS (virtual file system) for this application.boolean
hasProfile
(String profile) Profiles are constants that are defined by command-line arguments to the JVM.boolean
Return true if thestarted()
has returned.boolean
Return true if the app has been started.boolean
Return true if the app has been stopped.void
load()
Called fromAppLoader
when the application is first loaded.openDatabase
(String name, DatabaseMigrator migrator) Opens or creates a database with the specified name in the local storage area of the application.resolveAppBrowserIntent
(BrowserIntent intent) Override to processBrowserIntent
objects directed at this application.void
Sets the configuration bean.void
start()
Called fromAppLoader.start()
to notify the application is is being started.void
started()
Called afterstart()
returns.void
stop()
Called before the application is unloaded.void
unload()
Called when the application is being unloaded as a result of callingAppLoader.unload()
.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.service.config.ConfigAware
onConfigChanged, onConfigSet
Methods inherited from interface com.tccc.kos.commons.core.service.handle.HandleAware
addHandleChild, getName, getPath
-
Constructor Details
-
Application
public Application()
-
-
Method Details
-
getHandlePrefix
Description copied from interface:ContextHandleAware
Returns the prefix for the object to be used when the handle is allocated by the context. The prefix typically reflects the type of the object, such that two objects with the same name but different types are uniquely identified. This value should be the name of the getter if this object was to be fetched from a parent object. For example, if class was Pump there may be two instances: water and carb. The prefix for the water pump may be "water" while the prefix for carb may be "carb", as this distinguishes them. In cases where there is a single getter, it's not uncommon for the prefix to be the type of the object or null. The default implementation returns null.- Specified by:
getHandlePrefix
in interfaceContextHandleAware
-
getConfig
Retrieves the configuration bean.- Specified by:
getConfig
in interfaceConfigAware<T extends BaseAppConfig>
- Returns:
- the config bean
-
setConfig
Sets the configuration bean.- Specified by:
setConfig
in interfaceConfigAware<T extends BaseAppConfig>
-
getLoader
Return the loader that loaded the application. -
getCtx
Returns this applicaton's bean context.If this is the system app, then this context's parent is the kOS core context, and is the parent of all other applications. This allows the system app to easily expose resources to all other apps.
If this is not the system app, then this context is private to the application, and the parent context is the system app context. This allows resources to be exposed to various parts of the app using autowiring.
-
addToCtx
Add a bean to the application context.- Parameters:
bean
- the bean to add
-
getDescriptor
Returns the descriptor from this application's KAB file (descriptor.json). This provides easy access to the KAB file contents, allowing dotted notation access to individual fields or bean deserialization.- Specified by:
getDescriptor
in interfaceJsonDescriptorAware
-
getVfs
Returns the root VFS (virtual file system) for this application. The VFS controls which content is visible via the webserver, and each application is provided a base directory in the global VFS, which is /app/{appId}.The system app has a base direrctory of /system. There are many VFS components that can be used to export content to this path in the webserver. For more information check documentation for VFS.
-
getAppId
Returns the ID of this application, which comes from the kos.app.appId field of the descriptor.json file. -
getAppDir
Returns the base directory of the application. This is a read-only image of the application KAB contents mapped into the native filesystem. Contents of the KAB can be access directly from the KAB usinggetKab()
, or directly from the filesystem. Since the KAB contents are visible in the native filesystem, it is possible to package native binaries in a KAB and run them from the mounted filesystem. -
getAppFile
Adds the specified path to the base application directory and returns it as a File. This is a convenience method to convert relative paths to files within the application space.- Parameters:
path
- the relative path
-
getDataDir
Returns the base directory of the application's local storage area. This area is used by the application for any local storage needs, and is isolated from other applications.Application data is inherently nodeType specific and switching the nodeType of a board will cause it to use a new data directory. This is generally the preferred area to store data. In the event a board is removed from one device and used as a different nodeType in a different device, data from the original node type generally causes issues. Anything stored in the application data dir will not spill over across node types.
If there is a need to store data that spans node types on a given board, use
getCoreDir()
as this data area will remain the same regardless of nodeType of the board. This should only be used in very limited and special cases related to board reuse. -
getDataFile
Adds the specified path to the base application data directory and returns it as a File. This is a convenience method that converts relative paths to files within the application space.- Parameters:
path
- the relative path
-
getCoreDir
Returns the base directory of the application's core storage area. Core storage remains the same regardless of the nodeType of the board. This storage area should only be used for very limited use cases, such as storing a device birth cert that should be used the entire life of the board even if it's moved from device to device. Do not use this a the primary storage area for your application data. -
getCoreFile
Adds the specified path to the base application core directory and returns it as a File. This is a convenience method that converts relative paths to files within the application core space.Please see notes for
getCoreDir()
regarding the use of core space vs data space. In most cases data space should be used to store application data.- Parameters:
path
- the relative path
-
getKab
Returns theKabFile
for the application KAB. This allows direct access to the contents of the KAB, including its header information. -
getSection
Returns theResolvedManifestSection
associated with the application. This is the manifest section that is provided when the application is loaded. If no section was specified, then this is null.This provides access to related KAB files for the application to operate on, and provides a mechanism to enumerate and search the section for other related KABs.
-
getSection
Returns theResolvedManifestSection
with the specified name. This provides access to KAB files in the section. -
getSectionsByNamePrefix
Return allResolvedManifestSection
with the specified name prefix. -
getNodeManifest
Return the currently active node manifest for this node. -
getLocalization
Return localization context for the app. -
addLocalization
Add all kabs in the section with a type ofkos.localization
to the associated localization context.- Parameters:
section
- the section to examine
-
getKeyVal
Return theKeyValNameSpace
associated with the application. This provides simple key/val storage that is backed by the coreKeyValService
within kos. The applicationKeyValNameSpace
will be namespaced to the app id. TheKeyValNameSpace
is also part of the application context so it can be autowired into anything that has access to the application context. -
openDatabase
Opens or creates a database with the specified name in the local storage area of the application. The supplied migrator is used to create and/or migrate the database to the latest schema before theJdbi
wrapper is returned.If a single DAO is used, it can implement
DatabaseMigrator
and rely on theJdbi
instance injected after migration is complete. If multiple DAO's exist for the database, then the returnedJdbi
instance can be used to create the various DAO's.The
DatabaseMigrator
controls much of the database policy such as forward migration, how to handle rollback to a previous schema, and how many previous schema revisions to maintain. Check theDatabaseMigrator
documentation for more information.- Parameters:
migrator
- used to migrate the databasename
- the name of the database- Returns:
- the resulting
Jdbi
instance
-
resolveAppBrowserIntent
Override to processBrowserIntent
objects directed at this application. This allows applications to process intents without the need to implementBrowserIntentResolver
and filter out intents specific to this application.To generate an intent for an application, use
AppBrowserIntent()).
param intent the intent to resolve -
load
Called fromAppLoader
when the application is first loaded. This should be used for application initialization, however the application should not begin operation untilstart()
is called.When this method returns, the application context is updated, which triggers any pending autowiring. Any configurable objects added to the context are also configured. This allows these objects to be used in
start()
, knowing they are autowired and configured. -
start
Called fromAppLoader.start()
to notify the application is is being started. Any objects added to the context duringload()
will be autowired and configured before this is called. Once this returns, the application is considered to be running. Until an application is started, any associated endpoints are not accessible. This prevents the application from being used when it is not running.Once started, an application may be unloaded by calling
AppLoader.unload()
. -
started
Called afterstart()
returns. When this is called, all application vfs and endpoints are available for use. It is now safe to notify other systems that the application endpoints and content can be used.Override as needed.
-
stop
Called before the application is unloaded. When this is called, endpoints and vfs content has been disabled, but not yet unmounted.Override as needed.
-
unload
Called when the application is being unloaded as a result of callingAppLoader.unload()
. This must clean up all resources and references to allow the app class loader to be garbage collected.Override as needed.
-
hasProfile
Profiles are constants that are defined by command-line arguments to the JVM. This provides access to the list of profiles provided at startup, and returns true if the named profile is in the profile list. This is used to change behavior of an application based on a command-line argument.- Parameters:
profile
- the profile to check
-
isStarted
public boolean isStarted()Return true if the app has been started. This will become true just before the applicationstarted()
callback is called. Afterstarted()
returns,postStarted
will be true. -
isPostStarted
public boolean isPostStarted()Return true if thestarted()
has returned. This indicates the app is completely functional. -
isStopped
public boolean isStopped()Return true if the app has been stopped. -
getHandle
Description copied from interface:HandleAware
Returns the handle for this bean. This is used by the context to compute the opaque handle for the object.- Specified by:
getHandle
in interfaceHandleAware
- Returns:
- the handle node for the bean
-