org.openqa.grid.internal
Class BaseRemoteProxy

java.lang.Object
  extended by org.openqa.grid.internal.BaseRemoteProxy
All Implemented Interfaces:
java.lang.Comparable<RemoteProxy>, RemoteProxy
Direct Known Subclasses:
DefaultRemoteProxy

public class BaseRemoteProxy
extends java.lang.Object
implements RemoteProxy


Field Summary
protected  java.net.URL remoteHost
           
 
Constructor Summary
BaseRemoteProxy(RegistrationRequest request, Registry registry)
          Create the proxy from the info sent by the remote.
 
Method Summary
 int compareTo(RemoteProxy o)
           
 boolean equals(java.lang.Object obj)
           
 void forceSlotCleanerRun()
          Internal use only
 CapabilityMatcher getCapabilityHelper()
          Returns the capability matcher that will be used to by the remote proxy to determine whether its test slots can run a requested test session.
 java.util.Map<java.lang.String,java.lang.Object> getConfig()
          Returns the configuration the node was initialized with.
 HtmlRenderer getHtmlRender()
          Returns the object responsible for rendering any information about the proxy in a Web application.
 HttpClientFactory getHttpClientFactory()
          Retrieves the global factory for creating HTTP clients.
 java.lang.String getId()
          Returns the unique id for the node.
 int getMaxNumberOfConcurrentTestSessions()
          Returns the maximum number of concurrent tests that can run on this node.
static
<T extends RemoteProxy>
T
getNewInstance(RegistrationRequest request, Registry registry)
          Takes a registration request and return the RemoteProxy associated to it.
 TestSession getNewSession(java.util.Map<java.lang.String,java.lang.Object> requestedCapability)
          Creates and returns a new test session if the current node has the resources and is ready to run the test.
 RegistrationRequest getOriginalRegistrationRequest()
          Returns the request sent from the node to the hub to register the proxy.
 Registry getRegistry()
          Retrieves the handle to the registry this remote proxy is registered with.
 java.net.URL getRemoteHost()
          Get the host the node is on.
 float getResourceUsageInPercent()
          Return how much resources are currently used on the proxy.
 org.json.JSONObject getStatus()
          Renders the status of the node as JSON.
 java.util.List<TestSlot> getTestSlots()
          Each test running on the node will occupy a test slot.
 int getTimeOut()
          Indicates how long a node should wait for a seemingly non-responsive test session before deciding it has timed out.
 int getTotalUsed()
          Returns the total number of test slots used on this node.
 boolean hasCapability(java.util.Map<java.lang.String,java.lang.Object> requestedCapability)
          Checks if the node has the capability requested.
 int hashCode()
           
 boolean isBusy()
          Indicates whether the node has any test slots in use.
 void setupTimeoutListener()
          If the RemoteProxy implementation also implements TimeoutListener, then this method will start up the thread used to monitor timeouts and handle cleanup of timed out resources.
 void teardown()
          If the RemoteProxy implementation also implements TimeoutListener, then this method will stop the thread used to monitor timeouts.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

remoteHost

protected volatile java.net.URL remoteHost
Constructor Detail

BaseRemoteProxy

public BaseRemoteProxy(RegistrationRequest request,
                       Registry registry)
Create the proxy from the info sent by the remote.

If maxSession is not specified, default to 1 = max number of tests running at a given time will be 1.

For each capability, maxInstances is defaulted to 1 if not specified = max number of test of each capability running at a time will be 1. maxInstances for firefox can be > 1. IE won't support it.

Parameters:
request - The request
registry - The registry to use
Method Detail

getTestSlots

public java.util.List<TestSlot> getTestSlots()
Description copied from interface: RemoteProxy
Each test running on the node will occupy a test slot. A test slot can either be in use (have a session) or be available for scheduling (no associated session). This method allows retrieving the total state of the node, both test slots in use and those unused.

Specified by:
getTestSlots in interface RemoteProxy
Returns:
the test slots.

getRegistry

public Registry getRegistry()
Description copied from interface: RemoteProxy
Retrieves the handle to the registry this remote proxy is registered with.

Specified by:
getRegistry in interface RemoteProxy
Returns:
the registry.

getCapabilityHelper

public CapabilityMatcher getCapabilityHelper()
Description copied from interface: RemoteProxy
Returns the capability matcher that will be used to by the remote proxy to determine whether its test slots can run a requested test session.

Specified by:
getCapabilityHelper in interface RemoteProxy
Returns:
the capability matcher.

setupTimeoutListener

public void setupTimeoutListener()
Description copied from interface: RemoteProxy
If the RemoteProxy implementation also implements TimeoutListener, then this method will start up the thread used to monitor timeouts and handle cleanup of timed out resources.

Specified by:
setupTimeoutListener in interface RemoteProxy

getId

public java.lang.String getId()
Description copied from interface: RemoteProxy
Returns the unique id for the node. The ID should not change throughout the life of the node.

Specified by:
getId in interface RemoteProxy
Returns:
the unique node id.

teardown

public void teardown()
Description copied from interface: RemoteProxy
If the RemoteProxy implementation also implements TimeoutListener, then this method will stop the thread used to monitor timeouts.

Specified by:
teardown in interface RemoteProxy

forceSlotCleanerRun

public void forceSlotCleanerRun()
Internal use only


getConfig

public java.util.Map<java.lang.String,java.lang.Object> getConfig()
Description copied from interface: RemoteProxy
Returns the configuration the node was initialized with.

Specified by:
getConfig in interface RemoteProxy
Returns:
the node configuration.

getOriginalRegistrationRequest

public RegistrationRequest getOriginalRegistrationRequest()
Description copied from interface: RemoteProxy
Returns the request sent from the node to the hub to register the proxy.

Specified by:
getOriginalRegistrationRequest in interface RemoteProxy
Returns:
the original node registration request.

getMaxNumberOfConcurrentTestSessions

public int getMaxNumberOfConcurrentTestSessions()
Description copied from interface: RemoteProxy
Returns the maximum number of concurrent tests that can run on this node. NB: this number can be less than the number of test slots because a test slot only indicates what type of test session can be run on the remote. I.e., a node may allow N different types of tests, but only allow M tests to run at once, for M <= N.

Specified by:
getMaxNumberOfConcurrentTestSessions in interface RemoteProxy
Returns:

getRemoteHost

public java.net.URL getRemoteHost()
Description copied from interface: RemoteProxy
Get the host the node is on. This is different from the URL used to communicate with the driver. For a local node that support both RC and WebDriver protocols, remoteHost=http://localhost:5555, but the underlying server will respond on urls http://localhost:5555/wd/hub (proxy.host + slot.path, where slot is a WebDriver slot) and http://localhost:5555/selenium-server/driver (proxy.host + slot.path, where slot is an RC slot).

Specified by:
getRemoteHost in interface RemoteProxy
Returns:
the host the node is running on.

getNewSession

public TestSession getNewSession(java.util.Map<java.lang.String,java.lang.Object> requestedCapability)
Description copied from interface: RemoteProxy
Creates and returns a new test session if the current node has the resources and is ready to run the test.

Specified by:
getNewSession in interface RemoteProxy
Parameters:
requestedCapability - the type of test the client is interested in performing.
Returns:
a new TestSession if possible, null otherwise

getTotalUsed

public int getTotalUsed()
Description copied from interface: RemoteProxy
Returns the total number of test slots used on this node.

Specified by:
getTotalUsed in interface RemoteProxy
Returns:
the total number of test slots in use.

hasCapability

public boolean hasCapability(java.util.Map<java.lang.String,java.lang.Object> requestedCapability)
Description copied from interface: RemoteProxy
Checks if the node has the capability requested.

The definition of "has" is defined by CapabilityMatcher.matches(Map, Map)

hasCapability = true doesn't mean the test cast start just now, only that the proxy will be able to run a test requiring that capability at some point.

Specified by:
hasCapability in interface RemoteProxy
Parameters:
requestedCapability - the type of test the client is interested in performing.
Returns:
true if present

isBusy

public boolean isBusy()
Description copied from interface: RemoteProxy
Indicates whether the node has any test slots in use. The node may still be able to accept more work even if it is busy.

Specified by:
isBusy in interface RemoteProxy
Returns:
true if the node has any test slots in use.

getNewInstance

public static <T extends RemoteProxy> T getNewInstance(RegistrationRequest request,
                                                       Registry registry)
Takes a registration request and return the RemoteProxy associated to it. It can be any class extending RemoteProxy.

Parameters:
request - The request
registry - The registry to use
Returns:
a new instance built from the request.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(RemoteProxy o)
Specified by:
compareTo in interface java.lang.Comparable<RemoteProxy>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getHtmlRender

public HtmlRenderer getHtmlRender()
Description copied from interface: RemoteProxy
Returns the object responsible for rendering any information about the proxy in a Web application.

Specified by:
getHtmlRender in interface RemoteProxy
Returns:
the renderer.

getTimeOut

public int getTimeOut()
Description copied from interface: RemoteProxy
Indicates how long a node should wait for a seemingly non-responsive test session before deciding it has timed out.

Specified by:
getTimeOut in interface RemoteProxy
Returns:
the timeout in milliseconds.

getHttpClientFactory

public HttpClientFactory getHttpClientFactory()
Description copied from interface: RemoteProxy
Retrieves the global factory for creating HTTP clients.

Specified by:
getHttpClientFactory in interface RemoteProxy
Returns:
The thread-safe HTTP client factory.

getStatus

public org.json.JSONObject getStatus()
                              throws GridException
Description copied from interface: RemoteProxy
Renders the status of the node as JSON. Useful for APIs.

Specified by:
getStatus in interface RemoteProxy
Returns:
the node status.
Throws:
GridException - If the node if down or doesn't recognize the /wd/hub/status request.

getResourceUsageInPercent

public float getResourceUsageInPercent()
Description copied from interface: RemoteProxy
Return how much resources are currently used on the proxy. Default implementation is runningTests / maxTests on the proxy. For a proxy with more knowledge about its resources, a finer implementation can also take into account CPU usage, RAM usage etc.

Specified by:
getResourceUsageInPercent in interface RemoteProxy
Returns:
the percentage of the available resource used. Can be greater than 100 if the grid is under heavy load.


Copyright © 2012. All Rights Reserved.