Class ApplicationBean

java.lang.Object
helma.framework.core.ApplicationBean
All Implemented Interfaces:
Serializable

public class ApplicationBean extends Object implements Serializable
Application bean that provides a handle to the scripting environment to application specific functionality.
See Also:
  • Constructor Details

    • ApplicationBean

      public ApplicationBean(Application app)
      Creates a new ApplicationBean object.
      Parameters:
      app - ...
  • Method Details

    • clearCache

      public void clearCache()
      Clear the application cache.
    • getLogger

      public org.apache.commons.logging.Log getLogger()
      Get the app's event logger. This is a Log with the category helma.[appname].event.
      Returns:
      the app logger.
    • getLogger

      public org.apache.commons.logging.Log getLogger(String logname)
      Get the app logger. This is a commons-logging Log with the category logname.
      Returns:
      a logger for the given log name.
    • log

      public void log(Object msg)
      Log a INFO message to the app log.
      Parameters:
      msg - the log message
    • log

      public void log(String logname, Object msg)
      Log a INFO message to the log defined by logname.
      Parameters:
      logname - the name (category) of the log
      msg - the log message
    • debug

      public void debug(Object msg)
      Log a DEBUG message to the app log if debug is set to true in app.properties.
      Parameters:
      msg - the log message
    • debug

      public void debug(String logname, Object msg)
      Log a DEBUG message to the log defined by logname if debug is set to true in app.properties.
      Parameters:
      logname - the name (category) of the log
      msg - the log message
    • getRepositories

      public Object[] getRepositories()
      Returns the app's repository list.
      Returns:
      the an array containing this app's repositories
    • addRepository

      public void addRepository(Object obj)
      Add a repository to the app's repository list. The .zip extension is automatically added, if the original library path does not point to an existing file or directory.
      Parameters:
      obj - the repository, relative or absolute path to the library.
    • getClassLoader

      public ClassLoader getClassLoader()
      Get the app's classloader
      Returns:
      the app's classloader
    • countSessions

      public int countSessions()
      Return the number of currently active sessions
      Returns:
      the current number of active sessions
    • getSession

      public SessionBean getSession(String sessionID)
      Get a session object for the specified session id
      Parameters:
      sessionID - the session id
      Returns:
      the session belonging to the session id, or null
    • createSession

      public SessionBean createSession(String sessionID)
      Create a new session with the given session id
      Parameters:
      sessionID - the session id
      Returns:
      the newly created session
    • getSessions

      public SessionBean[] getSessions()
      Get an array of all active sessions
      Returns:
      an array of session beans
    • registerUser

      public INode registerUser(String username, String password)
      Register a user with the given name and password using the database mapping of the User prototype
      Parameters:
      username - the user name
      password - the user password
      Returns:
      the newly registered user, or null if we failed
    • getUser

      public INode getUser(String username)
      Get a user object with the given name
      Parameters:
      username - the user name
      Returns:
      the user object, or null
    • getActiveUsers

      public INode[] getActiveUsers()
      Get an array of currently active registered users
      Returns:
      an array of user nodes
    • getRegisteredUsers

      public INode[] getRegisteredUsers()
      Get an array of all registered users
      Returns:
      an array containing all registered users
    • getSessionsForUser

      public SessionBean[] getSessionsForUser(INode usernode)
      Get an array of all currently active sessions for a given user node
      Parameters:
      usernode - the user node
      Returns:
      an array of sessions for the given user
    • getSessionsForUser

      public SessionBean[] getSessionsForUser(String username)
      Get an array of all currently active sessions for a given user name
      Parameters:
      username - the user node
      Returns:
      an array of sessions for the given user
    • addCronJob

      public void addCronJob(String functionName)
      Add a cron job that will run once a minute
      Parameters:
      functionName - the function name
    • addCronJob

      public void addCronJob(String functionName, String year, String month, String day, String weekday, String hour, String minute)
      Add a cron job that will run at the specified time intervals
      Parameters:
      functionName - the function name
      year - comma separated list of years, or *
      month - comma separated list of months, or *
      day - comma separated list of days, or *
      weekday - comma separated list of weekdays, or *
      hour - comma separated list of hours, or *
      minute - comma separated list of minutes, or *
    • removeCronJob

      public void removeCronJob(String functionName)
      Unregister a previously registered cron job
      Parameters:
      functionName - the function name
    • getCronJobs

      public Map getCronJobs()
      Returns an read-only map of the custom cron jobs registered with the app
      Returns:
      a map of cron jobs
    • getCacheusage

      public int getCacheusage()
      Returns the number of elements in the NodeManager's cache
    • getData

      public INode getData()
      Returns the app's data node used to share data between the app's evaluators
      Returns:
      the app.data node
    • getModules

      public Map getModules()
      Returns the app's modules map used to register application modules
      Returns:
      the module map
    • getDir

      public String getDir()
      Returns the absolute path of the app dir. When using repositories this equals the first file based repository.
      Returns:
      the app dir
    • getName

      public String getName()
      Returns:
      the app name
    • getUpSince

      public Date getUpSince()
      Returns:
      the application start time
    • getRequestCount

      public long getRequestCount()
      Returns:
      the number of requests processed by this app
    • getXmlrpcCount

      public long getXmlrpcCount()
      Returns:
      the number of XML-RPC requests processed
    • getErrorCount

      public long getErrorCount()
      Returns:
      the number of errors encountered
    • get__app__

      public Application get__app__()
      Returns:
      the wrapped helma.framework.core.Application object
    • getProperties

      public Map getProperties()
      Get a wrapper around the app's properties
      Returns:
      a readonly wrapper around the application's app properties
    • getDbProperties

      public Map getDbProperties()
      Get a wrapper around the app's db properties
      Returns:
      a readonly wrapper around the application's db properties
    • getDbSource

      public DbSource getDbSource(String name)
      Return a DbSource object for a given name.
    • getAppsProperties

      public Map getAppsProperties()
      Get a wrapper around the app's apps.properties
      Returns:
      a readonly wrapper around the application's apps.properties
    • getPrototypes

      public Prototype[] getPrototypes()
      Get an array of this app's prototypes
      Returns:
      an array containing the app's prototypes
    • getPrototype

      public Prototype getPrototype(String name)
      Get a prototype by name.
      Parameters:
      name - the prototype name
      Returns:
      the prototype
    • getFreeThreads

      public int getFreeThreads()
      Get the number of currently available threads/request evaluators
      Returns:
      the currently available threads
    • getActiveThreads

      public int getActiveThreads()
      Get the number of currently active request threads
      Returns:
      the number of currently active threads
    • getMaxThreads

      public int getMaxThreads()
      Get the maximal thread number for this application
      Returns:
      the maximal number of threads/request evaluators
    • setMaxThreads

      public void setMaxThreads(int n)
      Set the maximal thread number for this application
      Parameters:
      n - the maximal number of threads/request evaluators
    • getSkin

      public Skin getSkin(String protoname, String skinname, Object[] skinpath)
      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.
    • getSkinfiles

      public Map getSkinfiles()
      Return a map of skin resources
      Returns:
      a map containing the skin resources
    • getSkinfilesInPath

      public Map getSkinfilesInPath(Object[] skinpath)
      Return a map of skin resources including the app-specific skinpath
      Parameters:
      skinpath - an array of directory paths or HopObjects to search for skins
      Returns:
      a map containing the skin resources
    • getAppDir

      public String getAppDir()
      Return the absolute application directory (appdir property in apps.properties file)
      Returns:
      the app directory as absolute path
    • getServerDir

      public String getServerDir()
      Return the absolute server directory
      Returns:
      the server directory as absolute path
    • getCharset

      public String getCharset()
      Return the app's default charset/encoding.
      Returns:
      the app's charset
    • setGlobalMacroPath

      public void setGlobalMacroPath(String[] path)
      Set the path for global macro resolution
      Parameters:
      path - an array of global namespaces, or null
    • getGlobalMacroPath

      public String[] getGlobalMacroPath()
      Get the path for global macro resolution
      Returns:
      an array of global namespaces, or null
    • invoke

      public Object invoke(Object thisObject, Object function, Object[] args) throws Exception
      Trigger a synchronous Helma invocation with a default timeout of 30 seconds.
      Parameters:
      thisObject - the object to invoke the function on, or null for global invokation
      function - the function or function name to invoke
      args - an array of arguments
      Returns:
      the value returned by the function
      Throws:
      Exception - exception thrown by the function
    • invoke

      public Object invoke(Object thisObject, Object function, Object[] args, long timeout) throws Exception
      Trigger a synchronous Helma invocation.
      Parameters:
      thisObject - the object to invoke the function on, or null for global invokation
      function - the function or function name to invoke
      args - an array of arguments
      timeout - the timeout in milliseconds. After waiting this long, we will try to interrupt the invocation
      Returns:
      the value returned by the function
      Throws:
      Exception - exception thrown by the function
    • invokeAsync

      public FutureResult invokeAsync(Object thisObject, Object function, Object[] args)
      Trigger an asynchronous Helma invocation. This method returns immedately with an object that allows to track the result of the function invocation with the following properties:
      • running - true while the function is running, false afterwards
      • result - the value returned by the function, if any
      • exception - the exception thrown by the function, if any
      • waitForResult() - wait indefinitely until invocation terminates and return the result
      • waitForResult(t) - wait for the specified number of milliseconds for invocation to terminate and return the result
      Parameters:
      thisObject - the object to invoke the function on, or null for global invokation
      function - the function or function name to invoke
      args - an array of arguments this long, we will try to interrupt the invocation
      Returns:
      an object with the properties described above
    • invokeAsync

      public FutureResult invokeAsync(Object thisObject, Object function, Object[] args, long timeout)
      Trigger an asynchronous Helma invocation. This method returns immedately with an object that allows to track the result of the function invocation with the following methods and properties:
      • running - true while the function is running, false afterwards
      • result - the value returned by the function, if any
      • exception - the exception thrown by the function, if any
      • waitForResult() - wait indefinitely until invocation terminates and return the result
      • waitForResult(t) - wait for the specified number of milliseconds for invocation to terminate and return the result
      Parameters:
      thisObject - the object to invoke the function on, or null for global invokation
      function - the function or function name to invoke
      args - an array of arguments
      timeout - the timeout in milliseconds. After waiting this long, we will try to interrupt the invocation
      Returns:
      an object with the properties described above
    • toString

      public String toString()
      Return a string presentation of this AppBean
      Overrides:
      toString in class Object
      Returns:
      string description of this app bean object