2.17.2: 2011-06-17

net.sf.basedb.core
Class Application

java.lang.Object
  extended by 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: 2010-10-07 08:48:16 +0200 (Thu, 07 Oct 2010) $

Nested Class Summary
private static class Application.DbCleaner
           
static class Application.Pinger
          A Pinger is an object that is used to protect another object from timing out by automatically pinging it.
private static class Application.SecondaryStorageControllerTask
           
private static class Application.SessionControlCacheCleaner
           
 
Field Summary
private static String authenticationDriver
          The name of the external authenication class, if any.
private static boolean autoUnloadPlugins
          Allow automatic unload of plug-in JAR files or not.
private static String databaseVersionNumber
          The name and version of the database server
private static String dynamicCatalog
          The name of the dynamic database.
private static String dynamicSchema
          The name of the dynamic schema.
private static String extendedPropertiesFile
          The path to the file containing extended properties.
private static String hostName
          The host name of the server running BASE.
private static InternalJobQueue internalJobQueue
          The internal job queue reference if it is enabled.
private static boolean isRunning
          If BASE is running or not.
private static Logger log
          Log core events.
private static LogManagerFactory logManagerFactory
          The log manager factory currently in use (may be null)
private static String logManagerFactoryDriver
          The name of the log manager factory class, if any.
private static boolean noAutoCompression
          If auto-compression has been enabled or not.
private static File nonCorePluginDirectory
          The directory where non-core plugins are located/installed.
private static int permissionTimeout
          Number of minutes permission information can be kept in memory before it must be reloaded.
private static Set<Application.Pinger> pingers
           
private static String queryFile
          The path to the file containing predefined queries.
private static String rawDataTypesFile
          The path to the file containing raw data types.
private static Scheduler scheduler
          An interface for adding timed task to the core timer.
private static String secondaryStorageDriver
          The name of the secondary storage controller class, if any.
private static Map<String,SessionControl> sessionCache
          A cache of SessionControl objects.
private static int sessionCacheTimeout
          Number of minutes a SessionControl object can be unused before it is removed from the cache.
private static StaticCache staticCache
          Cache for static data.
private static Timer timer
          The core timer which schedules events.
private static File userFilesDirectory
          The directory where uploaded files are stored.
 
Constructor Summary
Application()
           
 
Method Summary
static boolean autoCompressionEnabled()
          Check if auto-compression has been enabled or not.
(package private) static boolean autoUnloadPlugins()
          If external plug-in JAR files should automatically be unloaded if the are modified.
private static void cleanSessionControlCache(boolean force)
          Clean the cache from unused SessionControl objects.
static String generateRandomId(int bytes)
          Generate a random id.
(package private) static Authenticator getAuthenticator()
          Get an object of the class that is used for external authentication.
static int getBuild()
          Get the build number.
(package private) static Timer getCoreTimer()
           
static String getDatabaseVersionString()
          Gets the version of the database server
(package private) static String getDynamicCatalog()
          Get the name of the dynamic catalog.
(package private) static String getDynamicSchema()
          Get the name of the dynamic schema.
(package private) static List<String> getExtendedPropertyFiles()
          Get the path to the XML file containing extended properties.
static String getHostName()
          Get the host name of the server running BASE.
(package private) static Logger getLogger()
          Get the BASE core logger.
(package private) static LogManagerFactory getLogManagerFactory()
          Get the log manager factory, or null if not enabled.
static String getMaintenanceVersion()
          Get the maintenance version.
static String getMajorVersion()
          Get the major version.
static String getMinorVersion()
          Get the minor version.
static File getNonCorePluginDirectory()
          Get the directory where non-core plugins are located and installed
(package private) static String getQueryFile()
          Get the path to the XML file containing predefined queries for SQL and HQL.
(package private) static List<String> getRawDataTypeFiles()
          Get the path to the XML file containing raw data type definitions.
static Scheduler getScheduler()
          Get a scheduler that can be used for registering TimerTask for executions.
static int getSchemaVersion()
          Get the current database schema version number.
(package private) static SecondaryStorageController getSecondaryStorageController()
          Get an object of the class that is used for seconary storage handling.
static SessionControl getSessionControl(String sessionControlId, String remoteId)
          Get an existing SessionControl object if you know the id.
static StaticCache getStaticCache()
          Get the static cache mananger.
(package private) static File getUserFilesDirectory()
          Get the path to the directory where uploaded files are stored.
static String getVersionString()
          Get the BASE version string.
static boolean hasSecondaryStorage()
          Checks if the server has configured a secondary storage or not.
static boolean isRunning()
          Check if BASE is running.
static boolean isUsingInternalAuthentication()
          Check if BASE is using internal or external authentication.
static Application.Pinger newPinger(SessionControl sc)
          Create a new Pinger object that is used to keep a session control alive.
(package private) static PluginSessionControl newPluginSessionControl(SessionControl parent, PluginDefinition plugin, Job job)
          Create a new session control for executing plugins.
static SessionControl newSessionControl(String externalClientId, String remoteId, String sessionControlId)
          Create a new SessionControl object.
static int permissionTimeout()
          Get the maximum number of minutes permission information for a logged in user is kept in memory before beeing reloaded.
static int sessionCacheTimeout()
          Gets the maximum number of minutes before an active session is logged out.
static void start()
          Starts the BASE application.
static void start(boolean useInternalJobQueue)
          Starts the BASE application.
(package private) static void start(boolean installation, boolean verifySchemaVersion, Boolean useInternalJobQueue)
          Starts the BASE application.
static void stop()
          Stops the BASE application.
private static void stopPinger(Application.Pinger p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log
Log core events.


isRunning

private static boolean isRunning
If BASE is running or not.


authenticationDriver

private static String authenticationDriver
The name of the external authenication class, if any.


secondaryStorageDriver

private static String secondaryStorageDriver
The name of the secondary storage controller class, if any.


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.


staticCache

private static StaticCache staticCache
Cache for static data.


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.


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


nonCorePluginDirectory

private static File nonCorePluginDirectory
The directory where non-core plugins are located/installed.


noAutoCompression

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


logManagerFactoryDriver

private static String logManagerFactoryDriver
The name of the log manager factory class, if any.


logManagerFactory

private static LogManagerFactory logManagerFactory
The log manager factory currently in use (may be null)


pingers

private static Set<Application.Pinger> pingers
Constructor Detail

Application

public Application()
Method Detail

getMajorVersion

public static String getMajorVersion()
Get the major version.


getMinorVersion

public static String getMinorVersion()
Get the minor version.


getMaintenanceVersion

public static String getMaintenanceVersion()
Get the maintenance version.


getBuild

public static int getBuild()
Get the build number.


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 Logger getLogger()
Get the BASE core logger.


getHostName

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


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

public static void start(boolean useInternalJobQueue)
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

static void start(boolean installation,
                  boolean verifySchemaVersion,
                  Boolean useInternalJobQueue)
           throws BaseException
Starts the BASE application.

Parameters:
installation - TRUE if we are starting the application for installation, FALSE for a normal start
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()

isUsingInternalAuthentication

public static boolean isUsingInternalAuthentication()
Check if BASE is using internal or external authentication.

Returns:
TRUE if internal authentication is used, FALSE otherwise
See Also:
getAuthenticator()

getAuthenticator

static Authenticator getAuthenticator()
                               throws BaseException
Get an object of the class that is used for external authentication. The authenticator is initialised before it is returned. If internal authentication is used, this method returns null.

Returns:
An Authenticator object, or null if not using external authentication
Throws:
BaseException - If the authenticator class could not be loaded
See Also:
isUsingInternalAuthentication()

getLogManagerFactory

static LogManagerFactory getLogManagerFactory()
Get the log manager factory, or null if not enabled.

Since:
2.13

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

hasSecondaryStorage

public static boolean hasSecondaryStorage()
Checks if the server has configured a secondary storage or not.

Returns:
TRUE if a secondary storage is available, FALSE otherwise
See Also:
File.setLocation(Location)

getSecondaryStorageController

static SecondaryStorageController getSecondaryStorageController()
Get an object of the class that is used for seconary storage handling. The controller is initialised before it is returned. If no controller has been specified, this method returns null.

Returns:
A SecondaryStorageController object, or null if
Throws:
BaseException - If the controller class could not be loaded
See Also:
hasSecondaryStorage()

getUserFilesDirectory

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


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

getNonCorePluginDirectory

public static File getNonCorePluginDirectory()
Get the directory where non-core plugins are located and installed

Returns:
java.io.File A directory where the external plugins are located/installed, or null if not defined.
Since:
2.5

autoCompressionEnabled

public static boolean autoCompressionEnabled()
Check if auto-compression has been enabled or not. Files that are checked with the File.setMimeTypeAuto(String, FileType) 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 remoteId)
                                        throws ItemNotFoundException,
                                               BaseException
Get an existing SessionControl object if you know the id.

Parameters:
sessionControlId - The id of the SessionControl object
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
Returns:
The SessionControl object
Throws:
ItemNotFoundException - If an object with the specified id could not be found
PermissionDeniedException - If the remote id is different from the remote id that was passed when the SessionControl object was created
BaseException - If there is another error
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)

2.17.2: 2011-06-17