Class Application

java.lang.Object
net.sf.basedb.core.Application

public final class Application
extends Object
This class represents the BASE application and is the starting point for all client applications. This class is used to start and stop the application, create SessionControl objects used for user authentication, etc.
Version:
2.0
Author:
Nicklas
Last modified
$Date: 2021-05-10 14:02:56 +0200 (Mon, 10 May 2021) $
  • Field Details

    • log

      private static final org.slf4j.Logger log
      Log core events.
    • isRunning

      private static boolean isRunning
      If BASE is running or not.
    • sessionCache

      private static Map<String,​SessionControl> sessionCache
      A cache of SessionControl objects.
    • sessionCacheTimeout

      private static int sessionCacheTimeout
      Number of minutes a SessionControl object can be unused before it is removed from the cache.
    • timer

      private static volatile Timer timer
      The core timer which schedules events.
    • scheduler

      private static volatile Scheduler scheduler
      An interface for adding timed task to the core timer.
    • permissionTimeout

      private static int permissionTimeout
      Number of minutes permission information can be kept in memory before it must be reloaded.
    • userFilesDirectory

      private static File userFilesDirectory
      The directory where uploaded files are stored.
    • pluginsDirectory

      private static File pluginsDirectory
      The one and only place where plug-ins can be installed.
    • staticCache

      private static StaticCache staticCache
      Cache for static data.
    • cleaner

      private static Cleaner cleaner
      For keeping track of objects that need to be cleaned up.
    • queryFile

      private static String queryFile
      The path to the file containing predefined queries.
    • extendedPropertiesFile

      private static String extendedPropertiesFile
      The path to the file containing extended properties.
    • rawDataTypesFile

      private static String rawDataTypesFile
      The path to the file containing raw data types.
    • dynamicCatalog

      private static String dynamicCatalog
      The name of the dynamic database.
    • dynamicSchema

      private static String dynamicSchema
      The name of the dynamic schema.
    • autoUnloadPlugins

      private static boolean autoUnloadPlugins
      Allow automatic unload of plug-in JAR files or not.
    • hostName

      private static String hostName
      The host name of the server running BASE.
    • title

      private static String title
      The title of the server.
    • internalJobQueue

      private static InternalJobQueue internalJobQueue
      The internal job queue reference if it is enabled.
    • databaseVersionNumber

      private static String databaseVersionNumber
      The name and version of the database server
    • noAutoCompression

      private static boolean noAutoCompression
      If auto-compression has been enabled or not.
    • xtManager

      private static ExtensionsManager xtManager
      Manager for the extensions system.
    • schemaVersion

      private static int schemaVersion
    • pingers

      private static Set<Application.Pinger> pingers
  • Constructor Details

    • Application

      public Application()
  • Method Details

    • getMajorVersion

      public static int getMajorVersion()
      Get the major version.
      Since:
      3.0 (was returning a String in 2.x)
    • getMinorVersion

      public static int getMinorVersion()
      Get the minor version.
      Since:
      3.0 (was returning a String in 2.x)
    • getMaintenanceVersion

      public static int getMaintenanceVersion()
      Get the maintenance version.
      Since:
      3.0 (was returning a String in 2.x)
    • getBuild

      public static int getBuild()
      Get the build number.
    • getVersionSuffix

      public String getVersionSuffix()
      Get the version suffix (eg. "-dev").
      Since:
      3.0
    • getVersionString

      public static String getVersionString()
      Get the BASE version string. It is created by combining the major, minor, maintenance, build and schema versions.
    • getSchemaVersion

      public static int getSchemaVersion()
      Get the current database schema version number.
      Returns:
      The schema version number, or -2 if a connection to the database couldn't be established, or -1 if schemaVersion could not be loaded
    • getLogger

      static org.slf4j.Logger getLogger()
      Get the BASE core logger.
    • getHostName

      public static String getHostName()
      Get the host name of the server running BASE.
    • getTitle

      public static String getTitle()
      Get the "display title" of this server. This can be configured in base.config via the 'app.title' setting.
      Since:
      3.12
    • getDatabaseVersionString

      public static String getDatabaseVersionString()
      Gets the version of the database server
      Returns:
      A String with the name and version number of the database server
      Since:
      2.3.1
    • isRunning

      public static boolean isRunning()
      Check if BASE is running.
      Returns:
      TRUE if BASE is running, FALSE otherwise
      See Also:
      start(), stop()
    • start

      public static void start() throws BaseException
      Starts the BASE application. This method will read settings from the configurations files and initialise all internal structures. Changes made to configuration files requires a restart to become effective. If BASE is already started this method does nothing.
      Throws:
      BaseException - If BASE cannot be started
      See Also:
      stop(), isRunning()
    • start

      @Deprecated public static void start​(boolean useInternalJobQueue)
      Deprecated.
      In BASE 3.18; use start(StartupOptions) instead
      Starts the BASE application. This method will read settings from the configurations files except if the internal job queue should be enabled or not.
      Parameters:
      useInternalJobQueue - If the internal job queue should be enabled or not
      Throws:
      BaseException - If BASE cannot be started
      See Also:
      start(), stop(), isRunning()
    • start

      public static void start​(Application.StartupOptions options) throws BaseException
      Starts the BASE application.
      Parameters:
      options - Options for how BASE should be started
      Throws:
      BaseException - If BASE cannot be started
      See Also:
      start()
    • stop

      public static void stop() throws BaseException
      Stops the BASE application. If BASE is not running this method does nothing.
      Throws:
      BaseException - If BASE cannot be stopped
      See Also:
      start(), isRunning()
    • getExtensionsManager

      public static ExtensionsManager getExtensionsManager()
    • permissionTimeout

      public static int permissionTimeout()
      Get the maximum number of minutes permission information for a logged in user is kept in memory before beeing reloaded.
      Returns:
      An integer with the number of minutes
    • sessionCacheTimeout

      public static int sessionCacheTimeout()
      Gets the maximum number of minutes before an active session is logged out.
      Returns:
      An integer with number of minutes
      Since:
      2.5
    • getUserFilesDirectory

      public static File getUserFilesDirectory()
      Get the path to the directory where uploaded files are stored.
    • registerCleanup

      public static Cleaner.Cleanable registerCleanup​(Object monitor, Runnable action)
      Register an action that needs to be performed when the monitored object becomes unreachable. NOTE! If this is going to work the action MUST NOT contain a reference to the monitor object (since then the monitor will never become unreachable). Note that there is no guarantee as to when the cleaning action is performed. There may be a long delay. For best performance it is recommended to explicitely call Cleaner.Cleanable.clean() as soon as possible.
      Returns:
      A cleanable, or null if the cleaner is not running
      Since:
      3.16
      See Also:
      Cleaner.register(Object, Runnable)
    • getStaticCache

      public static StaticCache getStaticCache()
      Get the static cache mananger.
      Since:
      2.11
    • getQueryFile

      static String getQueryFile()
      Get the path to the XML file containing predefined queries for SQL and HQL.
      See Also:
      PredefinedQuery
    • getExtendedPropertyFiles

      static List<String> getExtendedPropertyFiles()
      Get the path to the XML file containing extended properties.
      See Also:
      ExtendedProperties
    • getRawDataTypeFiles

      static List<String> getRawDataTypeFiles()
      Get the path to the XML file containing raw data type definitions.
      See Also:
      RawDataTypes
    • getDynamicCatalog

      static String getDynamicCatalog()
      Get the name of the dynamic catalog.
    • getDynamicSchema

      static String getDynamicSchema()
      Get the name of the dynamic schema.
    • autoUnloadPlugins

      static boolean autoUnloadPlugins()
      If external plug-in JAR files should automatically be unloaded if the are modified.
      Since:
      2.4
    • getPluginsDirectory

      public static File getPluginsDirectory()
      Get the directory where plug-ins and extensions must be installed.
      Returns:
      java.io.File A directory where the external plugins are located/installed
      Since:
      3.0
    • autoCompressionEnabled

      public static boolean autoCompressionEnabled()
      Check if auto-compression has been enabled or not. Files that are checked with the File.setMimeTypeAuto(String, ItemSubtype) and will automaically be compressed if auto-compression is enabled and the MimeType.getAutoCompress() returns TRUE.
      Returns:
      TRUE if auto-compression is enabled
      Since:
      2.5
    • newSessionControl

      public static SessionControl newSessionControl​(String externalClientId, String remoteId, String sessionControlId) throws BaseException
      Create a new SessionControl object. If BASE is not running it will be started.
      Parameters:
      externalClientId - The external id for a registered client application, or null if not important
      remoteId - An optional parameter identifying the remote computer, for example the IP number. This should make it harder to hijack a login by guessing a sessionControlId.
      sessionControlId - The id to give the new SessionControl object, or null to generate a new id
      Throws:
      ItemNotFoundException - If no client with the specified external id exists
      ItemAlreadyExistsException - If another SessionControl with the given id already exists
      BaseException - If there is another error
      See Also:
      SessionControl.getId()
    • newPluginSessionControl

      static PluginSessionControl newPluginSessionControl​(SessionControl parent, PluginDefinition plugin, Job job)
      Create a new session control for executing plugins.
      Parameters:
      parent - The parent session control
      plugin - The plugin to execute
      job - The job that executes the plug-in, or null
      Returns:
      The new plugin session control
    • getSessionControl

      public static SessionControl getSessionControl​(String sessionControlId, String externalClientId, String remoteId, boolean checkLoggedIn) throws ItemNotFoundException, BaseException
      Get an existing SessionControl object if you know the id.
      Parameters:
      sessionControlId - The id of the SessionControl object
      externalClientId - The external id for a registered client application, or null if not important
      remoteId - If this parameter was passed to the newSessionControl method, the same value must be passed here. Use, for example, the IP address of the client computer. This should make it harder to hijack a login by guessing a sessionControlId
      checkLoggedIn - TRUE to check if a user is logged in, FALSE to not check
      Returns:
      The SessionControl object
      Throws:
      ItemNotFoundException - If an object with the specified id could not be found
      PermissionDeniedException - If the remote or external client id is different from the remote/external client id that was passed when the SessionControl object was created
      NotLoggedInException - If a user is not logged in when a check was requested
      BaseException - If there is another error
      Since:
      3.9
      See Also:
      newSessionControl(String,String,String), SessionControl.getId()
    • cleanSessionControlCache

      private static void cleanSessionControlCache​(boolean force)
      Clean the cache from unused SessionControl objects.
      Parameters:
      force - If TRUE all objects will be removed from the cache regardless of if they are in use or not
    • generateRandomId

      public static String generateRandomId​(int bytes)
      Generate a random id.
      Parameters:
      bytes - The number of bytes of the id
      Returns:
      The generated id represented as a hexadecimal string
    • getCoreTimer

      static Timer getCoreTimer()
    • getScheduler

      public static Scheduler getScheduler()
      Get a scheduler that can be used for registering TimerTask for executions. Each task that is added to the scheduler is executed in it's own thread.
      Returns:
      A scheduler
    • newPinger

      public static Application.Pinger newPinger​(SessionControl sc)
      Create a new Pinger object that is used to keep a session control alive.
      Parameters:
      sc - The SessionControl that the pinger should protect
      Returns:
      A pinger object
      Since:
      2.4.5
    • stopPinger

      private static void stopPinger​(Application.Pinger p)