com.creamtec.ajaxswing.core
Class ClientAgent

java.lang.Object
  extended by com.creamtec.ajaxswing.core.ClientAgent
All Implemented Interfaces:
ClientAgentRemote, java.rmi.Remote
Direct Known Subclasses:
HTMLClientAgent

public abstract 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 AjaxSwing 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
          Synchronizes the processing of a request.
 
Field Summary
static java.lang.ClassLoader commonClassLoader
           
static boolean shuttingDown
           
 
Constructor Summary
ClientAgent(java.lang.String agentName, java.lang.String appName)
          Initializes the client agent
 
Method Summary
 void addBlockedThread(AjaxSwingThread thread)
          Adds the given thread to the list of blocked threads within the clinet.
 void addDownloadFileName(java.lang.String filename)
           
 void addFastSubmitHandler(FastSubmitHandler handler, java.lang.String paramKey)
           
 void addKeepAliveEventHandler(KeepAliveEventHandler handler)
           
 void addURLParamHandler(URLParameterHandler handler, java.lang.String paramKey)
           
 void allowDownload(java.lang.String downloadFileName)
           
 boolean allowExit()
          Checks if System.exit() is allowed to shutdown the JVM
 void appendJavaScript(java.lang.String javaScript)
           
 void beginOperation()
          Begins a custom operation
 void checkAndMonitorAsynchronousUpdates()
          Checks if the number of threads at the moment called is different then the number of threads last marked.
 void clearAppendJavaScript()
           
 void clearUrlForOpenInNewTab()
           
 void denyDownload(java.io.File file)
          Remove download file from session by File
 void denyDownload(java.lang.String downloadFileName)
          Remove download file from session by name
 void doRun()
          Does the job of running the client application
 void endOperation()
          Marks an end of custom operation
 void endOperation(boolean endsOnModalDialog)
          Marks that next modal dialog ends custom operation
 void exit()
          Safe shutdown of JVM.
 AjaxSwingThreadGroup getAjaxSwingThreadGroup()
          Returns the thread group that owns all threads of this agent
 java.lang.String getAppendJavaScript()
           
 java.lang.String getAppName()
          Returns application name
 int getBrowserID()
          Returns the browser ID of the user, that the client agent is associated with
 java.lang.String getBrowserLocale()
           
 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
 java.awt.datatransfer.Clipboard getClipboard()
           
 java.lang.String getComponentProperty(java.lang.Object component, java.lang.String property)
          Looks up and returns the value of the component property in the current window
 java.lang.String getCsrfToken()
           
static ClientAgent getCurrentInstance()
          Returns the instance of ClientAgent, associated with the calling thread May not work correctly in a multi threaded application
 java.util.Map getDownloadFileNames()
           
 boolean getEndOperationOnModalDialog()
           
 AjaxSwingEventQueue getEventQueue()
          Used to retrieve the virtual user specific AWT event queue
 java.lang.Throwable getException()
          Returns the exception cought while processing a request
 java.lang.String getExitPage()
           
 java.awt.KeyboardFocusManager getFocusManager()
           
 double getFontCalibrationData(java.lang.String fontName, int fontSize, boolean isCapital)
           
 AbstractDocument getHTMLPage()
          Returns HTML Page, associated with this client
 AbstractDocument getHTMLPageWait()
           
 AgentInitData getInitData()
          Returns application initialization data
 KeepAliveEvent getLastKeepAliveEvent()
           
 java.awt.Dimension getMaximumWindowSize(java.awt.Window window)
           
 javax.swing.MenuSelectionManager getMenuSelectionManager()
           
 java.lang.Object getMouseGrabber()
           
 java.lang.Object getOperationLock()
          Used to control multithreaded applications
 AbstractDocumentRenderer getPageRenderer()
          Returns the instance of PageRenderer, associated with this client
 AjaxSwingProperties getProps()
          Returns the application initialization properties
 AjaxSwingRepaintManager getRepaintManager()
           
 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
 SchedulingEventQueue getSchedulingEventQueue()
           
 java.util.HashMap getSession()
          Returns the session map associated with the client.
 long getSessionTimeout()
           
 java.lang.String getShortFileName(java.lang.String downloadFileName)
           
 java.util.List getTempFiles()
          Client agent stores the temporary files created for the user They are automatically deleted when the agent is shutdown
 java.util.TimeZone getTimeZone()
          returns timezone for client browser, based on available information from browser.
 int getTimeZoneCurrentOffset()
          returns the time difference between GMT and current local time, in minutes
 int getTimeZoneRawOffset()
          returns the time difference between GMT and local time, in minutes, not affected by daylight saving time
 boolean getTimeZoneUseDaylight()
          returns if timezone use daylight saving time
 AjaxSwingUIManager getUIManager()
          Returns the instance of UIManager, associated with this client
 int getUpdateBrowserInterval()
           
 java.lang.String getUrlForOpenInNewTab()
          If set, on response will rerun url for open in new tab
 java.util.Locale getUserLocale()
           
 java.lang.String getWindowProperty(java.lang.String windowTitle, java.lang.String key)
          Looks up and returns the value of the property if set for a window with the given title
 int getWindowProperty(java.lang.String windowTitle, java.lang.String key, int defaultValue)
           
 java.util.List getWindowsForRendering()
           
 WindowUpdater getWindowUpdater()
          Returns the instance of WindowUpdater, associated with this client
 void init(AgentInitData data, HttpRequestData requestData)
          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 installGraphicsEnvironmentProperties(AjaxSwingProperties props, java.lang.Object traceObject)
          Installs GraphicsEnvironmentProperties.
 void installToolkit()
          Installs AWT toolkit.
 boolean isApplet()
          Can be used to test if the application is running as an applet
 boolean isBrowserIE()
          Returns true if user agent is Netscape or compatible
 boolean isDownloadAllowed(java.lang.String downloadFileName)
          Returns true if the download of the given file name is allowed
 boolean isFocusChangeAllowed(java.awt.Component component)
           
static boolean isGraphicsEnvironmentPropertiesInstalled()
          Returns true if the GraphicsEnvironmentProperties has already been installed
 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 monitorAsynchronousUpdates()
          Starts monitoring of UI updates by enabling browser update interval
 void monitorAsynchronousUpdates(int duration, int interval)
           
 void openInNewTab(java.lang.String urlForOpenInNewTab)
          Set url for open in new tab
 void print(byte[] pdfFile)
           
 void removeBlockedThread(AjaxSwingThread thread)
          Removes the given thread from a list of blocked threads.
 void removeDownloadFileName(java.lang.String filename)
          Remove download file from map where we wait files for download while them doesn't ready
 void removeFastSubmitHandler(FastSubmitHandler handler, java.lang.String paramKey)
           
 void removeKeepAliveEventHandler(KeepAliveEventHandler handler)
           
 void removeURLParamHandler(URLParameterHandler handler, java.lang.String paramKey)
           
 void runApp(boolean wait)
          Runs the application/applet.
 void setAllowExit(boolean allow)
          Used to allow or disallow JVM shutdown
 void setBrowserLocale(java.lang.String browserLocale)
           
 void setClientSize(int width, int height)
           
 void setException(java.lang.Throwable x)
          Sets the exception that occured in while processing a request
 void setExitPage(java.lang.String pageName)
           
 void setFocusChangeAllowed(boolean allowed)
           
 void setFontCalibrationData(java.lang.String allCalibrationData)
           
 void setHTMLPage(AbstractDocument page)
           
 void setMouseGrabber(java.lang.Object mouseGrabber)
           
 void setRequestData(HttpRequestData data)
           
 void setResponseData(HttpResponseData httpResponseData)
          Sets the data structure for HTTP response
 void setSessionTimeout(long seconds)
           
 void setUpdateBrowser(boolean updateBrowser)
          If set to true, when next updateInterval call comes, the browser will be refreshed to synchronize it with the Swing state on the server
 void setUpdateBrowserInterval(int newUpdateInterval)
          Sets the value of router.updateInterval property
 void setUserLocale(java.util.Locale currentLocale)
           
 boolean shouldUpdateBrowser()
           
 void shutdown()
          Initiates shutdown sequence and returns immediately
 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
 
Methods inherited from interface com.creamtec.ajaxswing.core.ClientAgentRemote
ping, processHttpRequest, renderWindows
 

Field Detail

shuttingDown

public static boolean shuttingDown

commonClassLoader

public static java.lang.ClassLoader commonClassLoader
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,
                 HttpRequestData requestData)
          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

setClientSize

public void setClientSize(int width,
                          int height)

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()
Initiates shutdown sequence and returns immediately

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 AjaxSwingEventQueue 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


isBrowserIE

public boolean isBrowserIE()
Returns true if user agent is Netscape or compatible

Returns:

getBrowserVersion

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


getWindowsForRendering

public java.util.List getWindowsForRendering()
                                      throws java.lang.Exception
Throws:
java.lang.Exception

runApp

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

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

getRepaintManager

public AjaxSwingRepaintManager getRepaintManager()

doRun

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


getHTMLPage

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


getHTMLPageWait

public AbstractDocument getHTMLPageWait()

setHTMLPage

public void setHTMLPage(AbstractDocument page)
                 throws java.lang.Exception
Throws:
java.lang.Exception

isRunning

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


getUIManager

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


getSchedulingEventQueue

public SchedulingEventQueue getSchedulingEventQueue()

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(AjaxSwingThread 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(AjaxSwingThread 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()
Begins a custom operation

Throws:
java.lang.Exception

endOperation

public void endOperation()
Marks an end of custom operation

Throws:
java.lang.Exception

endOperation

public void endOperation(boolean endsOnModalDialog)
Marks that next modal dialog ends custom operation

Throws:
java.lang.Exception

getEndOperationOnModalDialog

public boolean getEndOperationOnModalDialog()

getPageRenderer

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


getWindowUpdater

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


getProps

public AjaxSwingProperties getProps()
Returns the application initialization properties

Specified by:
getProps in interface ClientAgentRemote

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

Specified by:
getTempFiles in interface ClientAgentRemote
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

isGraphicsEnvironmentPropertiesInstalled

public static boolean isGraphicsEnvironmentPropertiesInstalled()
Returns true if the GraphicsEnvironmentProperties has already been installed

Returns:
boolean

installGraphicsEnvironmentProperties

public static void installGraphicsEnvironmentProperties(AjaxSwingProperties props,
                                                        java.lang.Object traceObject)
Installs GraphicsEnvironmentProperties. This is important to provide AjaxSwing Graphics Environment for correct work of ClientAgent/


installToolkit

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


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

setRequestData

public void setRequestData(HttpRequestData data)

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

getAjaxSwingThreadGroup

public AjaxSwingThreadGroup getAjaxSwingThreadGroup()
Returns the thread group that owns all threads of this agent

Returns:
AjaxSwingThreadGroup

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 key)
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
key - property name to search for, for example "refresh"
Returns:
value of the property or null if the property is not set

getWindowProperty

public int getWindowProperty(java.lang.String windowTitle,
                             java.lang.String key,
                             int defaultValue)

getComponentProperty

public java.lang.String getComponentProperty(java.lang.Object component,
                                             java.lang.String property)
Looks up and returns the value of the component property in the current window

Parameters:
componentKey - 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

getClipboard

public java.awt.datatransfer.Clipboard getClipboard()

shouldUpdateBrowser

public boolean shouldUpdateBrowser()

setUpdateBrowser

public void setUpdateBrowser(boolean updateBrowser)
If set to true, when next updateInterval call comes, the browser will be refreshed to synchronize it with the Swing state on the server

Parameters:
updateBrowser -

getUpdateBrowserInterval

public int getUpdateBrowserInterval()

setUpdateBrowserInterval

public void setUpdateBrowserInterval(int newUpdateInterval)
Sets the value of router.updateInterval property

Parameters:
newUpdateInterval -

isDownloadAllowed

public boolean isDownloadAllowed(java.lang.String downloadFileName)
                          throws java.rmi.RemoteException
Returns true if the download of the given file name is allowed

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

allowDownload

public void allowDownload(java.lang.String downloadFileName)

denyDownload

public void denyDownload(java.lang.String downloadFileName)
Description copied from interface: ClientAgentRemote
Remove download file from session by name

Specified by:
denyDownload in interface ClientAgentRemote

denyDownload

public void denyDownload(java.io.File file)
Description copied from interface: ClientAgentRemote
Remove download file from session by File

Specified by:
denyDownload in interface ClientAgentRemote

getShortFileName

public java.lang.String getShortFileName(java.lang.String downloadFileName)

print

public void print(byte[] pdfFile)

getAppendJavaScript

public java.lang.String getAppendJavaScript()

clearAppendJavaScript

public void clearAppendJavaScript()

appendJavaScript

public void appendJavaScript(java.lang.String javaScript)

setSessionTimeout

public void setSessionTimeout(long seconds)
Specified by:
setSessionTimeout in interface ClientAgentRemote

getSessionTimeout

public long getSessionTimeout()
Specified by:
getSessionTimeout in interface ClientAgentRemote

addURLParamHandler

public void addURLParamHandler(URLParameterHandler handler,
                               java.lang.String paramKey)

removeURLParamHandler

public void removeURLParamHandler(URLParameterHandler handler,
                                  java.lang.String paramKey)

addKeepAliveEventHandler

public void addKeepAliveEventHandler(KeepAliveEventHandler handler)

removeKeepAliveEventHandler

public void removeKeepAliveEventHandler(KeepAliveEventHandler handler)

getLastKeepAliveEvent

public KeepAliveEvent getLastKeepAliveEvent()

addFastSubmitHandler

public void addFastSubmitHandler(FastSubmitHandler handler,
                                 java.lang.String paramKey)

removeFastSubmitHandler

public void removeFastSubmitHandler(FastSubmitHandler handler,
                                    java.lang.String paramKey)

monitorAsynchronousUpdates

public void monitorAsynchronousUpdates()
Starts monitoring of UI updates by enabling browser update interval

Parameters:
component -

monitorAsynchronousUpdates

public void monitorAsynchronousUpdates(int duration,
                                       int interval)

checkAndMonitorAsynchronousUpdates

public void checkAndMonitorAsynchronousUpdates()
Checks if the number of threads at the moment called is different then the number of threads last marked. If different, starts monitoring of asynchronous updates


getTimeZoneCurrentOffset

public int getTimeZoneCurrentOffset()
returns the time difference between GMT and current local time, in minutes


getTimeZoneRawOffset

public int getTimeZoneRawOffset()
returns the time difference between GMT and local time, in minutes, not affected by daylight saving time


getTimeZoneUseDaylight

public boolean getTimeZoneUseDaylight()
returns if timezone use daylight saving time


getTimeZone

public java.util.TimeZone getTimeZone()
returns timezone for client browser, based on available information from browser.


getExitPage

public java.lang.String getExitPage()
Specified by:
getExitPage in interface ClientAgentRemote

setExitPage

public void setExitPage(java.lang.String pageName)
Specified by:
setExitPage in interface ClientAgentRemote

getUserLocale

public java.util.Locale getUserLocale()
Specified by:
getUserLocale in interface ClientAgentRemote

setUserLocale

public void setUserLocale(java.util.Locale currentLocale)
Specified by:
setUserLocale in interface ClientAgentRemote

getBrowserLocale

public java.lang.String getBrowserLocale()
Specified by:
getBrowserLocale in interface ClientAgentRemote

setBrowserLocale

public void setBrowserLocale(java.lang.String browserLocale)
Specified by:
setBrowserLocale in interface ClientAgentRemote

setFocusChangeAllowed

public void setFocusChangeAllowed(boolean allowed)

isFocusChangeAllowed

public boolean isFocusChangeAllowed(java.awt.Component component)

getCsrfToken

public java.lang.String getCsrfToken()
Specified by:
getCsrfToken in interface ClientAgentRemote

getFocusManager

public java.awt.KeyboardFocusManager getFocusManager()

getMenuSelectionManager

public javax.swing.MenuSelectionManager getMenuSelectionManager()

addDownloadFileName

public void addDownloadFileName(java.lang.String filename)

removeDownloadFileName

public void removeDownloadFileName(java.lang.String filename)
Description copied from interface: ClientAgentRemote
Remove download file from map where we wait files for download while them doesn't ready

Specified by:
removeDownloadFileName in interface ClientAgentRemote

getDownloadFileNames

public java.util.Map getDownloadFileNames()

getUrlForOpenInNewTab

public java.lang.String getUrlForOpenInNewTab()
If set, on response will rerun url for open in new tab

Returns:
String

openInNewTab

public void openInNewTab(java.lang.String urlForOpenInNewTab)
Set url for open in new tab


clearUrlForOpenInNewTab

public void clearUrlForOpenInNewTab()

getMouseGrabber

public java.lang.Object getMouseGrabber()

setMouseGrabber

public void setMouseGrabber(java.lang.Object mouseGrabber)

setFontCalibrationData

public void setFontCalibrationData(java.lang.String allCalibrationData)
Specified by:
setFontCalibrationData in interface ClientAgentRemote

getFontCalibrationData

public double getFontCalibrationData(java.lang.String fontName,
                                     int fontSize,
                                     boolean isCapital)
Specified by:
getFontCalibrationData in interface ClientAgentRemote


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