JXTA

net.jxta.impl.util.pipe.reliable
Class ReliableInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.jxta.impl.util.pipe.reliable.ReliableInputStream
All Implemented Interfaces:
Closeable, Incoming

public class ReliableInputStream
extends InputStream
implements Incoming

Acts as a reliable input stream. Accepts data which arrives in messages and orders it.


Nested Class Summary
static interface ReliableInputStream.MsgListener
          The listener interface for receiving Message
 
Field Summary
(package private)  long nextRetransRequest
           
 
Constructor Summary
ReliableInputStream(Outgoing outgoing, int timeout)
           
ReliableInputStream(Outgoing outgoing, int timeout, ReliableInputStream.MsgListener listener)
           
 
Method Summary
 int available()
          
 void close()
          

This is an explicit close operation.

 ReliableInputStream.MsgListener getListener()
          Returns the message listener for this pipe
 boolean hasNextMessage()
           
 boolean isInputShutdown()
          Returns true if closed
(package private)  Message nextMessage(boolean blocking)
           
 int read()
          
 int read(byte[] a, int offset, int length)
          
 void recv(Message msg)
          Receive this incoming message.
 void setTimeout(int timeout)
          Sets the Timeout attribute.
 void softClose()
          Prepare this input stream to being closed.
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextRetransRequest

long nextRetransRequest
Constructor Detail

ReliableInputStream

public ReliableInputStream(Outgoing outgoing,
                           int timeout)

ReliableInputStream

public ReliableInputStream(Outgoing outgoing,
                           int timeout,
                           ReliableInputStream.MsgListener listener)
Method Detail

close

public void close()
           throws IOException

This is an explicit close operation. All subsequent read() operations will fail.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

isInputShutdown

public boolean isInputShutdown()
Returns true if closed

Returns:
true if closed

softClose

public void softClose()
Prepare this input stream to being closed. It will still deliver the packets that have been received, but nothing more. This is meant to be called in response to the other side having initiated closure. We assume that when the other side does it it means that it is satisfied with what we have acknowledged so far.


setTimeout

public void setTimeout(int timeout)
Sets the Timeout attribute. A timeout of 0 blocks forever

Parameters:
timeout - The new soTimeout value

read

public int read()
         throws IOException

Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] a,
                int offset,
                int length)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

recv

public void recv(Message msg)
Receive this incoming message. This method should return quickly. If the receiving class needs to do substantial work with incoming messages, it should insert this message into a queue and then drain the queue processing the messages in its own thread.

Specified by:
recv in interface Incoming
Parameters:
msg - the message

hasNextMessage

public boolean hasNextMessage()

nextMessage

Message nextMessage(boolean blocking)
              throws IOException
Throws:
IOException

available

public int available()
              throws IOException

Overrides:
available in class InputStream
Throws:
IOException

getListener

public ReliableInputStream.MsgListener getListener()
Returns the message listener for this pipe

Returns:
MsgListener

JXSE