creamtec.webcream.core
Class ClientAgent

java.lang.Object
  extended by creamtec.webcream.core.ClientAgent
All Implemented Interfaces:
ClientAgentRemote, java.rmi.Remote
Direct Known Subclasses:
ServletHelper.InProcessClientAgent

public class ClientAgent
extends java.lang.Object
implements ClientAgentRemote

Main class within the client process/virtual process. The agent is responsible for loading the client starting class, executing it's main function, and responding to request to process Http requests. It also emulates user actions for the running client process and acts as a main point of contact and coordination of the client application. Client Agent can execute in within a shared JVM or as a stand alone process, in which case it makes itself available through RMI.

Each user, that connects to the WebCream enabled application, receives his own instance of the client agent.


Nested Class Summary
static class ClientAgent.InitLock
          Synchronizes the initialization of the JVM
static class ClientAgent.OperationLock
          Synchronizes the processing of a user-defined operation.
static class ClientAgent.RequestLock
          Syncrhonizes the processing of a request.
 
Field Summary
static boolean shuttingDown
           
static boolean useWebCreamFontsConfigFile
           
 
Constructor Summary
ClientAgent(java.lang.String agentName, java.lang.String appName)
          Initializes the client agent
 
Method Summary
 void addBlockedThread(WebCreamThread thread)
          Adds the given thread to the list of blocked threads within the clinet.
 boolean allowExit()
          Checks if System.exit() is allowed to shutdown the JVM
 void beginOperation()
          Begins a custom operation
 void doRun()
          Does the job of running the client application
 void emulateRequest(HttpRequestData data)
          Emulates the given request and action, as though triggered by the application user The action is executed on a separate threads, and all threads, spawned from the emulation thread are monitored for their state.
 void endOperation()
          Marks an end of custom operation
 void exit()
          Safe shutdown of JVM.
 java.lang.String getAppName()
          Returns application name
 int getBrowserID()
          Returns the browser ID of the user, that the client agent is associated with
 float getBrowserVersion()
          Returns the browser version of the user, that the client agent is associated with
 java.lang.ClassLoader getClassLoader()
          Returns the class loader used to load the classes of this virtual client
 int getClientId()
          Returns agent name
static ClientAgent getCurrentInstance()
          Returns the instance of ClientAgent, associated with the calling thread May not work correctly in a multi threaded application
 AbstractDocumentRenderer getDocumentRenderer()
          Returns the instance of PageRenderer, associated with this client
 java.awt.EventQueue getEventQueue()
          Used to retrieve the virtual user specific AWT event queue
 java.lang.Throwable getException()
          Returns the exception cought while processing a request
 HTMLPage getHTMLPage()
          Returns HTML Page, associated with this client
 AgentInitData getInitData()
          Returns application initialization data
 java.awt.Dimension getMaximumWindowSize(java.awt.Window window)
           
 java.lang.Object getOperationLock()
          Used to control multithreaded applications
 WebCreamProperties getProps()
          Returns the application initialization properties
 HttpRequestData getRequestData()
          Returns data received from the browser
 AgentRequestFilter getRequestFilter()
          Returns request filter instance or null
 long getRequestId()
          Each request increments the id
 HttpResponseData getResponseData()
          Returns data received from the browser
 java.util.HashMap getSession()
          Returns the session map associated with the client.
 java.util.List getTempFiles()
          Client agent stores the temporary files created for the user They are automatically deleted when the agent is shutdown
 WebCreamUIManager getUIManager()
          Returns the instance of UIManager, associated with this client
 WebCreamThreadGroup getWebCreamThreadGroup()
          Returns the thread group that owns all threads of this agent
 java.lang.String getWindowProperty(java.lang.String windowTitle, java.lang.String property)
          Looks up and returns the value of the property if set for a window with the given title
 WindowUpdater getWindowUpdater()
          Returns the instance of WindowUpdater, associated with this client
 void init(AgentInitData data)
          Completes client initialization by storing the data.
 void initProperties(java.lang.String appName)
          Initializes generic properties and variables of the client agent that do not depend on the specific application configuration
static void installExitTrap()
          Installs the security manager to intercept System.exit() attempts.
static void installToolkit()
          Installs AWT toolkit.
 boolean isApplet()
          Can be used to test if the application is running as an applet
 boolean isOperationActive()
          Operations can be defined using the application properties file to fine tune a multithreaded application
 boolean isRequestActive()
          Can be used to test if the agent is currently processing a request
 boolean isRunning()
          Returns true if the client is already executing
static boolean isToolkitInstalled()
          Returns true if the toolkit has already been installed
 void ping()
          Renews a lease on the agent.
 HttpResponseData processHttpRequest(HttpRequestData requestData)
          Processes HTTP request, as received by the servlet.
 void removeBlockedThread(WebCreamThread thread)
          Removes the given thread from a list of blocked threads.
 HttpResponseData renderCurrentWindow(HttpRequestData data)
          Renders the current window on EventDispatch thread
 void renderStandardPage(int status, java.lang.Throwable x)
          Renders a standard page based on the template and the status
 void runApp(boolean wait)
          Runs the application/applet.
 void setAllowExit(boolean allow)
          Used to allow or disallow JVM shutdown
 void setException(java.lang.Throwable x)
          Sets the exception that occured in while processing a request
 void setResponseData(HttpResponseData httpResponseData)
          Sets the data structure for HTTP response
 void shutdown()
          Ends client session and cleans up all client resources.
 void waitForBlockedThreads(java.lang.Object[] blockedThreads)
          Waits until all blocked threads finish running
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shuttingDown

public static boolean shuttingDown

useWebCreamFontsConfigFile

public static boolean useWebCreamFontsConfigFile
Constructor Detail

ClientAgent

public ClientAgent(java.lang.String agentName,
                   java.lang.String appName)
            throws java.lang.Exception
Initializes the client agent

Throws:
java.lang.Exception
Method Detail

init

public void init(AgentInitData data)
          throws java.rmi.RemoteException,
                 java.lang.Exception
Completes client initialization by storing the data. This is called when a browser actually attaches to the client agent

Specified by:
init in interface ClientAgentRemote
Throws:
java.rmi.RemoteException
java.lang.Exception

initProperties

public void initProperties(java.lang.String appName)
                    throws java.rmi.RemoteException,
                           java.lang.Exception
Initializes generic properties and variables of the client agent that do not depend on the specific application configuration

Throws:
java.rmi.RemoteException
java.lang.Exception

shutdown

public void shutdown()
Ends client session and cleans up all client resources. Stops threads, closes all windows and does other cleanup.

Specified by:
shutdown in interface ClientAgentRemote

allowExit

public boolean allowExit()
Checks if System.exit() is allowed to shutdown the JVM

Returns:
true if shutdown is allowed

exit

public void exit()
Safe shutdown of JVM. If shutdown is not allowed, an exception is thrown


setAllowExit

public void setAllowExit(boolean allow)
Used to allow or disallow JVM shutdown

Parameters:
allow - true to allow JVM shutdown

getEventQueue

public java.awt.EventQueue getEventQueue()
Used to retrieve the virtual user specific AWT event queue

Returns:
event queue

getBrowserID

public int getBrowserID()
Returns the browser ID of the user, that the client agent is associated with


getBrowserVersion

public float getBrowserVersion()
Returns the browser version of the user, that the client agent is associated with


renderCurrentWindow

public HttpResponseData renderCurrentWindow(HttpRequestData data)
                                     throws WebCreamException,
                                            java.rmi.RemoteException
Renders the current window on EventDispatch thread

Specified by:
renderCurrentWindow in interface ClientAgentRemote
Parameters:
data - request data to be processed
Returns:
response data, that is used by the caller
Throws:
WebCreamException
java.rmi.RemoteException

processHttpRequest

public HttpResponseData processHttpRequest(HttpRequestData requestData)
                                    throws java.rmi.RemoteException,
                                           WebCreamException
Processes HTTP request, as received by the servlet. The general algorithm is to update the currently focused window with the received data, emulate the action and render the newly focused window as a response

Specified by:
processHttpRequest in interface ClientAgentRemote
Returns:
HTTP response, containing HTML page to be displayed
Throws:
java.rmi.RemoteException
WebCreamException

renderStandardPage

public void renderStandardPage(int status,
                               java.lang.Throwable x)
                        throws WebCreamException
Renders a standard page based on the template and the status

Throws:
WebCreamException

emulateRequest

public void emulateRequest(HttpRequestData data)
                    throws java.lang.Throwable
Emulates the given request and action, as though triggered by the application user The action is executed on a separate threads, and all threads, spawned from the emulation thread are monitored for their state. If a blocking dialog is displayed on a thread, the thread is interrupted and the dialog is rendered, thus not blocking the request processing

Parameters:
data - request data
Throws:
java.lang.Throwable

runApp

public void runApp(boolean wait)
            throws WebCreamException,
                   java.rmi.RemoteException
Runs the application/applet. Can be used to preload app classes

Specified by:
runApp in interface ClientAgentRemote
Throws:
WebCreamException
java.rmi.RemoteException

doRun

public void doRun()
Does the job of running the client application


getHTMLPage

public HTMLPage getHTMLPage()
Returns HTML Page, associated with this client


isRunning

public boolean isRunning()
Returns true if the client is already executing


getUIManager

public WebCreamUIManager getUIManager()
Returns the instance of UIManager, associated with this client


getCurrentInstance

public static ClientAgent getCurrentInstance()
Returns the instance of ClientAgent, associated with the calling thread May not work correctly in a multi threaded application


addBlockedThread

public void addBlockedThread(WebCreamThread thread)
Adds the given thread to the list of blocked threads within the clinet. This allows to determine when the client has finished responding to an emulated user action, before a page is rendered.


removeBlockedThread

public void removeBlockedThread(WebCreamThread thread)
Removes the given thread from a list of blocked threads. Normally, is called when the thread is unblocked


waitForBlockedThreads

public void waitForBlockedThreads(java.lang.Object[] blockedThreads)
                           throws java.lang.Throwable
Waits until all blocked threads finish running

Parameters:
blockedThreads -
Throws:
java.lang.Throwable

isRequestActive

public boolean isRequestActive()
Can be used to test if the agent is currently processing a request

Returns:
true if the agent is currently processing a browser request

isOperationActive

public boolean isOperationActive()
Operations can be defined using the application properties file to fine tune a multithreaded application

Returns:
true if there is a custom defined operation active

isApplet

public boolean isApplet()
Can be used to test if the application is running as an applet

Returns:
true if the virtual user is running as an applet

getOperationLock

public java.lang.Object getOperationLock()
Used to control multithreaded applications

Returns:
operation lock

beginOperation

public void beginOperation()
                    throws java.lang.Exception
Begins a custom operation

Throws:
java.lang.Exception

endOperation

public void endOperation()
                  throws java.lang.Exception
Marks an end of custom operation

Throws:
java.lang.Exception

getDocumentRenderer

public AbstractDocumentRenderer getDocumentRenderer()
Returns the instance of PageRenderer, associated with this client


getWindowUpdater

public WindowUpdater getWindowUpdater()
Returns the instance of WindowUpdater, associated with this client


getProps

public WebCreamProperties getProps()
Returns the application initialization properties


getInitData

public AgentInitData getInitData()
Returns application initialization data

Returns:
initialization data

getTempFiles

public java.util.List getTempFiles()
Client agent stores the temporary files created for the user They are automatically deleted when the agent is shutdown

Returns:
list of temporary files.

getRequestId

public long getRequestId()
Each request increments the id

Returns:
current request id

isToolkitInstalled

public static boolean isToolkitInstalled()
Returns true if the toolkit has already been installed

Returns:
boolean

installToolkit

public static void installToolkit()
Installs AWT toolkit. This is important to intercept the window creation and graphics emulation.


ping

public void ping()
          throws java.rmi.RemoteException
Renews a lease on the agent. Used to keep warmedUp JVM running

Specified by:
ping in interface ClientAgentRemote
Throws:
java.rmi.RemoteException

installExitTrap

public static void installExitTrap()
Installs the security manager to intercept System.exit() attempts.


getException

public java.lang.Throwable getException()
Returns the exception cought while processing a request

Returns:
exception or null

getRequestData

public HttpRequestData getRequestData()
Returns data received from the browser

Returns:
data received from the browser

getResponseData

public HttpResponseData getResponseData()
Returns data received from the browser

Returns:
data received from the browser

setResponseData

public void setResponseData(HttpResponseData httpResponseData)
Sets the data structure for HTTP response

Parameters:
httpResponseData - HttpResponseData

getRequestFilter

public AgentRequestFilter getRequestFilter()
Returns request filter instance or null

Returns:
request filter instance or null

getWebCreamThreadGroup

public WebCreamThreadGroup getWebCreamThreadGroup()
Returns the thread group that owns all threads of this agent

Returns:
WebCreamThreadGroup

setException

public void setException(java.lang.Throwable x)
Sets the exception that occured in while processing a request

Parameters:
x - exception to be reported to the user

getSession

public java.util.HashMap getSession()
Returns the session map associated with the client. Session can be used by renderers and updaters to store application-specific information. To avoid name clashes, it is recommended to use a unique prefix for custom parameters, e.f. "custom.userName".


getAppName

public java.lang.String getAppName()
Returns application name


getClientId

public int getClientId()
Returns agent name


getMaximumWindowSize

public java.awt.Dimension getMaximumWindowSize(java.awt.Window window)

getWindowProperty

public java.lang.String getWindowProperty(java.lang.String windowTitle,
                                          java.lang.String property)
Looks up and returns the value of the property if set for a window with the given title

Parameters:
windowTitle - window title text, which does not have to be an exact match and can be a substring
property - property name to search for, for example "refresh"
Returns:
value of the property or null if the property is not set

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the class loader used to load the classes of this virtual client

Returns:
ClassLoader


Copyright © 2000-2006 CreamTec LLC. All Rights Reserved.