Project JXTA

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

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

public class ReliableOutputStream
extends OutputStream
implements Incoming

Accepts data and packages it into messages for sending to the remote. The messages are kept in a retry queue until the remote peer acknowledges receipt of the message.


Field Summary
(package private)  List retrQ
          The collection of messages available for re-transmission.
 
Constructor Summary
ReliableOutputStream(Outgoing outgoing)
           
ReliableOutputStream(Outgoing outgoing, FlowControl fc)
           
 
Method Summary
 void ackReceived(int seqnum, int[] sackList)
          Process an ACK Message.
 void close()
          

We don't current support linger.

 int getMaxAck()
           
 int getSeqNumber()
           
 boolean isQueueEmpty()
           
 boolean isQueueFull()
           
 void recv(Message msg)
          Receive this incoming message.
 int send(Message msg)
           
 void setClosing()
          indicate that we're in the process of closing.
 void waitQueueEvent(long timeout)
           
 void write(byte[] b, int off, int len)
          
 void write(int c)
          
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

retrQ

List retrQ
The collection of messages available for re-transmission. elements are RetrQElt

Constructor Detail

ReliableOutputStream

public ReliableOutputStream(Outgoing outgoing)

ReliableOutputStream

public ReliableOutputStream(Outgoing outgoing,
                            FlowControl fc)
Method Detail

close

public void close()
           throws IOException

We don't current support linger.

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

setClosing

public void setClosing()
indicate that we're in the process of closing. To respect the semantics of close()/isClosed(), we do not set the closed flag, yet. Instead, we set the flag "closing", which simply garantees that no new message will be queued. This, in combination with getSequenceNumber and getMaxAck, and waitQevent, enables fine grain control of the tear down process.


write

public void write(int c)
           throws IOException

Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException

Overrides:
write in class OutputStream
Throws:
IOException

send

public int send(Message msg)
         throws IOException
Throws:
IOException

getMaxAck

public int getMaxAck()

getSeqNumber

public int getSeqNumber()

isQueueFull

public boolean isQueueFull()

isQueueEmpty

public boolean isQueueEmpty()

waitQueueEvent

public void waitQueueEvent(long timeout)
                    throws InterruptedException
Throws:
InterruptedException

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

ackReceived

public void ackReceived(int seqnum,
                        int[] sackList)
Process an ACK Message. We remove ACKed messages from the retry queue. We only acknowledge messages received in sequence. The seqnum is for the largest unacknowledged seqnum the receipient has received. The sackList is a sequence of all of the received messages in the sender's input Q. All will be sequence numbers higher than the sequential ACK seqnum. Recepients are passive and only ack upon the receipt of an in sequence message. They depend on our RTO to fill holes in message sequences.


JXTA J2SE