Package helma.framework.core
Class Application
java.lang.Object
helma.framework.core.Application
- All Implemented Interfaces:
Runnable
The central class of a Helma application. This class keeps a pool of
request evaluators (threads with JavaScript interpreters), waits for
requests from the Web server or XML-RPC port and dispatches them to
the evaluators.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Vector
protected INode
boolean
protected long
protected Stack
Collections for evaluator thread poolingprotected NodeManager
protected long
protected SkinManager
The skin manager for this applicationThe type manager checks if anything in the application's prototype definitions has been updated prior to each evaluation.protected long
-
Constructor Summary
ConstructorsConstructorDescriptionApplication
(String name) Simple constructor for dead application instances.Application
(String name, Repository[] repositories, File dbDir) Build an application with the given name with the given sources.Application
(String name, Server server) Build an application with the given name and server instance.Application
(String name, Server server, Repository[] repositories, File customAppDir, File customDbDir) Build an application with the given name, server instance, sources and db directory. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addRepository
(Repository rep, Repository current) Add a repository to this app's repository list.boolean
authenticate
(String uname, String password) In contrast to login, this works outside the Hop user object framework.protected void
checkXmlRpcAccess
(String proto, String method) Check if a method may be invoked via XML-RPC on a prototype.void
Reset the application's object cache, causing all objects to be refetched from the database.correctPropertyName
(String propName) Returns the correct property name which is either case sensitive or case insensitiveint
int
int
int
int
Returns the number of currenty active sessions.int
createSession
(String sessionId) Return the session currently associated with a given Hop session ID.boolean
debug()
Tell other classes whether they should output logging information for this application.definePrototype
(String name, Map typeProps) Programmatically define a new prototype.execute
(RequestTrans req) Execute a request coming in from a web client.executeExternal
(String method, Vector args) executeXmlRpc
(String method, Vector args) Called to execute a method via XML-RPC, usally by helma.main.ApplicationManager which acts as default handler/request dispatcher.org.apache.commons.logging.Log
get the app's access log.int
Return the number of currently active threadsReturn a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing currently logged in users.Get the application directory.Returns the baseURI for Hrefs in this application.Return a transient node that is shared by all evaluators of this application ("app node")Returns a map of cache statisticsint
Returns the number of elements in the NodeManager's cacheReturn the name of the character encoding used by this applicationlong
Get a checksum that mirrors the state of this application in the sense that if anything in the applciation changes, the checksum hopefully will change, too.getChildElement
(Object obj, String name) Retrieve a child element of this object by name.Return the application's classloaderSet the code resource currently being evaluated/compiled.Get the current RequestEvaluator, or null if the calling thread is not evaluating a request.This method returns the root object of this application's object tree.protected Object
getDataRoot
(ScriptingEngine engine) This method returns the root object of this application's object tree.getDbMapping
(String typename) Get the DbMapping associated with a prototype name in this applicationGet the application's db propertiesgetDbSource
(String name) Return a DbSource object for a given name.getElementName
(Object obj) Return the name to be used to get this element from its parentlong
Returns a free evaluator to handle a request.org.apache.commons.logging.Log
get the app's event log.Returns the prototype name that Hrefs in this application should start with.getJavaClassForPrototype
(String typename) Return the java class that a given prototype wraps, or null.org.apache.commons.logging.Log
Get a logger object to log events for this application.getName()
Return the name of this applicationgetNodeHref
(Object elem, String actionName, Map queryParams) Return a path to be used in a URL pointing to the given element and actionReturns the node manager for this application.getParentElement
(Object obj) Return the parent element of this object.Get the application's app propertiesgetProperty
(String propname) Proxy method to get a property from the applications properties.getProperty
(String propname, String defvalue) Proxy method to get a property from the applications properties.getPrototype
(Object obj) Return a prototype for a given node.getPrototypeByName
(String name) Return the prototype with the given name, if it existsgetPrototypeName
(Object obj) Get the name of the prototype to be used for this object.Return a collection containing all prototypes defined for this applicationReturn a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing registered users of this application.Returns the repositories of this applicationint
Searches for the index of the given repository for this app.long
Get a comparator for comparing Resources according to the order of repositories they're contained in.Return the href to the root of this application.Return the id of the object to be used as this application's root objectReturn the prototype of the object to be used as this application's root objectReturn the directory of the Helma servergetSession
(String sessionId) Return the session currently associated with a given Hop session ID.Return the application's session managerReturn the whole session map.getSessionsForUsername
(String username) Return an array ofSessionBean
objects currently associated with a given Helma user.Return a skin for a given object.long
Return the current upload status.getUserNode
(String uid) Returns a Node representing a registered user of this application by his or her user name.Returns the Object which contains registered users of this application.Returns a wrapper containing the node manager for this application.long
Return the XML-RPC handler name for this app.boolean
Return true if the baseURI property is defined in the application properties, false otherwise.void
init()
Get the application ready to run, initializing the evaluators and type manager.void
Get the application ready to run, initializing the evaluators and type manager.boolean
isJavaPrototype
(String typename) Check whether a prototype is for scripting a java class, i.e.boolean
Returns true if this app is currently runningvoid
Log an application accessvoid
Log a generic application debug messagevoid
Log an application errorvoid
Log an application errorvoid
Log a generic application eventboolean
loginSession
(String uname, String password, Session session) Log in a user given his or her user name and password.void
logoutSession
(Session session) Log out a session from this application.void
Periodically called to log thread stats for this applicationregisterUser
(String uname, String password) Register a user with the given user name and password.void
Returns an evaluator back to the pool when the work is done.void
run()
The run method performs periodic tasks like executing the scheduler method and kicking out expired user sessions.void
setBaseURI
(String uri) This method sets the base URL of this application which will be prepended to the actual object path.void
setCurrentCodeResource
(Resource resource) Set the code resource currently being evaluated/compiled.protected void
Set the current RequestEvaluator for the calling thread.void
setDataRoot
(Object root) Set the application's root element to an arbitrary object.boolean
setNumberOfEvaluators
(int n) This can be used to set the maximum number of evaluators which will be allocated.void
start()
Create and start scheduler and cleanup threadvoid
stop()
This is called to shut down a running application.toString()
Return a string representation for this app.
-
Field Details
-
caseInsensitive
public boolean caseInsensitive -
nmgr
-
typemgr
The type manager checks if anything in the application's prototype definitions has been updated prior to each evaluation. -
skinmgr
The skin manager for this application -
freeThreads
Collections for evaluator thread pooling -
allThreads
-
cachenode
-
requestCount
protected volatile long requestCount -
xmlrpcCount
protected volatile long xmlrpcCount -
errorCount
protected volatile long errorCount
-
-
Constructor Details
-
Application
Simple constructor for dead application instances. -
Application
public Application(String name, Repository[] repositories, File dbDir) throws RemoteException, IllegalArgumentException Build an application with the given name with the given sources. No Server-wide properties are created or used. -
Application
Build an application with the given name and server instance. The app directories will be created if they don't exist already. -
Application
public Application(String name, Server server, Repository[] repositories, File customAppDir, File customDbDir) throws RemoteException, IllegalArgumentException Build an application with the given name, server instance, sources and db directory.
-
-
Method Details
-
init
public void init() throws DatabaseException, IllegalAccessException, InstantiationException, ClassNotFoundException, InterruptedExceptionGet the application ready to run, initializing the evaluators and type manager. -
init
public void init(String ignoreDirs) throws DatabaseException, IllegalAccessException, InstantiationException, ClassNotFoundException, InterruptedException Get the application ready to run, initializing the evaluators and type manager.- Parameters:
ignoreDirs
- comma separated list of directory names to ignore- Throws:
DatabaseException
IllegalAccessException
InstantiationException
ClassNotFoundException
InterruptedException
-
start
public void start()Create and start scheduler and cleanup thread -
stop
public void stop()This is called to shut down a running application. -
isRunning
public boolean isRunning()Returns true if this app is currently running- Returns:
- true if the app is running
-
getAppDir
Get the application directory.- Returns:
- the application directory, or first file based repository
-
getResourceComparator
Get a comparator for comparing Resources according to the order of repositories they're contained in.- Returns:
- a comparator that sorts resources according to their repositories
-
getEvaluator
Returns a free evaluator to handle a request. -
releaseEvaluator
Returns an evaluator back to the pool when the work is done. -
setNumberOfEvaluators
public boolean setNumberOfEvaluators(int n) This can be used to set the maximum number of evaluators which will be allocated. If evaluators are required beyound this number, an error will be thrown. -
getActiveThreads
public int getActiveThreads()Return the number of currently active threads -
execute
Execute a request coming in from a web client. -
executeXmlRpc
Called to execute a method via XML-RPC, usally by helma.main.ApplicationManager which acts as default handler/request dispatcher.- Throws:
Exception
-
executeExternal
- Throws:
Exception
-
clearCache
public void clearCache()Reset the application's object cache, causing all objects to be refetched from the database. -
getCacheUsage
public int getCacheUsage()Returns the number of elements in the NodeManager's cache -
getCacheStatistics
Returns a map of cache statistics -
setDataRoot
Set the application's root element to an arbitrary object. After this is called with a non-null object, the helma node manager will be bypassed. This function can be used to script and publish any Java object structure with Helma. -
getDataRoot
This method returns the root object of this application's object tree.- Throws:
Exception
-
getDataRoot
This method returns the root object of this application's object tree.- Throws:
Exception
-
getRootMapping
Return the prototype of the object to be used as this application's root object -
getRootId
Return the id of the object to be used as this application's root object -
getUserRoot
Returns the Object which contains registered users of this application. -
getNodeManager
Returns the node manager for this application. The node manager is the gateway to the helma.objectmodel packages, which perform the mapping of objects to relational database tables or the embedded database. -
getWrappedNodeManager
Returns a wrapper containing the node manager for this application. The node manager is the gateway to the helma.objectmodel packages, which perform the mapping of objects to relational database tables or the embedded database. -
getSessionManager
Return the application's session manager- Returns:
- the SessionManager instance used by this app
-
getCacheNode
Return a transient node that is shared by all evaluators of this application ("app node") -
getUserNode
Returns a Node representing a registered user of this application by his or her user name. -
getPrototype
Return a prototype for a given node. If the node doesn't specify a prototype, return the generic hopobject prototype. -
getPrototypeByName
Return the prototype with the given name, if it exists -
getPrototypes
Return a collection containing all prototypes defined for this application -
definePrototype
Programmatically define a new prototype. If a prototype with this name already exists return the existing prototype.- Parameters:
name
- the prototype nametypeProps
- custom type properties map- Returns:
- the new prototype
-
getSkin
Return a skin for a given object. The skin is found by determining the prototype to use for the object, then looking up the skin for the prototype.- Throws:
IOException
-
createSession
Return the session currently associated with a given Hop session ID. Create a new session if necessary. -
getActiveUsers
Return a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing currently logged in users. -
getRegisteredUsers
Return a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing registered users of this application. -
getSessionsForUsername
Return an array ofSessionBean
objects currently associated with a given Helma user. -
getSession
Return the session currently associated with a given Hop session ID. -
getSessions
Return the whole session map. -
countSessions
public int countSessions()Returns the number of currenty active sessions. -
registerUser
Register a user with the given user name and password. -
loginSession
Log in a user given his or her user name and password. -
logoutSession
Log out a session from this application. -
authenticate
In contrast to login, this works outside the Hop user object framework. Instead, the user is authenticated against a passwd file in the application directory. This is to have some sort of authentication available *before* the application is up and running, i.e. for application setup tasks. -
getRootHref
Return the href to the root of this application.- Returns:
- the root element's URL
- Throws:
UnsupportedEncodingException
- if the application's charset property is not a valid encoding name
-
getNodeHref
public String getNodeHref(Object elem, String actionName, Map queryParams) throws UnsupportedEncodingException Return a path to be used in a URL pointing to the given element and action- Parameters:
elem
- the object to get the URL foractionName
- an optional action namequeryParams
- optional map of query parameters- Returns:
- the element's URL
- Throws:
UnsupportedEncodingException
- if the application's charset property is not a valid encoding name
-
getBaseURI
Returns the baseURI for Hrefs in this application. -
setBaseURI
This method sets the base URL of this application which will be prepended to the actual object path. -
hasExplicitBaseURI
public boolean hasExplicitBaseURI()Return true if the baseURI property is defined in the application properties, false otherwise. -
getHrefRootPrototype
Returns the prototype name that Hrefs in this application should start with. -
debug
public boolean debug()Tell other classes whether they should output logging information for this application. -
getCurrentRequestEvaluator
Get the current RequestEvaluator, or null if the calling thread is not evaluating a request.- Returns:
- the RequestEvaluator belonging to the current thread
-
setCurrentRequestEvaluator
Set the current RequestEvaluator for the calling thread.- Parameters:
eval
- the RequestEvaluator belonging to the current thread
-
correctPropertyName
Returns the correct property name which is either case sensitive or case insensitive- Parameters:
propName
- the raw property name- Returns:
- the correct property name
-
getClassLoader
Return the application's classloader -
getElementName
Return the name to be used to get this element from its parent -
getChildElement
Retrieve a child element of this object by name. -
getParentElement
Return the parent element of this object. -
getPrototypeName
Get the name of the prototype to be used for this object. This will determine which scripts, actions and skins can be called on it within the Helma scripting and rendering framework. -
logError
Log an application error -
logError
Log an application error -
logEvent
Log a generic application event -
logDebug
Log a generic application debug message -
logAccess
Log an application access -
getEventLog
public org.apache.commons.logging.Log getEventLog()get the app's event log. -
getAccessLog
public org.apache.commons.logging.Log getAccessLog()get the app's access log. -
getLogger
Get a logger object to log events for this application. -
run
public void run()The run method performs periodic tasks like executing the scheduler method and kicking out expired user sessions. -
isJavaPrototype
Check whether a prototype is for scripting a java class, i.e. if there's an entry for it in the class.properties file. -
getJavaClassForPrototype
Return the java class that a given prototype wraps, or null. -
getDbSource
Return a DbSource object for a given name. A DbSource is a relational database defined in a db.properties file. -
getName
Return the name of this application -
addRepository
Add a repository to this app's repository list. This is used for ZipRepositories contained in top-level file repositories, for instance.- Parameters:
rep
- the repository to addcurrent
- the current/parent repository- Returns:
- if the repository was not yet contained
-
getRepositoryIndex
Searches for the index of the given repository for this app. The arguement must be a root argument, or -1 will be returned.- Parameters:
rep
- one of this app's root repositories.- Returns:
- the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
-
getRepositories
Returns the repositories of this application- Returns:
- iterator through application repositories
-
setCurrentCodeResource
Set the code resource currently being evaluated/compiled. This is used to set the proper parent repository when a new repository is added via app.addRepository().- Parameters:
resource
- the resource being currently evaluated/compiled
-
getCurrentCodeResource
Set the code resource currently being evaluated/compiled. This is used to set the proper parent repository when a new repository is added via app.addRepository().- Returns:
- the resource being currently evaluated/compiled
-
getServerDir
Return the directory of the Helma server -
getDbMapping
Get the DbMapping associated with a prototype name in this application -
getUploadStatus
Return the current upload status.- Parameters:
req
- the upload RequestTrans- Returns:
- the current upload status.
-
getChecksum
public long getChecksum()Get a checksum that mirrors the state of this application in the sense that if anything in the applciation changes, the checksum hopefully will change, too. -
getProperty
Proxy method to get a property from the applications properties. -
getProperty
Proxy method to get a property from the applications properties. -
getProperties
Get the application's app properties- Returns:
- the properties reflecting the app.properties
-
getDbProperties
Get the application's db properties- Returns:
- the properties reflecting the db.properties
-
getXmlRpcHandlerName
Return the XML-RPC handler name for this app. The contract is to always return the same string, even if it has been changed in the properties file during runtime, so the app gets unregistered correctly. -
toString
Return a string representation for this app. -
countThreads
public int countThreads() -
countEvaluators
public int countEvaluators() -
countFreeEvaluators
public int countFreeEvaluators() -
countActiveEvaluators
public int countActiveEvaluators() -
countMaxActiveEvaluators
public int countMaxActiveEvaluators() -
getRequestCount
public long getRequestCount() -
getXmlrpcCount
public long getXmlrpcCount() -
getErrorCount
public long getErrorCount() -
getStarttime
public long getStarttime()- Returns:
- ...
-
getCharset
Return the name of the character encoding used by this application- Returns:
- the character encoding
-
printThreadStats
public void printThreadStats()Periodically called to log thread stats for this application -
checkXmlRpcAccess
Check if a method may be invoked via XML-RPC on a prototype.- Throws:
Exception
-