ninja.activeproxy.path.io
Class PathOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--ninja.activeproxy.path.io.PathOutputStream

public class PathOutputStream
extends java.io.OutputStream

The PathOutputStream 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
 Operator operator
           
 java.io.OutputStream outputStream
           
 java.lang.Object pathID
           
 boolean rebuildFlag
           
 
Constructor Summary
PathOutputStream()
          Default constructor
PathOutputStream(Operator operator, java.lang.Object pathID, java.io.OutputStream outputStream)
          Create a new PathOutputStream from the provided output stream.
 
Method Summary
 void close()
           
 void flush()
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
          The write method -- called too handle data output on this stream.
 
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

outputStream

public java.io.OutputStream outputStream

rebuildFlag

public boolean rebuildFlag
Constructor Detail

PathOutputStream

public PathOutputStream()
Default constructor

PathOutputStream

public PathOutputStream(Operator operator,
                        java.lang.Object pathID,
                        java.io.OutputStream outputStream)
Create a new PathOutputStream from the provided output 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.
outputStream - The stream which we're wrapping
Method Detail

write

public void write(int b)
           throws java.io.IOException
The write method -- called too handle data output on this stream.

Basically works as follows:

1) call outputStream.write() to push the specified byte onto the stream

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:
write in class java.io.OutputStream
Parameters:
b - A byte of data to write
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.


write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream

flush

public void flush()
           throws java.io.IOException
Overrides:
flush in class java.io.OutputStream

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.io.OutputStream