com.parabon.client
Class RemoteSessionManager

java.lang.Object
  extended by com.parabon.client.SessionManager
      extended by com.parabon.client.RemoteSessionManager
Direct Known Subclasses:
SimulatorSessionManager

public class RemoteSessionManager
extends SessionManager

A run-remote implementation of SessionManager. Establishes a connection to the Frontier server, which can be used to create new jobs and tasks as well as monitor and control existing jobs and tasks.


Nested Class Summary
protected  class RemoteSessionManager.Establisher
           
protected  class RemoteSessionManager.GenericMessageConsumerTarget
           
protected  class RemoteSessionManager.MessageTransportRunnable
           
 
Field Summary
protected  java.lang.String actingClientID
           
static java.lang.String CLIENT_SERVLET_PATH
           
static java.lang.String CLIENT_USER_PASSWORD_PROPERTY
           
static java.lang.String CLIENT_USER_USERNAME_PROPERTY
           
protected  java.lang.String clientID
           
protected  java.net.URI dataServerURI
           
protected static float DEFAULT_MIN_CONNECTIONS_PER_HOUR
           
protected  RemoteSessionManager.Establisher establisher
           
protected  java.util.Map<java.lang.String,Job> jobIDMap
           
protected  int lastBarrierMessageID
           
protected  com.parabon.message.GenericMessageConsumer messageConsumer
           
protected  com.parabon.message.MessageTranslator messageTranslator
           
protected  RemoteSessionManager.MessageTransportRunnable messageTransportRunnable
           
protected  int nextBucketID
           
protected  int nextJobID
           
protected  java.util.Set<com.parabon.util.Listener> reestablishCompletionListeners
           
static java.lang.String REGISTER_URL_PROPERTY
           
static java.lang.String SERVER_TIMEOUT_PROPERTY
           
static java.lang.String SERVER_URL_PROPERTY
           
protected  java.lang.String sessionID
           
protected static java.lang.String THREAD_NAME
           
protected  com.parabon.io.SenecaTransport transport
           
 
Fields inherited from class com.parabon.client.SessionManager
DEFAULT_SESSION_MANAGER, destroyed, idGenerator, jobs, LOCAL_SESSION_MANAGER, log, pool, REMOTE_SESSION_MANAGER, SESSION_MODE_PROPERTY, SIMULATOR_SESSION_MANAGER, tempListenerList
 
Constructor Summary
  RemoteSessionManager()
          Open a new session with the Frontier server at a URL specified by the system property "com.parabon.server.url" and a timeout specified by the system property "serverTimeout".
protected RemoteSessionManager(boolean callInit)
           
  RemoteSessionManager(java.lang.String username, java.lang.String password)
          Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created.
  RemoteSessionManager(java.net.URL server)
          Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created.
  RemoteSessionManager(java.net.URL server, java.lang.String username, java.lang.String password, int blockMillis)
          Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created.
  RemoteSessionManager(java.net.URL server, java.lang.String username, java.lang.String password, java.lang.String onBehalfOf, int blockMillis)
          Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created.
 
Method Summary
protected  void addJob(Job job)
           
 Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_)
          Create and add a new Job with the given attributes.
 Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_, Job.JobConstraints constraints)
           
 Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_, java.lang.String launchToken)
           
 Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_, java.lang.String launchToken, Job.JobConstraints constraints)
           
static RemoteSessionManager createManagerWithLoginPrompt()
           
static RemoteSessionManager createManagerWithLoginPrompt(java.net.URL server, java.lang.String defaultUsername, java.lang.String defaultPassword, int blockMillis)
           
protected  java.lang.String createNewJobID()
           
 void destroy()
          Close this session, and release any resources associated with it.
 void destroy(int blockMillis)
          Close this session, and release any resources associated with it.
 void destroy(com.parabon.util.Listener completionListener)
          Close this session, and release any resources associated with it.
protected  void establishConnection(int blockMillis)
           
 void flush(int blockMillis)
          Block until all actions taken thus far in the current session have been recieved and acknowledged by the server.
protected  java.net.URI getBaseClientURI()
           
 java.net.URI getGlobalDataURI()
           
 int getMaxIncomingMessageQueueSize()
          Return the current maximum queue size for incoming messages.
 int getMaxOutgoingDataQueueSize()
          Return the current maximum queue size for outoing data.
 int getMaxOutgoingMessageQueueSize()
          Return the current maximum queue size for outgoing messages.
protected  java.lang.String getNewJobID()
           
 java.lang.String getPassword()
           
protected  java.lang.String getSessionID()
           
 java.lang.String getUsername()
           
protected  void init()
           
protected  int initJobID()
           
protected  void initTransport(java.net.URL serverURL, java.lang.String username, java.lang.String password, java.lang.String onBehalfOf, int blockMillis)
           
protected  void initTransport(java.net.URL serverURL, java.lang.String username, java.lang.String password, java.lang.String onBehalfOf, int blockMillis, boolean testConnection)
           
 void reestablish(int blockMillis)
          Attempt to retrieve the latest list of jobs from the Frontier server, blocking until complete or until approximately the given number milliseconds have elapsed.
 void reestablish(com.parabon.util.Listener completionListener)
          Attempt to retrieve the latest list of jobs from the Frontier server, returning immediately without waiting for the operation to complete.
protected  void removeJob(Job job)
           
protected  int sendMessage(com.parabon.message.Message m, boolean barrier, com.parabon.util.IntegerSet dependencies)
           
protected  void setLog(org.apache.log4j.Logger log_)
           
 void setMaxIncomingMessageQueueSize(int size)
          Limit the size of the incoming message queue to approximately the specified number of messages.
 void setMaxOutgoingDataQueueSize(int size)
          Limit the size of the outgoing data queue to approximately the specified number of elements.
 void setMaxOutgoingMessageQueueSize(int size)
          Limit the size of the outgoing message queue to approximately the specified number of messages.
 void submitElement(java.net.URI uri, com.parabon.io.DataWrapper contents)
           
 void submitElementBundle(java.net.URI uri, com.parabon.io.DataWrapper contents)
           
 java.lang.String toString()
           
 
Methods inherited from class com.parabon.client.SessionManager
addElement, addElement, addElement, addElement, getClientDataURI, getInstance, getInstance, getJobDataURI, getJobs, getLog, getTaskDataURI, notifyTaskEventListeners, reestablish
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MIN_CONNECTIONS_PER_HOUR

protected static final float DEFAULT_MIN_CONNECTIONS_PER_HOUR
See Also:
Constant Field Values

THREAD_NAME

protected static final java.lang.String THREAD_NAME
See Also:
Constant Field Values

SERVER_URL_PROPERTY

public static final java.lang.String SERVER_URL_PROPERTY
See Also:
Constant Field Values

REGISTER_URL_PROPERTY

public static final java.lang.String REGISTER_URL_PROPERTY
See Also:
Constant Field Values

CLIENT_USER_USERNAME_PROPERTY

public static final java.lang.String CLIENT_USER_USERNAME_PROPERTY
See Also:
Constant Field Values

CLIENT_USER_PASSWORD_PROPERTY

public static final java.lang.String CLIENT_USER_PASSWORD_PROPERTY
See Also:
Constant Field Values

SERVER_TIMEOUT_PROPERTY

public static final java.lang.String SERVER_TIMEOUT_PROPERTY
See Also:
Constant Field Values

CLIENT_SERVLET_PATH

public static final java.lang.String CLIENT_SERVLET_PATH
See Also:
Constant Field Values

messageTransportRunnable

protected RemoteSessionManager.MessageTransportRunnable messageTransportRunnable

jobIDMap

protected java.util.Map<java.lang.String,Job> jobIDMap

sessionID

protected java.lang.String sessionID

messageTranslator

protected com.parabon.message.MessageTranslator messageTranslator

messageConsumer

protected com.parabon.message.GenericMessageConsumer messageConsumer

transport

protected com.parabon.io.SenecaTransport transport

dataServerURI

protected java.net.URI dataServerURI

clientID

protected java.lang.String clientID

actingClientID

protected java.lang.String actingClientID

nextJobID

protected int nextJobID

nextBucketID

protected int nextBucketID

lastBarrierMessageID

protected int lastBarrierMessageID

establisher

protected RemoteSessionManager.Establisher establisher

reestablishCompletionListeners

protected java.util.Set<com.parabon.util.Listener> reestablishCompletionListeners
Constructor Detail

RemoteSessionManager

public RemoteSessionManager(java.net.URL server,
                            java.lang.String username,
                            java.lang.String password,
                            int blockMillis)
                     throws ServerCommunicationException,
                            com.parabon.io.InvalidLoginException
Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created. Sends the provided username/password via HTTP basic authentication; do not provide a secure password on an insecure network unless https is being used.

Blocks until a session is successfully established, or a maximum of approximately blockMillis milliseconds. If communications with the server cannot be successfully established within the time given or if the attempt to establish a connection fails, throws a RemoteSessionManager.ServerCommunicationException.

Parameters:
server - http or https URL specifying the base address of the Frontier server
username -
password -
blockMillis - maximum number of milliseconds to block while attempting to establish a connection before giving up and throwing an exception. If blockMillis == -1, block indefinitely, until the connection either succeeds or fails.
Throws:
com.parabon.io.InvalidLoginException
ServerCommunicationException

RemoteSessionManager

public RemoteSessionManager(java.net.URL server,
                            java.lang.String username,
                            java.lang.String password,
                            java.lang.String onBehalfOf,
                            int blockMillis)
                     throws ServerCommunicationException,
                            com.parabon.io.InvalidLoginException
Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created. Sends the provided username/password via HTTP basic authentication; do not provide a secure password on an insecure network unless https is being used.

Blocks until a session is successfully established, or a maximum of approximately blockMillis milliseconds. If communications with the server cannot be successfully established within the time given or if the attempt to establish a connection fails, throws a RemoteSessionManager.ServerCommunicationException. If onBehalfOf is not null, attempts to open a session for the user specified by onBehalfOf using credentials for another user. If the user corresponding to the supplied credentials is authorized to open a session "on behalf of" the specified user, then the session will continue as though the supplied username had been equal to the "onBehalfOf" user (in tandem with a valid corresponding password). If the credentialled user is not authorized to open such a session, an InvalidLoginException will be thrown.

Parameters:
server - http or https URL specifying the base address of the Frontier server
username -
password -
onBehalfOf -
blockMillis - maximum number of milliseconds to block while attempting to establish a connection before giving up and throwing an exception. If blockMillis == -1, block indefinitely, until the connection either succeeds or fails.
Throws:
com.parabon.io.InvalidLoginException
ServerCommunicationException

RemoteSessionManager

public RemoteSessionManager(java.lang.String username,
                            java.lang.String password)
                     throws ServerCommunicationException,
                            com.parabon.io.InvalidLoginException
Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created. Sends the provided username/password via HTTP basic authentication; do not provide a secure password on an insecure network unless https is being used.

Blocks until a session is successfully established, or a maximum of approximately blockMillis milliseconds. If communications with the server cannot be successfully established within the time given or if the attempt to establish a connection fails, throws a RemoteSessionManager.ServerCommunicationException.

Parameters:
username -
password -
Throws:
com.parabon.io.InvalidLoginException
ServerCommunicationException
See Also:
RemoteSessionManager(URL, String, String, int)

RemoteSessionManager

public RemoteSessionManager(java.net.URL server)
                     throws ServerCommunicationException,
                            com.parabon.io.InvalidLoginException
Open a new session with the Frontier server at the specified URL, through which running jobs and tasks can be accessed and new jobs and tasks created. Uses the username and password specified via the CLIENT_USER_USERNAME_PROPERTY and CLIENT_USER_PASSWORD_PROPERTY properties.

Blocks until a session is successfully established, or a maximum of approximately blockMillis milliseconds. If communications with the server cannot be successfully established within the time given or if the attempt to establish a connection fails, throws a RemoteSessionManager.ServerCommunicationException.

Parameters:
server - http or https URL specifying the base address of the Frontier server
Throws:
com.parabon.io.InvalidLoginException
ServerCommunicationException
See Also:
RemoteSessionManager(URL, String, String, int)

RemoteSessionManager

public RemoteSessionManager()
                     throws com.parabon.io.InvalidLoginException,
                            ServerCommunicationException
Open a new session with the Frontier server at a URL specified by the system property "com.parabon.server.url" and a timeout specified by the system property "serverTimeout". Uses the username and password specified via the CLIENT_USER_USERNAME_PROPERTY and CLIENT_USER_PASSWORD_PROPERTY properties.

Throws:
com.parabon.io.InvalidLoginException
ServerCommunicationException
See Also:
RemoteSessionManager(URL, String, String, int)

RemoteSessionManager

protected RemoteSessionManager(boolean callInit)
Method Detail

createManagerWithLoginPrompt

public static RemoteSessionManager createManagerWithLoginPrompt()
                                                         throws com.parabon.io.InvalidLoginException,
                                                                ServerCommunicationException
Throws:
com.parabon.io.InvalidLoginException
ServerCommunicationException

createManagerWithLoginPrompt

public static RemoteSessionManager createManagerWithLoginPrompt(java.net.URL server,
                                                                java.lang.String defaultUsername,
                                                                java.lang.String defaultPassword,
                                                                int blockMillis)
                                                         throws com.parabon.io.InvalidLoginException,
                                                                ServerCommunicationException
Throws:
com.parabon.io.InvalidLoginException
ServerCommunicationException

init

protected void init()

initTransport

protected void initTransport(java.net.URL serverURL,
                             java.lang.String username,
                             java.lang.String password,
                             java.lang.String onBehalfOf,
                             int blockMillis)
                      throws ServerCommunicationException,
                             com.parabon.io.InvalidLoginException
Throws:
ServerCommunicationException
com.parabon.io.InvalidLoginException

initTransport

protected void initTransport(java.net.URL serverURL,
                             java.lang.String username,
                             java.lang.String password,
                             java.lang.String onBehalfOf,
                             int blockMillis,
                             boolean testConnection)
                      throws ServerCommunicationException,
                             com.parabon.io.InvalidLoginException
Throws:
ServerCommunicationException
com.parabon.io.InvalidLoginException

setLog

protected void setLog(org.apache.log4j.Logger log_)
Overrides:
setLog in class SessionManager

flush

public void flush(int blockMillis)
Block until all actions taken thus far in the current session have been recieved and acknowledged by the server. Blocks at most approximately the specified number of milliseconds; if blockMillis == -1, no timeout is used, and blocks until the flush condition is satisfied.

Specified by:
flush in class SessionManager

destroy

public void destroy()
Description copied from class: SessionManager
Close this session, and release any resources associated with it. Any further operations on this session manager or any jobs or tasks created through it will result in undefined behaviour.

Does not neccessarily block until destruction is actually complete: worker threads may continue to run in the background until all pending interactions are complete.

This routine should be used with caution, especially if this is a remote session and an application uses System.exit(), as this can result in messages not being correctly and completely transferred to the Frontier server, and hence operations initiated with this SessionManager (such as job or task creation or removal) may not occur. To avoid this scenario, use destroy(-1) or call flush(-1) before calling destroy().

destroy() is equivalent to destroy(0).

Overrides:
destroy in class SessionManager
See Also:
SessionManager.destroy(int), SessionManager.flush(int)

destroy

public void destroy(int blockMillis)
Description copied from class: SessionManager
Close this session, and release any resources associated with it. Any further operations on this session manager or any jobs or tasks created through it will result in undefined behaviour.

Blocks at most approximately blockMillis milliseconds (or indefinitely if blockMillis == -1) for destruction to complete successfully; otherwise continues destruction but returns from the method call if possible while destruction continues.

Note that this version of destroy() should not be called from within a listener, as this could create a deadlock situation.

If a relatively short timeout is given, and this routine exits before interactions are complete, threads may continue attempting to complete various interactions in the background. If the application subsequently exits the JVM (e.g. via System.exit()), these interactions may not complete successfully -- for example, messages may not be correctly and complete transferred to the Frontier server, and hence operations initiated with this SessionManager (such as job or task creation or removal) may not occur.

Overrides:
destroy in class SessionManager

destroy

public void destroy(com.parabon.util.Listener completionListener)
Description copied from class: SessionManager
Close this session, and release any resources associated with it. Any further operations on this session manager or any jobs or tasks created through it will result in undefined behaviour.

Does not neccessarily block until destruction is actually complete: worker threads may continue to run in the background until all pending interactions are complete. Once all such interactions are complete, calls completionListener.alert(null); this may occur before destroy() returns (on either the current thread or another), or may occur after (on another thread).

Overrides:
destroy in class SessionManager

getUsername

public java.lang.String getUsername()

getPassword

public java.lang.String getPassword()

getMaxOutgoingMessageQueueSize

public int getMaxOutgoingMessageQueueSize()
Return the current maximum queue size for outgoing messages.


setMaxOutgoingMessageQueueSize

public void setMaxOutgoingMessageQueueSize(int size)
Limit the size of the outgoing message queue to approximately the specified number of messages. Does not enforce a hard limit, but serves as a hint not to significantly exceed the given size. This is useful in implementing a constant sized client. If the supplied value is zero or negative, no outgoing message queue size limit is used. Defaults to -1 (unlimited).


getMaxIncomingMessageQueueSize

public int getMaxIncomingMessageQueueSize()
Return the current maximum queue size for incoming messages.


setMaxIncomingMessageQueueSize

public void setMaxIncomingMessageQueueSize(int size)
Limit the size of the incoming message queue to approximately the specified number of messages. Does not enforce a hard limit, but serves as a hint not to significantly exceed the given size. This is useful in implementing a constant sized client. If the supplied value is zero or negative, no incoming message queue size limit is used. Defaults to -1 (unlimited).


getMaxOutgoingDataQueueSize

public int getMaxOutgoingDataQueueSize()
Return the current maximum queue size for outoing data.


setMaxOutgoingDataQueueSize

public void setMaxOutgoingDataQueueSize(int size)
Limit the size of the outgoing data queue to approximately the specified number of elements. Does not enforce a hard limit, but serves as a hint not to significantly exceed the given size. This is useful in implementing a constant sized client. If the supplied value is zero or negative, no outgoing data queue size limit is used. Defaults to -1 (unlimited).


reestablish

public void reestablish(int blockMillis)
                 throws TimeoutException
Description copied from class: SessionManager
Attempt to retrieve the latest list of jobs from the Frontier server, blocking until complete or until approximately the given number milliseconds have elapsed. If results are not obtained within the specitied timeout, a TimeoutException will be thrown, but the reestablish attempt might still result in the list of jobs being updated in the future.

If blockMillis==-1, the SessionManager will block indefinitely. Note that this method should never be called (except with a timeout of 0) from within an event listener or any other method which must complete in order for further events to be processed, as this would lead to a possible deadlock.

Specified by:
reestablish in class SessionManager
Throws:
TimeoutException

reestablish

public void reestablish(com.parabon.util.Listener completionListener)
Description copied from class: SessionManager
Attempt to retrieve the latest list of jobs from the Frontier server, returning immediately without waiting for the operation to complete. completionListener.alert(nul) will be called when reestablishment is complete.

Specified by:
reestablish in class SessionManager

getGlobalDataURI

public java.net.URI getGlobalDataURI()
                              throws java.net.URISyntaxException
Specified by:
getGlobalDataURI in class SessionManager
Throws:
java.net.URISyntaxException

getBaseClientURI

protected java.net.URI getBaseClientURI()
                                 throws java.net.URISyntaxException
Specified by:
getBaseClientURI in class SessionManager
Throws:
java.net.URISyntaxException

submitElement

public void submitElement(java.net.URI uri,
                          com.parabon.io.DataWrapper contents)
Specified by:
submitElement in class SessionManager

submitElementBundle

public void submitElementBundle(java.net.URI uri,
                                com.parabon.io.DataWrapper contents)

sendMessage

protected int sendMessage(com.parabon.message.Message m,
                          boolean barrier,
                          com.parabon.util.IntegerSet dependencies)

getSessionID

protected java.lang.String getSessionID()

addJob

protected void addJob(Job job)
Overrides:
addJob in class SessionManager

createJob

public Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_)
Description copied from class: SessionManager
Create and add a new Job with the given attributes. The given attributes may be modified after createJob returns without affecting the newly-created job.

Specified by:
createJob in class SessionManager

createJob

public Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_,
                     Job.JobConstraints constraints)

createJob

public Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_,
                     java.lang.String launchToken)

createJob

public Job createJob(java.util.Map<java.lang.String,java.lang.String> attributes_,
                     java.lang.String launchToken,
                     Job.JobConstraints constraints)

removeJob

protected void removeJob(Job job)
Overrides:
removeJob in class SessionManager

establishConnection

protected void establishConnection(int blockMillis)
                            throws ServerCommunicationException
Throws:
ServerCommunicationException

toString

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

initJobID

protected int initJobID()

createNewJobID

protected java.lang.String createNewJobID()

getNewJobID

protected java.lang.String getNewJobID()