ninja.activeproxy.path.io
Class PathInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--ninja.activeproxy.path.io.PathInputStream

public class PathInputStream
extends java.io.InputStream

The PathInputStream is a wrapper for a standard java InputStream which handles failure detection and recovery for Ninja paths. The general process for doing this is as follows: When an exception occurs on input or output, notify the operator passed into the constructor by calling the operator.pathFailed exception. This operator is considered to be the "path master" and is responsible for rebuilding part or all of the path when it is notified of an error.


Field Summary
 java.io.InputStream inputStream
           
 Operator operator
           
 java.lang.Object pathID
           
 boolean rebuildFlag
           
 
Fields inherited from class java.io.InputStream
SKIP_BUFFER_SIZE, skipBuffer
 
Constructor Summary
PathInputStream()
          Default constructor
PathInputStream(Operator operator, java.lang.Object pathID, java.io.InputStream inputStream)
          Create a new PathInputStream from the provided input stream.
 
Method Summary
 int available()
           
 void close()
          Same as default InputStream close method
 void mark(int readlimit)
          Same as default InputStream mark method
 boolean markSupported()
          Same as default InputStream markSupported method
 int read()
          The read method -- called too handle data input on this stream.
 int read(byte[] b)
          Try to fill array b with data.
 void reset()
          Same as default InputStream reset method
 long skip(long n)
          fill b with data, starting at offset off and for len bytes
 
Methods inherited from class java.io.InputStream
read
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

operator

public Operator operator

pathID

public java.lang.Object pathID

inputStream

public java.io.InputStream inputStream

rebuildFlag

public boolean rebuildFlag
Constructor Detail

PathInputStream

public PathInputStream()
Default constructor

PathInputStream

public PathInputStream(Operator operator,
                       java.lang.Object pathID,
                       java.io.InputStream inputStream)
Create a new PathInputStream from the provided input stream.
Parameters:
operator - The master operator for this path; should be notified on path failure
pathID - The pathID which this stream belongs to -- needs to be kept so the appropriate message can be passed to the pathFailed method of the path owner.
inputStream - The stream which we're wrapping
Method Detail

read

public int read()
         throws java.io.IOException
The read method -- called too handle data input on this stream.

Basically works as follows:

1) call inputStream.read() to block for incoming data

2) if an exception occurs, call the pathFailed method of the path master

3) if the path was rebuilt, throw a "PathInterruptedException" to the stream owner

4) if the path was unable to be rebuilt, thrown a "NoPathFoundException"

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException - which is either:

PathInterruptedException: The stream owner is being notified that the path had to be rebuilt and some data may have been lost. It is currently the responsibility of the path owner to hand end-to-end delivery constraints

NoPathFoundException: The stream could not be or was not rebuilt, but isn't allowing data to flow properly. The stream owner is basically SOL, but should attept to clean up and fail gracefully.


read

public int read(byte[] b)
         throws java.io.IOException
Try to fill array b with data.
Overrides:
read in class java.io.InputStream
Parameters:
b - An array of bytes to fill with data
Throws:
IOException, - see int read()<\i> above.

skip

public long skip(long n)
          throws java.io.IOException
fill b with data, starting at offset off and for len bytes
Overrides:
skip in class java.io.InputStream
Parameters:
b - The array to put data into
off - The offset to being writing data at
len - The number of bytes to read

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream

close

public void close()
           throws java.io.IOException
Same as default InputStream close method
Overrides:
close in class java.io.InputStream

mark

public void mark(int readlimit)
Same as default InputStream mark method
Overrides:
mark in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException
Same as default InputStream reset method
Overrides:
reset in class java.io.InputStream

markSupported

public boolean markSupported()
Same as default InputStream markSupported method
Overrides:
markSupported in class java.io.InputStream