public abstract class WebApplication extends AbstractApplication implements SessionPoolProvider, SessionManagerProvider
Web applications usually run in a container such as glassfish or in case of JRuby/Rails in a pack of mongrels or a single webrick. Because we cannot make any assumptions about the threading model (single thread/single instance/single jvm as with JRuby/Webrick or full-blown multithreaded as in glassfish or half-way in between like JRuby with mongrel_jcluster) the WebAbstractApplication provides a logical Db-pool on top of multiplexed physical database connections. The initial size of the logical Db pool is 2 on 1 physical connection. This will not waste resources in single thread per JVM setups (like Rails/Webrick) but will dynamically grow otherwise.
Web applications need some mapping between sessions and
SessionInfo-objects that in turn carry the user id
and a SecurityManager. For the time of a web-roundtrip
a logical Db is picked from the pool and associated with that
user info (i.e. "session"). Notice that there may be more than
one session per user (but each gets its own user info). That's
why user infos are mapped by a session key object and not by
the user id. Furthermore, depending on the container's session
model, it is not sure that the container's session carries
the user id at all.
| Constructor and Description |
|---|
WebApplication(String name)
Creates an instance of a web application.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSession(Object sessionKey,
SessionInfo userInfo)
Adds a mapping between a session and a user info.
|
protected void |
configurePreferences() |
SessionPool |
createDbPool()
Creates the logical SessionPool.
|
ConnectionManager |
createSessionManager()
Creates the connection cache for the client sessions.
|
protected void |
doFinishStartup()
Finishes the startup.
The default implementation starts the modification thread, unless "--nomodthread" given, creates the connection cache, the Db pool,
and the DbServer instance. |
protected void |
doLogin()
Connects the server to the database backend.
|
protected void |
doStop(int exitValue)
Terminates the application server.
|
protected void |
doStop(int exitValue,
Exception ex)
Terminates the application server.
|
Db |
getDb(Object sessionKey)
Gets a logical db connection by a session key.
|
static WebApplication |
getInstance(Class<? extends WebApplication> clazz,
Properties props)
Gets the current web application instance or
starts a new instance if not already running.
|
SessionPool |
getSessionPool() |
static WebApplication |
getWebApplication()
Gets the current web application instance.
|
boolean |
isServer()
Returns whether the application is a server.
|
void |
putDb(Db db)
Release a logical db connection.
|
void |
removeSession(Object sessionKey)
Removes a mapping between a session and a user info.
|
void |
setSessionInfo(SessionInfo sessionInfo) |
void |
start(Properties props)
Starts the application.
|
void |
stop()
Gracefully terminates the web application server.
|
configurePdoTracker, configureSecurityManager, createDomainContext, createSession, createSessionInfo, detectContainer, detectJNLP, doConfigureApplication, doInitialize, getCreationTime, getDomainContext, getName, getProperties, getProperty, getRunningApplication, getSession, getSessionInfo, getUser, getUser, isDeployedByJNLP, isRunningInContainer, logStackdump, register, setDomainContext, setName, setProperties, toString, unregister, updateSessionInfoAfterLoginclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetSessionManageron, opnpublic WebApplication(String name)
name - the application namepublic static WebApplication getWebApplication()
This is just a convenience method to AbstractApplication.getRunningApplication().
public static WebApplication getInstance(Class<? extends WebApplication> clazz, Properties props) throws org.tentackle.misc.ApplicationException
Web containers should use this method to make sure that only one instance is started per JVM/classloader-context.
If the application runs in a container (tomcat, glassfish, etc...) additional properties may be appended/overwritten to/in the given props-argument. In web.xml add the following lines:
<env-entry>
<env-entry-name>tentackle.properties</env-entry-name>
<env-entry-value>../myapplication.properties</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
This will load the properties-file myapplication.properties from
the WEB-INF-directory (without "../" from WEB-INF/classes)
and modify the properties given by props.clazz - the application classprops - the properties to configure the applicationorg.tentackle.misc.ApplicationException - if failedpublic void setSessionInfo(SessionInfo sessionInfo)
Overwridden to protect the sessioninfo once it is set.
setSessionInfo in class AbstractApplicationpublic boolean isServer()
isServer in class AbstractApplicationprotected void configurePreferences()
configurePreferences in class AbstractApplicationpublic void addSession(Object sessionKey, SessionInfo userInfo)
sessionKey - the (unique) session keyuserInfo - the user infopublic void removeSession(Object sessionKey)
sessionKey - the (unique) session keypublic Db getDb(Object sessionKey)
sessionKey - the session keypublic void putDb(Db db)
db - the db to releasepublic void start(Properties props) throws org.tentackle.misc.ApplicationException
props - the properties to configure the applicationorg.tentackle.misc.ApplicationException - if startup failedAbstractApplication.setProperties(java.util.Properties)public void stop()
throws org.tentackle.misc.ApplicationException
org.tentackle.misc.ApplicationException - if termination failedpublic ConnectionManager createSessionManager()
public SessionPool createDbPool()
public SessionPool getSessionPool()
getSessionPool in interface SessionPoolProviderprotected void doLogin()
throws org.tentackle.misc.ApplicationException
org.tentackle.misc.ApplicationException - if login failedprotected void doFinishStartup()
throws org.tentackle.misc.ApplicationException
"--nomodthread" given, creates the connection cache, the Db pool,
and the DbServer instance.doFinishStartup in class AbstractApplicationorg.tentackle.misc.ApplicationException - if failedprotected void doStop(int exitValue,
Exception ex)
exitValue - the doStop value for System.exit()ex - an exception causing the termination, null if noneprotected void doStop(int exitValue)
exitValue - the doStop value for System.exit()Copyright © 2016 Krake Softwaretechnik. All rights reserved.