org.jppf.client
Class AbstractJPPFClientConnection

java.lang.Object
  extended by org.jppf.client.AbstractJPPFClientConnection
All Implemented Interfaces:
ClientConnectionStatusHandler, JPPFClientConnection
Direct Known Subclasses:
JPPFClientConnectionImpl, JPPFJcaClientConnection

public abstract class AbstractJPPFClientConnection
extends Object
implements JPPFClientConnection

This class provides an API to submit execution requests and administration commands, and request server information data.
It has its own unique identifier, used by the nodes, to determine whether classes from the submitting application should be dynamically reloaded or not depending on whether the uuid has changed or not.

Author:
Laurent Cohen

Field Summary
protected  String appUuid
          Unique identifier for this JPPF client.
protected  int classServerPort
          The TCP port the class server is listening to.
protected  AbstractGenericClient client
          The JPPF client that owns this connection.
protected  String connectionUuid
          Unique ID for this connection and its two channels.
protected  JPPFSecurityContext credentials
          Security credentials associated with the application.
protected  ClassServerDelegate delegate
          Enables loading local classes onto remote nodes.
protected  String host
          The name or IP address of the host the JPPF driver is running on.
protected  boolean isShutdown
          Determines whether this connection has been shut down;
protected  JPPFJob job
          Holds the tasks, data provider and submission mode for the current execution.
protected  List<ClientConnectionStatusListener> listeners
          List of status listeners for this connection.
protected  String name
          Configuration name for this local client.
protected  int port
          The TCP port the JPPF driver listening to for submitted tasks.
protected  int priority
          Priority given to the driver this client is connected to.
protected  AtomicReference<JPPFClientConnectionStatus> status
          Status of the connection.
protected  Object statusLock
          Used to synchronize access to the status.
protected  TaskServerConnectionHandler taskServerConnection
          Handler for the connection to the task server.
protected  int totalTaskCount
          Total count of the tasks submitted by this client.
 
Constructor Summary
AbstractJPPFClientConnection()
           
 
Method Summary
 void addClientConnectionStatusListener(ClientConnectionStatusListener listener)
          Add a connection status listener to this connection's list of listeners.
abstract  List<JPPFJob> close()
          Shutdown this client and retrieve all pending executions for resubmission.
protected  void configure(String uuid, String name, String host, int driverPort, int classServerPort, int priority)
          Configure this client connection with the specified parameters.
protected abstract  SocketInitializer createSocketInitializer()
          Create a socket initializer.
 void delegateStatusChanged(ClientConnectionStatusEvent event)
          Invoked to notify of a status change event on a client connection.
protected  void fireStatusChanged(JPPFClientConnectionStatus oldStatus)
          Notify all listeners that the status of this connection has changed.
 AbstractGenericClient getClient()
          Get the JPPF client that owns this connection.
 String getConnectionUuid()
          Get the unique ID for this connection and its two channels.
 JPPFJob getCurrentJob()
          Get the object that holds the tasks, data provider and submission mode for the current execution.
 LoadBalancer getLoadBalancer()
          Get the load balancer that distributes the load between local and remote execution.
 String getName()
          Get the name assigned tothis client connection.
 int getPriority()
          Get the priority assigned to this connection.
protected  String getSerializationHelperClassName()
          Get the name of the serialization helper implementation class name to use.
 JPPFClientConnectionStatus getStatus()
          Get the status of this connection.
 TaskServerConnectionHandler getTaskServerConnection()
          Get the handler for the connection to the task server.
abstract  void init()
          Initialize this client connection.
 void initCredentials()
          Initialize this client's security credentials.
protected  SerializationHelper makeHelper()
          Instantiate a SerializationHelper using the current context class loader.
protected  SerializationHelper makeHelper(ClassLoader cl)
          Instantiate a SerializationHelper using the current context class loader.
protected  void processStatusChanged(JPPFClientConnectionStatus delegateStatus, JPPFClientConnectionStatus taskConnectionStatus)
          Handle a status change from either the class server delegate or the task server connection and determine whether it triggers a status change for the client connection.
 Pair<List<JPPFTask>,Integer> receiveResults()
          Receive results of tasks execution.
 Pair<List<JPPFTask>,Integer> receiveResults(ClassLoader cl)
          Receive results of tasks execution.
 void removeClientConnectionStatusListener(ClientConnectionStatusListener listener)
          Remove a connection status listener from this connection's list of listeners.
 void sendTasks(JPPFJob job)
          Send tasks to the server for execution.
 void sendTasks(JPPFTaskBundle header, JPPFJob job)
          Send tasks to the server for execution.
 void setCurrentJob(JPPFJob currentExecution)
          Set the object that holds the tasks, data provider and submission mode for the current execution.
 void setPriority(int priority)
          Set the priority assigned to this connection.
 void setStatus(JPPFClientConnectionStatus status)
          Set the status of this connection.
 void taskServerConnectionStatusChanged(ClientConnectionStatusEvent event)
          Invoked to notify of a status change event on a client connection.
 String toString()
          Get a string representation of this client connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jppf.client.JPPFClientConnection
submit
 

Field Detail

taskServerConnection

protected TaskServerConnectionHandler taskServerConnection
Handler for the connection to the task server.


delegate

protected ClassServerDelegate delegate
Enables loading local classes onto remote nodes.


appUuid

protected String appUuid
Unique identifier for this JPPF client.


connectionUuid

protected final String connectionUuid
Unique ID for this connection and its two channels.


host

protected String host
The name or IP address of the host the JPPF driver is running on.


port

protected int port
The TCP port the JPPF driver listening to for submitted tasks.


classServerPort

protected int classServerPort
The TCP port the class server is listening to.


credentials

protected JPPFSecurityContext credentials
Security credentials associated with the application.


totalTaskCount

protected int totalTaskCount
Total count of the tasks submitted by this client.


name

protected String name
Configuration name for this local client.


priority

protected int priority
Priority given to the driver this client is connected to. The client is always connected to the available driver(s) with the highest priority. If multiple drivers have the same priority, they will be used as a pool and tasks will be evenly distributed among them.


status

protected AtomicReference<JPPFClientConnectionStatus> status
Status of the connection.


statusLock

protected Object statusLock
Used to synchronize access to the status.


listeners

protected List<ClientConnectionStatusListener> listeners
List of status listeners for this connection.


job

protected JPPFJob job
Holds the tasks, data provider and submission mode for the current execution.


isShutdown

protected boolean isShutdown
Determines whether this connection has been shut down;


client

protected AbstractGenericClient client
The JPPF client that owns this connection.

Constructor Detail

AbstractJPPFClientConnection

public AbstractJPPFClientConnection()
Method Detail

configure

protected void configure(String uuid,
                         String name,
                         String host,
                         int driverPort,
                         int classServerPort,
                         int priority)
Configure this client connection with the specified parameters.

Parameters:
uuid - the unique identifier for this local client.
name - configuration name for this local client.
host - the name or IP address of the host the JPPF driver is running on.
driverPort - the TCP port the JPPF driver listening to for submitted tasks.
classServerPort - the TCP port the class server is listening to.
priority - the assigned to this client connection.

init

public abstract void init()
Initialize this client connection.

Specified by:
init in interface JPPFClientConnection
See Also:
JPPFClientConnection.init()

initCredentials

public void initCredentials()
                     throws Exception
Initialize this client's security credentials.

Throws:
Exception - if an error is raised during initialization.

sendTasks

public void sendTasks(JPPFJob job)
               throws Exception
Send tasks to the server for execution.

Parameters:
job - - the job to execute remotely.
Throws:
Exception - if an error occurs while sending the request.

sendTasks

public void sendTasks(JPPFTaskBundle header,
                      JPPFJob job)
               throws Exception
Send tasks to the server for execution.

Parameters:
header - the task bundle to send to the driver.
job - the job to execute remotely.
Throws:
Exception - if an error occurs while sending the request.

receiveResults

public Pair<List<JPPFTask>,Integer> receiveResults()
                                            throws Exception
Receive results of tasks execution.

Returns:
a pair of objects representing the executed tasks results, and the index of the first result within the initial task execution request.
Throws:
Exception - if an error is raised while reading the results from the server.

receiveResults

public Pair<List<JPPFTask>,Integer> receiveResults(ClassLoader cl)
                                            throws Exception
Receive results of tasks execution.

Parameters:
cl - the cintext classloader to use to deserialize the results.
Returns:
a pair of objects representing the executed tasks results, and the index of the first result within the initial task execution request.
Throws:
Exception - if an error is raised while reading the results from the server.

makeHelper

protected SerializationHelper makeHelper()
                                  throws Exception
Instantiate a SerializationHelper using the current context class loader.

Returns:
a SerializationHelper instance.
Throws:
Exception - if the serialiozation helper could not be instantiated.

makeHelper

protected SerializationHelper makeHelper(ClassLoader cl)
                                  throws Exception
Instantiate a SerializationHelper using the current context class loader.

Parameters:
cl - the class loader to usew to load the seriaization helper class.
Returns:
a SerializationHelper instance.
Throws:
Exception - if the serialiozation helper could not be instantiated.

getSerializationHelperClassName

protected String getSerializationHelperClassName()
Get the name of the serialization helper implementation class name to use.

Returns:
the fully qualified class name of a SerializationHelper implementation.

getPriority

public int getPriority()
Get the priority assigned to this connection.

Specified by:
getPriority in interface JPPFClientConnection
Returns:
a priority as an int value.
See Also:
JPPFClientConnection.getPriority()

setPriority

public void setPriority(int priority)
Set the priority assigned to this connection.

Parameters:
priority - a priority as an int value.

getStatus

public JPPFClientConnectionStatus getStatus()
Get the status of this connection.

Specified by:
getStatus in interface ClientConnectionStatusHandler
Returns:
a JPPFClientConnectionStatus enumerated value.
See Also:
ClientConnectionStatusHandler.getStatus()

setStatus

public void setStatus(JPPFClientConnectionStatus status)
Set the status of this connection.

Specified by:
setStatus in interface ClientConnectionStatusHandler
Parameters:
status - a JPPFClientConnectionStatus enumerated value.
See Also:
ClientConnectionStatusHandler.setStatus(org.jppf.client.JPPFClientConnectionStatus)

addClientConnectionStatusListener

public void addClientConnectionStatusListener(ClientConnectionStatusListener listener)
Add a connection status listener to this connection's list of listeners.

Specified by:
addClientConnectionStatusListener in interface ClientConnectionStatusHandler
Parameters:
listener - the listener to add to the list.
See Also:
ClientConnectionStatusHandler.addClientConnectionStatusListener(org.jppf.client.event.ClientConnectionStatusListener)

removeClientConnectionStatusListener

public void removeClientConnectionStatusListener(ClientConnectionStatusListener listener)
Remove a connection status listener from this connection's list of listeners.

Specified by:
removeClientConnectionStatusListener in interface ClientConnectionStatusHandler
Parameters:
listener - the listener to remove from the list.
See Also:
ClientConnectionStatusHandler.removeClientConnectionStatusListener(org.jppf.client.event.ClientConnectionStatusListener)

fireStatusChanged

protected void fireStatusChanged(JPPFClientConnectionStatus oldStatus)
Notify all listeners that the status of this connection has changed.

Parameters:
oldStatus - the connection status before the change.

close

public abstract List<JPPFJob> close()
Shutdown this client and retrieve all pending executions for resubmission.

Specified by:
close in interface JPPFClientConnection
Returns:
a list of JPPFJob instances to resubmit.
See Also:
JPPFClientConnection.close()

getName

public String getName()
Get the name assigned tothis client connection.

Specified by:
getName in interface JPPFClientConnection
Returns:
the name as a string.
See Also:
JPPFClientConnection.getName()

toString

public String toString()
Get a string representation of this client connection.

Overrides:
toString in class Object
Returns:
a string representing this connection.
See Also:
Object.toString()

createSocketInitializer

protected abstract SocketInitializer createSocketInitializer()
Create a socket initializer.

Returns:
an instance of a class implementing SocketInitializer.

getCurrentJob

public JPPFJob getCurrentJob()
Get the object that holds the tasks, data provider and submission mode for the current execution.

Returns:
a JPPFJob instance.

setCurrentJob

public void setCurrentJob(JPPFJob currentExecution)
Set the object that holds the tasks, data provider and submission mode for the current execution.

Parameters:
currentExecution - a ClientExecution instance.

getTaskServerConnection

public TaskServerConnectionHandler getTaskServerConnection()
Get the handler for the connection to the task server.

Returns:
a TaskServerConnectionHandler instance.

delegateStatusChanged

public void delegateStatusChanged(ClientConnectionStatusEvent event)
Invoked to notify of a status change event on a client connection.

Parameters:
event - the event to notify of.
See Also:
ClientConnectionStatusListener.statusChanged(org.jppf.client.event.ClientConnectionStatusEvent)

taskServerConnectionStatusChanged

public void taskServerConnectionStatusChanged(ClientConnectionStatusEvent event)
Invoked to notify of a status change event on a client connection.

Parameters:
event - the event to notify of.
See Also:
ClientConnectionStatusListener.statusChanged(org.jppf.client.event.ClientConnectionStatusEvent)

processStatusChanged

protected void processStatusChanged(JPPFClientConnectionStatus delegateStatus,
                                    JPPFClientConnectionStatus taskConnectionStatus)
Handle a status change from either the class server delegate or the task server connection and determine whether it triggers a status change for the client connection.

Parameters:
delegateStatus - status of the class server delegate conneciton.
taskConnectionStatus - status of the task server connection.

getLoadBalancer

public LoadBalancer getLoadBalancer()
Get the load balancer that distributes the load between local and remote execution.

Returns:
a LoadBalancer instance.

getClient

public AbstractGenericClient getClient()
Get the JPPF client that owns this connection.

Returns:
an AbstractGenericClient instance.

getConnectionUuid

public String getConnectionUuid()
Get the unique ID for this connection and its two channels.

Returns:
the id as a string.


Copyright © 2005-2010 JPPF Team.