Package net.sf.basedb.core
Class Application
java.lang.Object
net.sf.basedb.core.Application
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) $
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
static class
APinger
is an object that is used to protect another object from timing out by automatically pinging it.private static class
static final class
Startup optins when starting the BASE application. -
Field Summary
Modifier and TypeFieldDescriptionprivate static boolean
Allow automatic unload of plug-in JAR files or not.private static Cleaner
For keeping track of objects that need to be cleaned up.private static String
The name and version of the database serverprivate static String
The name of the dynamic database.private static String
The name of the dynamic schema.private static String
The path to the file containing extended properties.private static String
The host name of the server running BASE.private static InternalJobQueue
The internal job queue reference if it is enabled.private static boolean
If BASE is running or not.private static final Logger
Log core events.private static boolean
If auto-compression has been enabled or not.private static int
Number of minutes permission information can be kept in memory before it must be reloaded.private static Set<Application.Pinger>
private static File
The one and only place where plug-ins can be installed.private static String
The path to the file containing predefined queries.private static String
The path to the file containing raw data types.private static Scheduler
An interface for adding timed task to the core timer.private static int
private static Map<String,
SessionControl> A cache of SessionControl objects.private static int
Number of minutes a SessionControl object can be unused before it is removed from the cache.private static StaticCache
Cache for static data.private static Timer
The core timer which schedules events.private static String
The title of the server.private static File
The directory where uploaded files are stored.private static ExtensionsManager
Manager for the extensions system. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Check if auto-compression has been enabled or not.(package private) static boolean
If external plug-in JAR files should automatically be unloaded if the are modified.private static void
cleanSessionControlCache
(boolean force) Clean the cache from unusedSessionControl
objects.static String
generateRandomId
(int bytes) Generate a random id.static int
getBuild()
Get the build number.(package private) static Timer
static String
Gets the version of the database server(package private) static String
Get the name of the dynamic catalog.(package private) static String
Get the name of the dynamic schema.Get the path to the XML file containing extended properties.static ExtensionsManager
static String
Get the host name of the server running BASE.(package private) static Logger
Get the BASE core logger.static int
Get the maintenance version.static int
Get the major version.static int
Get the minor version.static File
Get the directory where plug-ins and extensions must be installed.(package private) static String
Get the path to the XML file containing predefined queries for SQL and HQL.Get the path to the XML file containing raw data type definitions.static Scheduler
Get a scheduler that can be used for registeringTimerTask
for executions.static int
Get the current database schema version number.static SessionControl
getSessionControl
(String sessionControlId, String externalClientId, String remoteId, boolean checkLoggedIn) Get an existingSessionControl
object if you know the id.static StaticCache
Get the static cache mananger.static String
getTitle()
Get the "display title" of this server.static File
Get the path to the directory where uploaded files are stored.static String
Get the BASE version string.Get the version suffix (eg.static boolean
Check if BASE is running.static Application.Pinger
Create a newPinger
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 newSessionControl
object.static int
Get the maximum number of minutes permission information for a logged in user is kept in memory before beeing reloaded.static Cleaner.Cleanable
registerCleanup
(Object monitor, Runnable action) Register an action that needs to be performed when the monitored object becomes unreachable.static int
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) Deprecated.static void
start
(Application.StartupOptions options) Starts the BASE application.static void
stop()
Stops the BASE application.private static void
-
Field Details
-
log
Log core events. -
isRunning
private static boolean isRunningIf BASE is running or not. -
sessionCache
A cache of SessionControl objects. -
sessionCacheTimeout
private static int sessionCacheTimeoutNumber of minutes a SessionControl object can be unused before it is removed from the cache. -
timer
The core timer which schedules events. -
scheduler
An interface for adding timed task to the core timer. -
permissionTimeout
private static int permissionTimeoutNumber of minutes permission information can be kept in memory before it must be reloaded. -
userFilesDirectory
The directory where uploaded files are stored. -
pluginsDirectory
The one and only place where plug-ins can be installed. -
staticCache
Cache for static data. -
cleaner
For keeping track of objects that need to be cleaned up. -
queryFile
The path to the file containing predefined queries. -
extendedPropertiesFile
The path to the file containing extended properties. -
rawDataTypesFile
The path to the file containing raw data types. -
dynamicCatalog
The name of the dynamic database. -
dynamicSchema
The name of the dynamic schema. -
autoUnloadPlugins
private static boolean autoUnloadPluginsAllow automatic unload of plug-in JAR files or not. -
hostName
The host name of the server running BASE. -
title
The title of the server. -
internalJobQueue
The internal job queue reference if it is enabled. -
databaseVersionNumber
The name and version of the database server -
noAutoCompression
private static boolean noAutoCompressionIf auto-compression has been enabled or not. -
xtManager
Manager for the extensions system. -
schemaVersion
private static int schemaVersion -
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
Get the version suffix (eg. "-dev").- Since:
- 3.0
-
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
Get the BASE core logger. -
getHostName
Get the host name of the server running BASE. -
getTitle
Get the "display title" of this server. This can be configured in base.config via the 'app.title' setting.- Since:
- 3.12
-
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. -
start
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:
-
start
Deprecated.In BASE 3.18; usestart(StartupOptions)
insteadStarts 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
Starts the BASE application.- Parameters:
options
- Options for how BASE should be started- Throws:
BaseException
- If BASE cannot be started- See Also:
-
stop
Stops the BASE application. If BASE is not running this method does nothing.- Throws:
BaseException
- If BASE cannot be stopped- See Also:
-
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
Get the path to the directory where uploaded files are stored. -
registerCleanup
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 callCleaner.Cleanable.clean()
as soon as possible.- Returns:
- A cleanable, or null if the cleaner is not running
- Since:
- 3.16
- See Also:
-
getStaticCache
Get the static cache mananger.- Since:
- 2.11
-
getQueryFile
Get the path to the XML file containing predefined queries for SQL and HQL.- See Also:
-
getExtendedPropertyFiles
Get the path to the XML file containing extended properties.- See Also:
-
getRawDataTypeFiles
Get the path to the XML file containing raw data type definitions.- See Also:
-
getDynamicCatalog
Get the name of the dynamic catalog. -
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
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 theFile.setMimeTypeAuto(String, ItemSubtype)
and will automaically be compressed if auto-compression is enabled and theMimeType.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 newSessionControl
object. If BASE is not running it will be started.- Parameters:
externalClientId
- The external id for a registered client application, or null if not importantremoteId
- An optional parameter identifying the remote computer, for example the IP number. This should make it harder to hijack a login by guessing asessionControlId
.sessionControlId
- The id to give the newSessionControl
object, or null to generate a new id- Throws:
ItemNotFoundException
- If no client with the specified external id existsItemAlreadyExistsException
- If anotherSessionControl
with the given id already existsBaseException
- If there is another error- See Also:
-
newPluginSessionControl
static PluginSessionControl newPluginSessionControl(SessionControl parent, PluginDefinition plugin, Job job) Create a new session control for executing plugins.- Parameters:
parent
- The parent session controlplugin
- The plugin to executejob
- 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 existingSessionControl
object if you know the id.- Parameters:
sessionControlId
- The id of theSessionControl
objectexternalClientId
- The external id for a registered client application, or null if not importantremoteId
- If this parameter was passed to thenewSessionControl
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 asessionControlId
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 foundPermissionDeniedException
- If the remote or external client id is different from the remote/external client id that was passed when theSessionControl
object was createdNotLoggedInException
- If a user is not logged in when a check was requestedBaseException
- If there is another error- Since:
- 3.9
- See Also:
-
cleanSessionControlCache
private static void cleanSessionControlCache(boolean force) Clean the cache from unusedSessionControl
objects.- Parameters:
force
- If TRUE all objects will be removed from the cache regardless of if they are in use or not
-
generateRandomId
Generate a random id.- Parameters:
bytes
- The number of bytes of the id- Returns:
- The generated id represented as a hexadecimal string
-
getCoreTimer
-
getScheduler
Get a scheduler that can be used for registeringTimerTask
for executions. Each task that is added to the scheduler is executed in it's own thread.- Returns:
- A scheduler
-
newPinger
Create a newPinger
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
-
start(StartupOptions)
instead