org.ourgrid.gridmachine.useragent
Class UserAgentClient

java.lang.Object
  extended by org.ourgrid.gridmachine.useragent.UserAgentClient
All Implemented Interfaces:
java.io.Serializable, GumClient
Direct Known Subclasses:
FakeGumClient, SleeperFakeUserAgentClient

public class UserAgentClient
extends java.lang.Object
implements GumClient

Concrete implementation of the GumClient interface that provides methods for remote execution, file transfer and information retrieval like remote file information.

It is the representation of a Gum in the broker side. It will use the methods of Gum to provide services to the broker users

See Also:
Serialized Form

Field Summary
protected  java.nio.channels.FileChannel channel
          Lock-related objects.
protected  java.util.Map<ExecutorHandle,ExecutorHandle> executorHandles
          Map containing all the executor handles of the remote executions on this UserAgent.
static java.lang.String FLAG_COMMAND
          This constant is the flag used in the REM_EXEC spec field to indicate the command must be executed at the Gum.
static java.lang.String FLAG_MACHINE
          This constant is the flag used in the REM_EXEC spec field to indicate which Gum must execute the command.
 java.nio.channels.FileLock localFileLock
          This object represents the lock for a given file.
 java.io.FileInputStream localFileStream
          The FileInputStream used to read a local file that will be transfered to the grid machine.
protected  java.lang.String playpenPath
          The string representation for the playpen used in a given execution.
 java.io.RandomAccessFile randomFile
          This abstract representation for a Random Access file is used to obtain a exclusive lock during file transfer operations.
protected  Gum ua
          A reference to the grid machine.
 
Constructor Summary
UserAgentClient(Gum gum, GumSpec gumSpec)
          Default constructor.
 
Method Summary
 java.lang.String createPlaypen(int size)
           
 java.lang.String createStorageDirectory()
           
 boolean equals(java.lang.Object o)
           
 boolean fileExists(java.io.File file)
           
 void getFile(java.lang.String remoteFile, java.lang.String localFile)
           
 GumSpec getGumSpec()
          Retrieves the gum specification cached on the client side
 long getRemoteFileLastModification(java.io.File remoteFile, boolean normalized)
           
 long getRemoteFileLength(java.io.File file)
           
 ExecutorResult getResult(ExecutorHandle handle)
           
 GumStatus getStatus()
           
 java.lang.String getStorageDirectory()
           
 Gum getUAServer()
           
 void putFile(java.lang.String localFile, java.lang.String remoteFile)
           
 ExecutorHandle remoteExecute(java.lang.String remoteDir, java.lang.String command, java.util.Map<java.lang.String,java.lang.String> environmentVars)
           
 void startReplica()
           
 void stopReplica()
           
 void storeFile(java.lang.String localFilePath, java.lang.String remoteFilePath)
          This method stores a local file into the remote storage location.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAG_COMMAND

public static final java.lang.String FLAG_COMMAND
This constant is the flag used in the REM_EXEC spec field to indicate the command must be executed at the Gum.

See Also:
Constant Field Values

FLAG_MACHINE

public static final java.lang.String FLAG_MACHINE
This constant is the flag used in the REM_EXEC spec field to indicate which Gum must execute the command.

See Also:
Constant Field Values

localFileStream

public transient java.io.FileInputStream localFileStream
The FileInputStream used to read a local file that will be transfered to the grid machine.


channel

protected transient java.nio.channels.FileChannel channel
Lock-related objects.


ua

protected Gum ua
A reference to the grid machine.


executorHandles

protected java.util.Map<ExecutorHandle,ExecutorHandle> executorHandles
Map containing all the executor handles of the remote executions on this UserAgent. The map is updated on each getResult() invocation.


randomFile

public transient java.io.RandomAccessFile randomFile
This abstract representation for a Random Access file is used to obtain a exclusive lock during file transfer operations.


localFileLock

public transient java.nio.channels.FileLock localFileLock
This object represents the lock for a given file. This lock is intended to be exclusive and should avoid concurrent writing operations.


playpenPath

protected java.lang.String playpenPath
The string representation for the playpen used in a given execution.

Constructor Detail

UserAgentClient

public UserAgentClient(Gum gum,
                       GumSpec gumSpec)
Default constructor.

Parameters:
gum - a remote reference the the grid machine
gumSpec - information about the gum features
Method Detail

storeFile

public void storeFile(java.lang.String localFilePath,
                      java.lang.String remoteFilePath)
               throws UnableToExecuteException,
                      UnavailableGumException,
                      FileTransferException
Description copied from interface: GumClient
This method stores a local file into the remote storage location. In general that location is the ".mgstorage" directory in a shared file system at the remote site.

Specified by:
storeFile in interface GumClient
Parameters:
localFilePath - A string representing the local file path.
remoteFilePath - A string representing the remote file path.
Throws:
UnavailableGumException - if the requested GM is not available.
FileTransferException - if some transfer problems happen.
UnableToExecuteException

fileExists

public boolean fileExists(java.io.File file)
                   throws UnavailableGumException
Specified by:
fileExists in interface GumClient
Throws:
UnavailableGumException - Occurs if the requested processor is not available.
See Also:
Gum.fileExists(java.io.File)

getRemoteFileLength

public long getRemoteFileLength(java.io.File file)
                         throws UnavailableGumException,
                                UnableToExecuteException
Specified by:
getRemoteFileLength in interface GumClient
Throws:
UnavailableGumException - if the requested GM is not available.
UnableToExecuteException - Occurs if some operation could not be performed in order to get the remote file length.
See Also:
Gum.getRemoteFileLength(java.io.File)

getRemoteFileLastModification

public long getRemoteFileLastModification(java.io.File remoteFile,
                                          boolean normalized)
                                   throws UnavailableGumException,
                                          UnableToExecuteException
Specified by:
getRemoteFileLastModification in interface GumClient
Throws:
UnavailableGumException - if the requested GM is not available.
UnableToExecuteException - Occurs if some operation could not be performed in order to get the remote file length.
See Also:
(java.io.File, boolean)

createPlaypen

public java.lang.String createPlaypen(int size)
                               throws UnavailableGumException,
                                      UnableToCreatePlaypenException
Specified by:
createPlaypen in interface GumClient
Throws:
UnavailableGumException - if the requested GM is not available.
UnableToCreatePlaypenException
See Also:
Gum.createPlaypen(int)

getUAServer

public Gum getUAServer()
                throws java.rmi.RemoteException
Returns:
the gum reference
Throws:
java.rmi.RemoteException

createStorageDirectory

public java.lang.String createStorageDirectory()
                                        throws UnavailableGumException,
                                               UnableToCreateStorageException
Specified by:
createStorageDirectory in interface GumClient
Throws:
UnavailableGumException - if the requested GM is not available.
UnableToCreateStorageException - if the creation of the directory was not possible due to permission denied, disk space is full, etc.
See Also:
Gum.createStorageDirectory()

getStorageDirectory

public java.lang.String getStorageDirectory()
                                     throws UnavailableGumException
Specified by:
getStorageDirectory in interface GumClient
Throws:
UnavailableGumException - if the requested GM is not available.
See Also:
Gum.getStorageDirectory()

remoteExecute

public ExecutorHandle remoteExecute(java.lang.String remoteDir,
                                    java.lang.String command,
                                    java.util.Map<java.lang.String,java.lang.String> environmentVars)
                             throws UnavailableGumException,
                                    UnableToExecuteException
Specified by:
remoteExecute in interface GumClient
Throws:
UnavailableGumException - Throws if the contact with the remote machine is lost.
UnableToExecuteException - Throws if cannot execute the command on the machine. For example, if the command does not exist or the machine already is executing a remote task command.
See Also:
Gum.remoteExecute(java.lang.String, java.lang.String, java.util.Map)

putFile

public void putFile(java.lang.String localFile,
                    java.lang.String remoteFile)
             throws UnavailableGumException,
                    FileTransferException
Specified by:
putFile in interface GumClient
Throws:
FileTransferException - Throws if can not transfer the file.
UnavailableGumException
See Also:
Gum.putFile(String, byte[], boolean)

getFile

public void getFile(java.lang.String remoteFile,
                    java.lang.String localFile)
             throws UnavailableGumException,
                    FileTransferException
Specified by:
getFile in interface GumClient
Throws:
FileTransferException - if the file cannot be transfered.
UnavailableGumException
See Also:
Gum.getFile(String, long, int)

getResult

public ExecutorResult getResult(ExecutorHandle handle)
                         throws UnavailableGumException,
                                UnableToExecuteException
Specified by:
getResult in interface GumClient
Throws:
UnavailableGumException
UnableToExecuteException
See Also:
Gum.getResult(org.ourgrid.common.executor.ExecutorHandle)

getStatus

public GumStatus getStatus()
Specified by:
getStatus in interface GumClient
See Also:
Gum.getStatus()

startReplica

public void startReplica()
                  throws UnavailableGumException
Specified by:
startReplica in interface GumClient
Throws:
UnavailableGumException - If the contact with grid machine is lost.
See Also:
Gum.startReplica()

stopReplica

public void stopReplica()
                 throws UnavailableGumException
Specified by:
stopReplica in interface GumClient
Throws:
UnavailableGumException - If the contact with grid machine is lost.
See Also:
Gum.stopReplica()

equals

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

getGumSpec

public GumSpec getGumSpec()
Description copied from interface: GumClient
Retrieves the gum specification cached on the client side

Specified by:
getGumSpec in interface GumClient