Class AbstractApplication

java.lang.Object
org.tentackle.app.AbstractApplication
All Implemented Interfaces:
Application, DomainContextProvider, SessionProvider
Direct Known Subclasses:
AbstractClientApplication

public abstract class AbstractApplication extends Object implements Application
Base class for all kinds of Tentackle applications.
Author:
harald
  • Field Details

    • DISABLE_MODIFICATION_TRACKER

      public static final String DISABLE_MODIFICATION_TRACKER
      Property to disable the modification tracker.
      See Also:
    • DISABLE_SECURITY_MANAGER

      public static final String DISABLE_SECURITY_MANAGER
      Property to disable the tentackle security manager.
      See Also:
    • ENABLE_STATISTICS

      public static final String ENABLE_STATISTICS
      Property to enable statistics.
      See Also:
    • SCRIPTING

      public static final String SCRIPTING
      Property to set the default scripting language.
      See Also:
    • LOCALE

      public static final String LOCALE
      Property to set the default locale.
      See Also:
  • Constructor Details

    • AbstractApplication

      public AbstractApplication(String name, String version)
      Super constructor for all derived classes.
      Detects whether application is running within a container or deployed by JNLP (webstart).
      Parameters:
      name - the application name, null for default name
      version - the application version, null for default version
      See Also:
  • Method Details

    • getName

      public String getName()
      Gets the application name.
      Specified by:
      getName in interface Application
      Returns:
      the name, never null
    • filterName

      protected String filterName(String name)
      Filters the application name.
      Parameters:
      name - the name given by the constructor
      Returns:
      the filtered name, never null
    • getVersion

      public String getVersion()
      Gets the application version.
      Specified by:
      getVersion in interface Application
      Returns:
      the version, never null
    • filterVersion

      protected String filterVersion(String version)
      Filters the application version.
      Parameters:
      version - the version given by the constructor
      Returns:
      the filtered version, never null
    • getCreationTime

      public long getCreationTime()
      Gets the creation time in epochal milliseconds.
      Specified by:
      getCreationTime in interface Application
      Returns:
      the creation time of this application
    • toString

      public String toString()
      Gets the application's name.
      Overrides:
      toString in class Object
      Returns:
      the name
    • getCommandLine

      public org.tentackle.misc.CommandLine getCommandLine()
      Gets the command line.
      Specified by:
      getCommandLine in interface Application
      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:
      isServer in interface Application
      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:
      isInteractive in interface Application
      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
    • applyProperties

      public void applyProperties(Properties properties)
      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 with SYSTEM_ or ^ followed by the property name.

      Other well-known properties that can be set:

      scripting=... sets the default scripting language

      nosecurity disables the tentackle security manager

      locale=... sets the default locale.

      Specified by:
      applyProperties in interface Application
      Parameters:
      properties - the properties, null if none
    • getProperty

      public String getProperty(String key)
      Description copied from interface: Application
      Gets an application property.
      Specified by:
      getProperty in interface Application
      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

      public String getPropertyIgnoreCase(String key)
      Description copied from interface: Application
      Gets an application property case-insensitive.
      Specified by:
      getPropertyIgnoreCase in interface Application
      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

      public char[] getPropertyAsChars(String key)
      Description copied from interface: Application
      Gets an application property as a character array.
      Useful for passwords and alike.
      Specified by:
      getPropertyAsChars in interface Application
      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

      public char[] getPropertyAsCharsIgnoreCase(String key)
      Description copied from interface: Application
      Gets an application property as a character array, case-insensitive.
      Useful for passwords and alike.
      Specified by:
      getPropertyAsCharsIgnoreCase in interface Application
      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

      public Session getSession()
      Specified by:
      getSession in interface SessionProvider
    • setDomainContext

      protected void setDomainContext(DomainContext context)
      Sets the domain context.
      Parameters:
      context - the context
    • getDomainContext

      public DomainContext getDomainContext()
      Gets the domain context.
      Specified by:
      getDomainContext in interface DomainContextProvider
      Returns:
      the domain context
    • getSessionInfo

      public SessionInfo getSessionInfo()
      Gets the session info.
      Specified by:
      getSessionInfo in interface Application
      Returns:
      the session info
    • setSessionInfo

      protected void setSessionInfo(SessionInfo sessionInfo)
      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 user
      password - is the password, null if none
      sessionPropertiesBaseName - the resource bundle basename of the property file, null if default
      Returns:
      the sessionInfo
    • createSession

      public Session createSession(SessionInfo sessionInfo)
      Creates a session.
      Parameters:
      sessionInfo - the session info
      Returns:
      the open session
    • createDomainContext

      public DomainContext createDomainContext(Session session)
      Creates the domain context.
      Override this method if the application uses a subclass of DomainContext.
      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.
    • 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()
      Do anything what's necessary after the connection has been established.
      The default creates the modification tracker (but does not start it), and configures the preferences and security manager.
    • finishStartup

      protected void finishStartup()
      Finishes the startup.
      The default implementation starts the modification tracker, unless the property "notracker" is given.
      The property "statistics" activates the statistics.
    • 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 from start(java.lang.String[]).
    • start

      public void start(String[] args)
      Description copied from interface: Application
      Starts the application.
      Specified by:
      start in interface Application
      Parameters:
      args - the arguments (usually from commandline), null or empty if none
    • stop

      public void stop(int exitValue, Throwable exitThrowable)
      Description copied from interface: Application
      Terminates the application with optional error handling.
      Specified by:
      stop in interface Application
      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 from stop(int, java.lang.Throwable)