net.i2p.client.streaming
Class MessageInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.i2p.client.streaming.MessageInputStream
All Implemented Interfaces:
Closeable

 class MessageInputStream
extends InputStream

Stream that can be given messages out of order yet present them in order.

I2PSession -> MessageHandler -> PacketHandler -> ConnectionPacketHandler -> MessageInputStream

This buffers unlimited data via messageReceived() - limiting / blocking is done in ConnectionPacketHandler.receivePacket().


Constructor Summary
MessageInputStream(I2PAppContext ctx)
           
 
Method Summary
 int available()
           
 void close()
           
 void closeReceived()
           
 long getHighestBlockId()
           
 long getHighestReadyBockId()
          What is the highest block ID we've completely received through?
 long[] getNacks()
          Retrieve the message IDs that are holes in our sequence - ones past the highest ready ID and below the highest received message ID.
 int getReadTimeout()
          how long a read() call should block (if less than 0, block indefinitely, but if it is 0, do not block at all)
 int getTotalReadySize()
          Same as available() but doesn't throw IOE
 boolean messageReceived(long messageId, ByteArray payload)
          A new message has arrived - toss it on the appropriate queue (moving previously pending messages to the ready queue if it fills the gap, etc).
 void notifyActivity()
           
 int read()
           
 int read(byte[] target)
           
 int read(byte[] target, int offset, int length)
           
 void setReadTimeout(int timeout)
           
(package private)  void streamErrorOccurred(IOException ioe)
          Stream b0rked, die with the given error
 void updateAcks(PacketLocal packet)
          Adds the ack-through and nack fields to a packet we are building for transmission
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageInputStream

public MessageInputStream(I2PAppContext ctx)
Method Detail

getHighestReadyBockId

public long getHighestReadyBockId()
What is the highest block ID we've completely received through?

Returns:
highest data block ID completely received

getHighestBlockId

public long getHighestBlockId()

getNacks

public long[] getNacks()
Retrieve the message IDs that are holes in our sequence - ones past the highest ready ID and below the highest received message ID. This may return null if there are no such IDs.

Returns:
array of message ID holes, or null if none

updateAcks

public void updateAcks(PacketLocal packet)
Adds the ack-through and nack fields to a packet we are building for transmission


getReadTimeout

public int getReadTimeout()
how long a read() call should block (if less than 0, block indefinitely, but if it is 0, do not block at all)

Returns:
how long read calls should block, 0 or less indefinitely block

setReadTimeout

public void setReadTimeout(int timeout)

closeReceived

public void closeReceived()

notifyActivity

public void notifyActivity()

messageReceived

public boolean messageReceived(long messageId,
                               ByteArray payload)
A new message has arrived - toss it on the appropriate queue (moving previously pending messages to the ready queue if it fills the gap, etc).

Parameters:
messageId - ID of the message
payload - message payload
Returns:
true if this is a new packet, false if it is a dup

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] target)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] target,
                int offset,
                int length)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

getTotalReadySize

public int getTotalReadySize()
Same as available() but doesn't throw IOE


close

public void close()
Specified by:
close in interface Closeable
Overrides:
close in class InputStream

streamErrorOccurred

void streamErrorOccurred(IOException ioe)
Stream b0rked, die with the given error