Class AbstractApplication
- All Implemented Interfaces:
Application, DomainContextProvider, SessionProvider
- Direct Known Subclasses:
AbstractClientApplication
- Author:
- harald
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty to disable the modification tracker.static final StringProperty to disable the tentackle security manager.static final StringProperty to enable statistics.static final StringProperty to set the default locale.static final StringProperty to set the default scripting language. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractApplication(String name, String version) Super constructor for all derived classes.
Installs a default uncaught exception handler that logs the exception. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidActivate statistics.
Recommended during development.voidapplyProperties(Properties properties) Applies the given properties.
If the given properties are different from the application properties, they will be copied to the application properties.protected voidcleanup()Cleans up resources.
Invoked fromstop(int, java.lang.Throwable)protected voidDoes whatever is necessary after the connection has been established.
The default implementation configures the modification tracker (but does not start it), the preferences and the security manager.protected voidConfigures the modification tracker singleton.protected voidConfigures the preferences.protected voidConfigures the security manager.
The default implementation enables the security manager, unless the property"nosecurity"is given.createDomainContext(Session session) Creates the domain context.
The context is created viaPdo.createDomainContext(Session, boolean)with an immutable session, i.e., by theDomainContextFactory, which is the recommended way to provide an application-specific context.createSession(SessionInfo sessionInfo) Creates a session.createSessionInfo(String username, char[] password, String sessionPropertiesBaseName) Creates the sessionInfo.
Presets the attributes like locale, timezone, vm-, os- and host-info.protected StringfilterName(String name) Filters the application name.protected StringfilterVersion(String version) Filters the application version.protected voidFinishes the startup.
The default implementation: activates the statistics, if the property"statistics"is given, preloads the caches (seepreloadCaches()) and starts the modification tracker, unless the property"notracker"is given, which disables all PDO caches instead, and, if this is a server, waits until the caches are preloaded.org.tentackle.misc.CommandLineGets the command line.longGets the creation time in epoch milliseconds.Gets the domain context.getName()Gets the application name.protected org.tentackle.common.EncryptedPropertiesGets the current properties.getProperty(String key) Gets an application property.char[]getPropertyAsChars(String key) Gets an application property as a character array.
Useful for passwords and alike.char[]Gets an application property as a character array, case-insensitive.
Useful for passwords and alike.Gets an application property case-insensitive.Gets the session info.Gets the application version.protected voidInitializes the application.
This is the first step when an application is launched.protected voidInitializes the scripting.booleanReturns whether the running application is interactive.protected booleanisPropertySet(String key) Returns whether a property is set, regardless of its value.
The key is case-insensitive.booleanisServer()Returns whether the application is a server.protected booleanReturns whether System.exit() must be invoked to stop the application.voidLogs a stackdump.voidLogs and clears the statistics.protected CountDownLatchPreloads the caches.
Invoked fromfinishStartup()after initializing the modification tracker.protected voidsetDomainContext(DomainContext context) Sets the domain context.protected voidsetProperties(org.tentackle.common.EncryptedProperties props) Sets the properties to configure the application.protected voidsetSessionInfo(SessionInfo sessionInfo) Sets the session info.voidStarts the application.protected abstract voidstartup()Invokes all steps to start up the application.
Invoked fromstart(java.lang.String[]).voidTerminates the application with optional error handling.toString()Gets the application's name.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Application
getUser, register, start, stop, unregisterMethods inherited from interface DomainContextProvider
isWithinContext, isWithinContext, on, on, op, op
-
Field Details
-
DISABLE_MODIFICATION_TRACKER
Property to disable the modification tracker.- See Also:
-
DISABLE_SECURITY_MANAGER
Property to disable the tentackle security manager.- See Also:
-
ENABLE_STATISTICS
-
SCRIPTING
-
LOCALE
-
-
Constructor Details
-
AbstractApplication
Super constructor for all derived classes.
Installs a default uncaught exception handler that logs the exception.- Parameters:
name- the application name, null for default nameversion- the application version, null for default version- See Also:
-
-
Method Details
-
getName
Gets the application name.- Specified by:
getNamein interfaceApplication- Returns:
- the name, never null
-
filterName
-
getVersion
Gets the application version.- Specified by:
getVersionin interfaceApplication- Returns:
- the version, never null
-
filterVersion
-
getCreationTime
public long getCreationTime()Gets the creation time in epoch milliseconds.- Specified by:
getCreationTimein interfaceApplication- Returns:
- the creation time of this application
-
toString
-
getCommandLine
public org.tentackle.misc.CommandLine getCommandLine()Gets the command line.- Specified by:
getCommandLinein interfaceApplication- Returns:
- the commandline, null if not started
-
logStackdump
public void logStackdump()Logs a stackdump.The logging level used is INFO.
Can be used for example from a groovy console at runtime. -
isServer
public boolean isServer()Returns whether the application is a server.- Specified by:
isServerin interfaceApplication- Returns:
- true if server, false if a client or nothing of both
-
isInteractive
public boolean isInteractive()Returns whether the running application is interactive.- Specified by:
isInteractivein interfaceApplication- Returns:
- true if interaction with user, false if server, daemon or whatever
-
setProperties
protected void setProperties(org.tentackle.common.EncryptedProperties props) Sets the properties to configure the application.Must be set before starting the application.
- Parameters:
props- the properties to configure the application
-
getProperties
protected org.tentackle.common.EncryptedProperties getProperties()Gets the current properties.- Returns:
- the properties
-
isPropertySet
Returns whether a property is set, regardless of its value.
The key is case-insensitive.- Parameters:
key- the property key- Returns:
- true if set
-
applyProperties
Applies the given properties.
If the given properties are different from the application properties, they will be copied to the application properties.The default implementation first parses the properties for system properties and replaces any system properties according to
StringHelper.evaluate(String, Function).
System properties start withSYSTEM_or^followed by the property name.Other well-known properties that can be set:
scripting=...sets the default scripting languagenosecuritydisables the tentackle security managerlocale=...sets the default locale.- Specified by:
applyPropertiesin interfaceApplication- Parameters:
properties- the properties, null if none
-
getProperty
Description copied from interface:ApplicationGets an application property.- Specified by:
getPropertyin interfaceApplication- Parameters:
key- the property's name- Returns:
- the value of the key, null if no such property, the empty string if no value for this property
-
getPropertyIgnoreCase
Description copied from interface:ApplicationGets an application property case-insensitive.- Specified by:
getPropertyIgnoreCasein interfaceApplication- Parameters:
key- the property's name- Returns:
- the value of the key, null if no such property, the empty string if no value for this property
-
getPropertyAsChars
Description copied from interface:ApplicationGets an application property as a character array.
Useful for passwords and alike.- Specified by:
getPropertyAsCharsin interfaceApplication- Parameters:
key- the property's name- Returns:
- the value of the key, null if no such property, the empty array if no value for this property
-
getPropertyAsCharsIgnoreCase
Description copied from interface:ApplicationGets an application property as a character array, case-insensitive.
Useful for passwords and alike.- Specified by:
getPropertyAsCharsIgnoreCasein interfaceApplication- Parameters:
key- the property's name- Returns:
- the value of the key, null if no such property, the empty array if no value for this property
-
getSession
- Specified by:
getSessionin interfaceSessionProvider
-
setDomainContext
Sets the domain context.- Parameters:
context- the context
-
getDomainContext
Gets the domain context.- Specified by:
getDomainContextin interfaceDomainContextProvider- Returns:
- the domain context
-
getSessionInfo
Gets the session info.- Specified by:
getSessionInfoin interfaceApplication- Returns:
- the session info
-
setSessionInfo
Sets the session info.- Parameters:
sessionInfo- the session info
-
createSessionInfo
public SessionInfo createSessionInfo(String username, char[] password, String sessionPropertiesBaseName) Creates the sessionInfo.
Presets the attributes like locale, timezone, vm-, os- and host-info.- Parameters:
username- is the name of the userpassword- is the password, null if nonesessionPropertiesBaseName- the resource bundle basename of the property file, null if default- Returns:
- the sessionInfo
-
createSession
Creates a session.- Parameters:
sessionInfo- the session info- Returns:
- the open session
-
createDomainContext
Creates the domain context.
The context is created viaPdo.createDomainContext(Session, boolean)with an immutable session, i.e., by theDomainContextFactory, which is the recommended way to provide an application-specific context. For remote sessions, the user's ID, class ID, and name are taken from the server's view of the session.- Parameters:
session- the session, null if thread-local- Returns:
- the domain context
-
configureModificationTracker
protected void configureModificationTracker()Configures the modification tracker singleton. -
configurePreferences
protected void configurePreferences()Configures the preferences.If the property
"readonlyprefs"is set, any write attempt to the preferences will be silently ignored.
The property"noprefsync"turns off preferences auto sync between jvms.
The property"systemprefs"restricts to system preferences. Default is user and system prefs. -
configureSecurityManager
protected void configureSecurityManager()Configures the security manager.
The default implementation enables the security manager, unless the property"nosecurity"is given. -
initialize
protected void initialize()Initializes the application.
This is the first step when an application is launched. -
initializeScripting
protected void initializeScripting()Initializes the scripting. -
configure
protected void configure()Does whatever is necessary after the connection has been established.
The default implementation configures the modification tracker (but does not start it), the preferences and the security manager. -
finishStartup
protected void finishStartup()Finishes the startup.
The default implementation:- activates the statistics, if the property
"statistics"is given, - preloads the caches (see
preloadCaches()) and starts the modification tracker, unless the property"notracker"is given, which disables all PDO caches instead, - and, if this is a server, waits until the caches are preloaded.
- activates the statistics, if the property
-
preloadCaches
Preloads the caches.
Invoked fromfinishStartup()after initializing the modification tracker.- Returns:
- a countdown latch that can be used to wait for the preload to finish, null if preloaded synchronously
-
activateStatistics
protected void activateStatistics()Activate statistics.
Recommended during development. -
logStatistics
public void logStatistics()Logs and clears the statistics. -
startup
protected abstract void startup()Invokes all steps to start up the application.
Invoked fromstart(java.lang.String[]). -
start
Description copied from interface:ApplicationStarts the application.- Specified by:
startin interfaceApplication- Parameters:
args- the arguments (usually from commandline), null or empty if none
-
stop
Description copied from interface:ApplicationTerminates the application with optional error handling.- Specified by:
stopin interfaceApplication- Parameters:
exitValue- the stop value for System.exit()exitThrowable- an exception causing the termination, null if none
-
isSystemExitNecessaryToStop
protected boolean isSystemExitNecessaryToStop()Returns whether System.exit() must be invoked to stop the application.- Returns:
- true if JVM must be terminated
-
cleanup
protected void cleanup()Cleans up resources.
Invoked fromstop(int, java.lang.Throwable)
-