ninja.activeproxy.path
Class Operator

java.lang.Object
  |
  +--ninja.rmi.NinjaRemoteObject
        |
        +--ninja.ispace.iSpaceService
              |
              +--ninja.activeproxy.path.SDSOperator
                    |
                    +--ninja.activeproxy.path.Operator

public abstract class Operator
extends SDSOperator
implements OperatorIF, java.lang.Runnable

Operator is the base abstract class that other operators should inherit from. There is only one method that operators must implement: run().


Field Summary
private  java.util.Hashtable pathIDToInputConnector
           
private  java.util.Hashtable pathIDToOperatorToNotify
           
private  java.util.Hashtable pathIDToOutputConnector
           
private  java.util.Hashtable pathIDToPathDescription
           
private  java.util.Hashtable pathIDToReader
           
private  java.util.Hashtable pathIDToRebuildFlag
           
private  java.util.Hashtable pathIDToWriter
           
private  java.util.Hashtable threadToPathID
           
 
Fields inherited from class ninja.activeproxy.path.SDSOperator
descr, running, serviceName, xmlData
 
Fields inherited from class ninja.rmi.NinjaRemoteObject
servref
 
Constructor Summary
Operator()
           
 
Method Summary
 java.lang.Object getCommunicationInfo(java.lang.Object pathID)
          Returns an object which the previous operator in the path will use to create a connection with this operator.
 java.lang.String getIdentification()
          Returns "local_hostname:current_time".
 java.lang.String getOperatorDescription()
          Returns an operator description.
 OperatorIF getOperatorToNotify(java.lang.Object pathID)
          Returns the operator which would be notified in case of path failure.
 PathDescription getPathDescription(java.lang.Object pathID)
           
 java.lang.Object getPathID(java.lang.Thread thread)
          Returns the pathID handled by the given thread.
 PathInputStream getReader(java.lang.Object pathID)
          Returns the reader for this operator in the path with given ID.
private  java.lang.Thread getThread(java.lang.Object pathID)
           
 PathOutputStream getWriter(java.lang.Object pathID)
          Returns the writer for this operator in the path with the given ID.
 java.net.InetAddress hostName()
           
 boolean isPathAlive(java.lang.Object pathID)
          Determines if the path specified by the given path ID still runs (there is a thread handling this path) through this operator.
 boolean isReaderReady(java.lang.Object pathID)
          Determines if the reader for this operator in the path has been set.
 boolean isReady(java.lang.Object pathID)
          Determines if the reader and writer for this operator in the path have been set.
 boolean isWriterReady(java.lang.Object pathID)
          Determines if the writer for this operator in the path has been set.
 void kill(java.lang.Object pathID)
          Tears down the connections established by this operator in the path, cleans up state associated with this path and kills its thread of execution.
 void loadInputConnector(java.net.URL inputConnectorURL, java.lang.String inputConnectorClass, java.lang.Object pathID)
          Loads and instantiates the input connector.
 void loadOutputConnector(java.net.URL outputConnectorURL, java.lang.String outputConnectorClass, java.lang.Object pathID)
          Loads and instantiates the output connector.
 void pathFailed(java.lang.Object pathID)
          Notifies another operator that path failed (previous operator, source operator where path originated or whatever operator was set by setOperatorToNotify.
 void resume(java.lang.Object pathID)
          Resume the thread managing the specified pathID.
abstract  void run()
           
 void setOperatorToNotify(OperatorIF operatorToNotify, java.lang.Object pathID)
          Sets the operator to notify in case of path failure; used for failure detection while the path is running.
 void setPathDescription(PathDescription path, java.lang.Object pid)
           
 void setReader(java.io.InputStream reader, java.lang.Object pathID)
          Sets the reader for this operator in the path with the given ID.
 void setupReader(java.lang.Object pathID)
          Sets up the reader for this operator in the path with the given ID.
 void setupWriter(OperatorIF nextOperator, java.lang.Object pathID)
          Sets up the writer for this operator in the path with the given ID.
 void setWriter(java.io.OutputStream writer, java.lang.Object pathID)
          Sets the writer for this operator in the path with the given ID.
 void start(java.lang.Object pathID)
          Starts a new thread of execution in the operator to service the path identified by path ID.
 void suspend(java.lang.Object pathID)
          Suspend the thread managing the specified pathID.
 
Methods inherited from class ninja.activeproxy.path.SDSOperator
destroy, getDescription, GetServiceDescriptor, GetServiceName, init
 
Methods inherited from class ninja.rmi.NinjaRemoteObject
exportObject, getStub, unexportObject
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

threadToPathID

private java.util.Hashtable threadToPathID

pathIDToInputConnector

private java.util.Hashtable pathIDToInputConnector

pathIDToOutputConnector

private java.util.Hashtable pathIDToOutputConnector

pathIDToReader

private java.util.Hashtable pathIDToReader

pathIDToWriter

private java.util.Hashtable pathIDToWriter

pathIDToOperatorToNotify

private java.util.Hashtable pathIDToOperatorToNotify

pathIDToPathDescription

private java.util.Hashtable pathIDToPathDescription

pathIDToRebuildFlag

private java.util.Hashtable pathIDToRebuildFlag
Constructor Detail

Operator

public Operator()
         throws java.rmi.RemoteException
Method Detail

loadInputConnector

public void loadInputConnector(java.net.URL inputConnectorURL,
                               java.lang.String inputConnectorClass,
                               java.lang.Object pathID)
                        throws java.lang.ClassNotFoundException,
                               java.lang.InstantiationException,
                               java.lang.IllegalAccessException,
                               java.rmi.RemoteException
Description copied from interface: OperatorIF
Loads and instantiates the input connector.
Specified by:
loadInputConnector in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
inputConnectorURL - URL where the input connector can be downloaded from.
inputConnectorClass - input connector class.
pathID - path ID.
Throws:
java.lang.ClassNotFoundException - if the class loader cannot find a definition for the input connector class.
java.lang.InstantiationException - if the instantiation of the input connector fails.
java.lang.IllegalAccessException - if the class or initializer of the input connector is not accessible.
java.rmi.RemoteException - if RMI failed.

loadOutputConnector

public void loadOutputConnector(java.net.URL outputConnectorURL,
                                java.lang.String outputConnectorClass,
                                java.lang.Object pathID)
                         throws java.lang.ClassNotFoundException,
                                java.lang.InstantiationException,
                                java.lang.IllegalAccessException,
                                java.rmi.RemoteException
Description copied from interface: OperatorIF
Loads and instantiates the output connector.
Specified by:
loadOutputConnector in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
outputConnectorURL - URL where the output connector can be downloaded from.
outputConnectorClass - output connector class.
pathID - path ID.
Throws:
java.lang.ClassNotFoundException - if the class loader cannot find a definition for the output connector class.
java.lang.InstantiationException - if the instantiation of the output connector fails.
java.lang.IllegalAccessException - if the class or initializer of the output connector is not accessible.
java.rmi.RemoteException - if RMI failed.

setupReader

public void setupReader(java.lang.Object pathID)
                 throws InvalidPathIDException,
                        java.rmi.RemoteException
Description copied from interface: OperatorIF
Sets up the reader for this operator in the path with the given ID.
Specified by:
setupReader in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Throws:
InvalidPathIDException - if path ID is invalid.
java.rmi.RemoteException - if RMI failed.

setupWriter

public void setupWriter(OperatorIF nextOperator,
                        java.lang.Object pathID)
                 throws InvalidPathIDException,
                        java.rmi.RemoteException
Description copied from interface: OperatorIF
Sets up the writer for this operator in the path with the given ID.
Specified by:
setupWriter in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
nextOperator - next operator in the path.
Throws:
InvalidPathIDException - if path ID is invalid.
java.rmi.RemoteException - if RMI failed.

setOperatorToNotify

public void setOperatorToNotify(OperatorIF operatorToNotify,
                                java.lang.Object pathID)
                         throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Sets the operator to notify in case of path failure; used for failure detection while the path is running. The operator to notify can be the previous operator in the path, the source operator where the path originated, etc.
Specified by:
setOperatorToNotify in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
operatorToNotify - operator to be notified in case of path failure.
pathID - path ID.
Throws:
java.rmi.RemoteException - if RMI failed.

getOperatorToNotify

public OperatorIF getOperatorToNotify(java.lang.Object pathID)
                               throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Returns the operator which would be notified in case of path failure.
Specified by:
getOperatorToNotify in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Returns:
the operator which would be notified in case of path failure.
Throws:
java.rmi.RemoteException - if RMI failed.

getCommunicationInfo

public java.lang.Object getCommunicationInfo(java.lang.Object pathID)
                                      throws InvalidPathIDException,
                                             java.rmi.RemoteException
Description copied from interface: OperatorIF
Returns an object which the previous operator in the path will use to create a connection with this operator.
Specified by:
getCommunicationInfo in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Returns:
object encapsulating enough information to help the previous operator in the path create a connection with the this operator; in case of socket connection, this can be an Integer object containing the port number on which thread is listening for connections in this operator; in case of operators on the same machine, this can be a PipedInputStream; etc.
Throws:
InvalidPathIDException - if the input connector of the next operator in the path is not set.
java.rmi.RemoteException - if RMI failed.

pathFailed

public void pathFailed(java.lang.Object pathID)
                throws java.rmi.RemoteException
Notifies another operator that path failed (previous operator, source operator where path originated or whatever operator was set by setOperatorToNotify. This method can be overloaded by subclasses; for example, the source operator in the path can request another path when this method is called, clean up state, etc.
Specified by:
pathFailed in interface OperatorIF
Parameters:
pathID - path ID.
Throws:
InvalidPathIDException - if there is no operator to notify.
java.rmi.RemoteException - if RMI failed.

getThread

private java.lang.Thread getThread(java.lang.Object pathID)

isPathAlive

public boolean isPathAlive(java.lang.Object pathID)
                    throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Determines if the path specified by the given path ID still runs (there is a thread handling this path) through this operator.
Specified by:
isPathAlive in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Returns:
true if path still runs through this operator; otherwise, false.
Throws:
java.rmi.RemoteException - if RMI failed.

isReady

public boolean isReady(java.lang.Object pathID)
                throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Determines if the reader and writer for this operator in the path have been set. If they have been setup, then the operator in the path is ready to read/write data and, thus, it is safe to start a new thread within the operator.
Specified by:
isReady in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Returns:
true if reader and writer have been set for this operator; otherwise, false.
Throws:
java.rmi.RemoteException - if RMI failed.

isReaderReady

public boolean isReaderReady(java.lang.Object pathID)
                      throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Determines if the reader for this operator in the path has been set.
Specified by:
isReaderReady in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Returns:
true if reader has been set for this operator; otherwise, false.
Throws:
java.rmi.RemoteException - if RMI failed.

isWriterReady

public boolean isWriterReady(java.lang.Object pathID)
                      throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Determines if the writer for this operator in the path has been set.
Specified by:
isWriterReady in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Returns:
true if writer has been set for this operator; otherwise, false.
Throws:
java.rmi.RemoteException - if RMI failed.

start

public void start(java.lang.Object pathID)
           throws InvalidPathIDException,
                  java.rmi.RemoteException
Description copied from interface: OperatorIF
Starts a new thread of execution in the operator to service the path identified by path ID.
Specified by:
start in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Throws:
InvalidPathIDException - if a thread couldn't be started for the path with the given ID; little strange, but let's just say that there was something wrong with the given path ID instead of creating some special exception; also thrown if path ID passed is null.
java.rmi.RemoteException - if RMI failed.

suspend

public void suspend(java.lang.Object pathID)
             throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Suspend the thread managing the specified pathID.
Specified by:
suspend in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - The pathID to suspend.
Throws:
java.rmi.RemoteException - if the operator is unavailable.

resume

public void resume(java.lang.Object pathID)
            throws java.rmi.RemoteException
Description copied from interface: OperatorIF
Resume the thread managing the specified pathID.
Specified by:
resume in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - The pathID to resume.
Throws:
java.rmi.RemoteException - if the operator is unavailable.

kill

public void kill(java.lang.Object pathID)
Description copied from interface: OperatorIF
Tears down the connections established by this operator in the path, cleans up state associated with this path and kills its thread of execution.
Specified by:
kill in interface OperatorIF
Tags copied from interface: OperatorIF
Parameters:
pathID - path ID.
Throws:
java.rmi.RemoteException - if RMI failed.

getIdentification

public java.lang.String getIdentification()
                                   throws java.rmi.RemoteException
Returns "local_hostname:current_time". Local host is in the format "%d.%d.%d.%d" and current time is in UTC.
Specified by:
getIdentification in interface OperatorIF
Throws:
java.rmi.RemoteException - if RMI failed.

hostName

public java.net.InetAddress hostName()
                              throws java.rmi.RemoteException
Specified by:
hostName in interface OperatorIF
Returns:
the hostname of this operator

getPathID

public java.lang.Object getPathID(java.lang.Thread thread)
Returns the pathID handled by the given thread.
Parameters:
thread - thread handling path going through operator.
Returns:
path ID or null if there is no path handled by the given thread.

setReader

public void setReader(java.io.InputStream reader,
                      java.lang.Object pathID)
Sets the reader for this operator in the path with the given ID.
Parameters:
reader - input stream to read from.
pathID - path ID.

getReader

public PathInputStream getReader(java.lang.Object pathID)
Returns the reader for this operator in the path with given ID.
Parameters:
pathID - path ID.
Returns:
input stream to read from.

setWriter

public void setWriter(java.io.OutputStream writer,
                      java.lang.Object pathID)
Sets the writer for this operator in the path with the given ID.
Parameters:
writer - output stream to write to.
pathID - path ID.

getWriter

public PathOutputStream getWriter(java.lang.Object pathID)
Returns the writer for this operator in the path with the given ID.
Parameters:
pathID - path ID.
Returns:
output stream to write to.

getOperatorDescription

public java.lang.String getOperatorDescription()
                                        throws java.rmi.RemoteException
Returns an operator description. This method looks in the working directory for a file describing this operator (an XML file). The source and destination operators in a path, which will not be SDSOperator's, must store in the current directory where the endpoint program is run (most of the time, this is the directory where the Java file for that program exists) a file describing this operator (inputs, outputs, etc.).
Specified by:
getOperatorDescription in interface OperatorIF
Returns:
an operator description or null if there was no operator description available.
Throws:
java.rmi.RemoteException - if RMI failed.

setPathDescription

public void setPathDescription(PathDescription path,
                               java.lang.Object pid)

getPathDescription

public PathDescription getPathDescription(java.lang.Object pathID)

run

public abstract void run()
Specified by:
run in interface java.lang.Runnable