com.cosylab.jcosyne.server
Class ResultRepository

java.lang.Object
  extended byjavax.management.NotificationBroadcasterSupport
      extended bycom.cosylab.jcosyne.server.RemoteTask
          extended bycom.cosylab.jcosyne.server.ResultRepository
All Implemented Interfaces:
javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, RemoteTaskMBean, ResultRepositoryMBean, java.lang.Runnable

public class ResultRepository
extends RemoteTask
implements ResultRepositoryMBean

This is the implementation of the functionality parametrized by ResultRepositoryMBean. Result repository stores results of the remote task executions in the form (remote task invocation index, infiles, outfiles) triplets. All these files are stored in the result repository path, which is obtained by concatenating user's home directory with RepositoryRoot attribute. This attribute is set by the JMX server and is read from the server configuration file. Indices are stored into standalone files in the INDEX subdirectory of result repository, each file is named simply with a number, which is the ID of that remote task invocation. Input files are stored in INPUT and output files into OUTPUT subdirectories. Output subdirectories furthermore contain subdirectories that have names such as "2003-11-08", i.e. initial timestamp dates of the algorithm runs. Input and output files are ASCII TXT by design contract, while indices are in Java serialized form. Result repository parses the indices, creates new ones, creates new output files on request of remote tasks, opens input files from the input location. It also tracks, for each executing remote task, which input and output files it needs and records that into the remote task invocation instance for that invocation.

Author:
Gasper Tkacik (gasper.tkacik@cosylab.com)
See Also:
Constants

Field Summary
static java.lang.String INDEX
          Index subdirectory of the result repository dir.
static java.lang.String INPUT
          Input subdirectory of the result repository dir.
static java.lang.String OUTPUT
          Output subdirectory of the result repository dir.
 
Fields inherited from class com.cosylab.jcosyne.server.RemoteTask
log, name, running, sequence, SERVER_DELEGATE, serverRef, suspended
 
Constructor Summary
ResultRepository()
          Create a new instance of result repository.
 
Method Summary
 void addRecord(RemoteTaskInvocation invoc, javax.management.ObjectName target)
          Adds a remote task invocation record to the file system.
 void deleteRecord(RemoteTaskInvocation rti, boolean deleteOutputs)
          Deletes the record from the result repository, optionally deleting outputs as well.
 byte[] getInputFile(java.lang.String name)
          Returns the input file as a complete byte array that can be serialized to remote computer.
 java.lang.String getInputRepositoryPath()
          Returns the concatenation of the repository root with the input directory.
 byte[] getOutputFile(java.lang.String name)
          Returns the complete output file in the byte array form.
 java.lang.String getOutputRepositoryPath()
          Returns the concatenation of the repository root with the output directory.
 RemoteTaskInvocation[] getRecords(java.util.Map criteria)
          Returns all remote task invocations in the result repository that satisfy the supplied criteria.
 java.lang.String getRepositoryRoot()
          Returns the value set by setRepositoryRoot()
protected  void internalInitialize()
          Does NOP.
 boolean isReadyToRun()
          This is a framework remote task and is never executed.
 boolean isRecording()
          Returns the value of the recording attribute.
 void postRegister(java.lang.Boolean value)
          Overloaded post register form adds a server listener that tracks new registering and old unregistering remote tasks.
 void preDeregister()
          Removes itself as the server listener from the server and remove itself as execution listener from all remote tasks.
 java.lang.String requestInputFilename(javax.management.ObjectName task, java.lang.String name)
          Creates a new input filename for a given remote task.
 java.lang.String requestOutputFilename(javax.management.ObjectName task, java.lang.String sub)
          Creates a new output filename for a given task.
 void run()
          Do NOP.
 void setRecording(boolean recording)
          If set to false the repository will not produce any output.
 void setRepositoryRoot(java.lang.String pathRelativeToHome)
          Sets the root directory for the repository.
 int storeRecord(RemoteTaskInvocation rti, boolean assignNewID)
          Store a remote task invocation record that has supposedly been initialized by some other agent (or modified by the user inside a GUI, for example).
 
Methods inherited from class com.cosylab.jcosyne.server.RemoteTask
checkState, copyStateFrom, copyStateFrom, executeScript, getInputResource, getLastScriptResult, getName, getOutputResource, getPostExecutionScript, getPostInitializactionScript, getProgress, getSequence, getState, initialize, isAborting, isFinished, isInitialized, isRunning, isSuspended, loadMatrix, loadMatrix, notifyAttributeChange, notifyExecutionStarts, notifyExecutionStops, postDeregister, preRegister, saveMatrix, setFinished, setPostExecutionScript, setPostInitializationScript, setProgress, setRunning, setSuspended
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.cosylab.jcosyne.server.RemoteTaskMBean
copyStateFrom, copyStateFrom, equals, executeScript, getLastScriptResult, getName, getPostExecutionScript, getPostInitializactionScript, getProgress, getState, hashCode, initialize, isFinished, isInitialized, isRunning, isSuspended, setPostExecutionScript, setPostInitializationScript, setRunning, setSuspended
 

Field Detail

INPUT

public static final java.lang.String INPUT
Input subdirectory of the result repository dir. Algorithm input files are stored here.

See Also:
Constant Field Values

OUTPUT

public static final java.lang.String OUTPUT
Output subdirectory of the result repository dir. Output files are stored here, in subdirectories named by dates of execution.

See Also:
Constant Field Values

INDEX

public static final java.lang.String INDEX
Index subdirectory of the result repository dir. Serialized instances of the RemoteTaskInvocation class are stored here.

See Also:
Constant Field Values
Constructor Detail

ResultRepository

public ResultRepository()
Create a new instance of result repository.

Method Detail

addRecord

public void addRecord(RemoteTaskInvocation invoc,
                      javax.management.ObjectName target)
Adds a remote task invocation record to the file system. First locates a free filename (index that is not yet assigned), opens the INDEX location andserializes the invoc to the output stream. Finally removes the invocation data from the list of active invocations. Notice that all processing is quietly skipped if the Recording attribute is false.

Parameters:
invoc - the invocation data to serialize
target - the name of the remote task for which data is being serialized

setRepositoryRoot

public void setRepositoryRoot(java.lang.String pathRelativeToHome)
Sets the root directory for the repository. This is a subdirectory under users home directory and has no leading or trailing file separator characters. This attribute is set automatically by the JMX server at startup and is parsed from the setup configuration file.

Specified by:
setRepositoryRoot in interface ResultRepositoryMBean
Parameters:
pathRelativeToHome - pathname that will be appended to home directory to locate the result repository

getRepositoryRoot

public java.lang.String getRepositoryRoot()
Returns the value set by setRepositoryRoot()

Specified by:
getRepositoryRoot in interface ResultRepositoryMBean
Returns:
the respository root path
See Also:
setRepositoryRoot(java.lang.String)

getOutputRepositoryPath

public java.lang.String getOutputRepositoryPath()
Returns the concatenation of the repository root with the output directory.

Specified by:
getOutputRepositoryPath in interface ResultRepositoryMBean
Returns:
append the return value to the home directory to get the output dir

getInputRepositoryPath

public java.lang.String getInputRepositoryPath()
Returns the concatenation of the repository root with the input directory.

Specified by:
getInputRepositoryPath in interface ResultRepositoryMBean
Returns:
append the return value to the home directory to get the input dir

requestInputFilename

public java.lang.String requestInputFilename(javax.management.ObjectName task,
                                             java.lang.String name)
Creates a new input filename for a given remote task. The name is relative to the input directory. The requested input will be automatically appended as needed input resource to the remote task invocation for this algorithm run.

Specified by:
requestInputFilename in interface ResultRepositoryMBean
Parameters:
task - the task requiring access to the input resource
name - input file name, without the prefixing input directory path
Returns:
the absolute name of the input file

requestOutputFilename

public java.lang.String requestOutputFilename(javax.management.ObjectName task,
                                              java.lang.String sub)
Creates a new output filename for a given task. Automatically adds a newly created name to the list of output files for the current algorithm run.

Specified by:
requestOutputFilename in interface ResultRepositoryMBean
Parameters:
task - task requesting a new output filename
sub - since the task can produce multiple output files, it can separate them with sub strings; these become part of the output file name; i.e. the task may need one file for storing eigenvectors and one for eigenvalues; customarily the sub stands for the attribute being saved to the output; can be null.
Returns:
absolute filename; note that all paths do not necessarily exist

isRecording

public boolean isRecording()
Returns the value of the recording attribute. If false, the result repository does no writing. This value is set by JMX server at startup.

Specified by:
isRecording in interface ResultRepositoryMBean
Returns:
true iff this repository is keeping results on permanent storage of current activities
See Also:
Constants

setRecording

public void setRecording(boolean recording)
If set to false the repository will not produce any output. In other words, nothing will be saved for the algorithm runs. JMX Server sets this value at startup, when result repository is constructed.

Specified by:
setRecording in interface ResultRepositoryMBean
Parameters:
recording - true iff the repository should record to permanent storage the results of remote task processing; if false the repository does nothing

postRegister

public void postRegister(java.lang.Boolean value)
Overloaded post register form adds a server listener that tracks new registering and old unregistering remote tasks.

Specified by:
postRegister in interface javax.management.MBeanRegistration
Overrides:
postRegister in class RemoteTask
Parameters:
value - passed to super

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Removes itself as the server listener from the server and remove itself as execution listener from all remote tasks.

Specified by:
preDeregister in interface javax.management.MBeanRegistration
Overrides:
preDeregister in class RemoteTask
Throws:
java.lang.Exception

internalInitialize

protected void internalInitialize()
Does NOP.

Specified by:
internalInitialize in class RemoteTask
See Also:
RemoteTask.initialize()

getRecords

public RemoteTaskInvocation[] getRecords(java.util.Map criteria)
Returns all remote task invocations in the result repository that satisfy the supplied criteria. The criteria are a list of string name string value pairs. Names (or criterion keys) are defined in Constants, where it is also explained what values are accepted for a given key.

Specified by:
getRecords in interface ResultRepositoryMBean
Parameters:
criteria - a map of (string, string) name value pairs which will be used to filter the returning RTI set, can be null in which case all records are returned
Returns:
the array of all invocation data satisfying the criteria
See Also:
Constants

getInputFile

public byte[] getInputFile(java.lang.String name)
Returns the input file as a complete byte array that can be serialized to remote computer.

Specified by:
getInputFile in interface ResultRepositoryMBean
Parameters:
name - the input file name to open, relative to the input repository path
Returns:
byte array with the complete file

getOutputFile

public byte[] getOutputFile(java.lang.String name)
Returns the complete output file in the byte array form.

Specified by:
getOutputFile in interface ResultRepositoryMBean
Parameters:
name - the name of the file to open, relative to the repository output path
Returns:
the complete file as a byte array

storeRecord

public int storeRecord(RemoteTaskInvocation rti,
                       boolean assignNewID)
Store a remote task invocation record that has supposedly been initialized by some other agent (or modified by the user inside a GUI, for example).

Specified by:
storeRecord in interface ResultRepositoryMBean
Parameters:
rti - the remote task invocation to store
assignNewID - if true, a new unique ID will be assigned by looking for the first free ID in the index directory of the repository; if false the ID supplied in rti will be used and if existing file with the same ID already exists, it will be overwritten.
Returns:
ID under which the record was stored

deleteRecord

public void deleteRecord(RemoteTaskInvocation rti,
                         boolean deleteOutputs)
Deletes the record from the result repository, optionally deleting outputs as well. Note that inputs are never deleted by this method, because they may be shared with other invocations.

Specified by:
deleteRecord in interface ResultRepositoryMBean
Parameters:
rti - remote task invocation to delete; this method uses the ID in the rti to locate the appropriate index file
deleteOutputs - iff true, the outputs specified in the rti will be deleted from the output repository location as well

run

public void run()
Do NOP.

Specified by:
run in interface java.lang.Runnable

isReadyToRun

public boolean isReadyToRun()
This is a framework remote task and is never executed.

Specified by:
isReadyToRun in interface RemoteTaskMBean
Returns:
false