Project 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()
          
 ReliableInputStream.MsgListener getListener()
          Returns the message listener for this pipe
 boolean hasNextMessage()
           
 boolean isInputShutdown()
          
 Message nextMessage()
           
 int read()
          
 int read(byte[] a, int offset, int length)
          
 void recv(Message msg)
          Receive this incoming message.
 void setClosing()
          prepare this input stream to being closed.
 void setTimeout(int timeout)
          Sets the Timeout attribute.
 
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

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

isInputShutdown

public boolean isInputShutdown()


setClosing

public void setClosing()
                throws IOException
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 satified with what we have acknoleged so far.

Throws:
IOException

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)
Description copied from interface: Incoming
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

hasNextMessage

public boolean hasNextMessage()

nextMessage

public Message nextMessage()
                    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

JXTA J2SE