com.threerings.nio.conman
Class ConnectionManager.OverflowQueue

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<byte[]>
              extended by com.threerings.nio.conman.ConnectionManager.OverflowQueue
All Implemented Interfaces:
ConnectionManager.PartialWriteHandler, Serializable, Cloneable, Iterable<byte[]>, Collection<byte[]>, List<byte[]>, RandomAccess
Enclosing class:
ConnectionManager

protected class ConnectionManager.OverflowQueue
extends ArrayList<byte[]>
implements ConnectionManager.PartialWriteHandler

Used to handle messages for a client whose network buffer has filled up because their outgoing network buffer has filled up. This can happen if the client receives many messages in rapid succession or if they receive very large messages or if they become unresponsive and stop acknowledging network packets sent by the server. We want to accomodate the first to circumstances and recognize the third as quickly as possible so that we can disconnect the client and propagate that information up to the higher levels so that further messages are not queued up for the unresponsive client.

See Also:
Serialized Form

Field Summary
protected  int _msgs
          A couple of counters.
protected  ByteBuffer _partial
          The remains of a message that was only partially written on its first attempt.
protected  int _partials
          A couple of counters.
 Connection conn
          The connection for which we're managing overflow.
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ConnectionManager.OverflowQueue(Connection conn, ByteBuffer message)
          Creates a new overflow queue for the supplied connection and with the supplied initial partial message.
 
Method Summary
 void handlePartialWrite(Connection wconn, ByteBuffer buffer)
           
 String toString()
           
 boolean writeOverflowMessages(long iterStamp)
          Called each time through the ConnectionManager.iterate() loop, this attempts to send any remaining partial message and all subsequent messages in the overflow queue.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

conn

public Connection conn
The connection for which we're managing overflow.


_partial

protected ByteBuffer _partial
The remains of a message that was only partially written on its first attempt.


_msgs

protected int _msgs
A couple of counters.


_partials

protected int _partials
A couple of counters.

Constructor Detail

ConnectionManager.OverflowQueue

public ConnectionManager.OverflowQueue(Connection conn,
                                       ByteBuffer message)
Creates a new overflow queue for the supplied connection and with the supplied initial partial message.

Method Detail

writeOverflowMessages

public boolean writeOverflowMessages(long iterStamp)
                              throws IOException
Called each time through the ConnectionManager.iterate() loop, this attempts to send any remaining partial message and all subsequent messages in the overflow queue.

Returns:
true if all messages in this queue were successfully sent, false if there remains data to be sent on the next loop.
Throws:
IOException - if an error occurs writing data to the connection or if we have been unable to write any data to the connection for ten seconds.

handlePartialWrite

public void handlePartialWrite(Connection wconn,
                               ByteBuffer buffer)
Specified by:
handlePartialWrite in interface ConnectionManager.PartialWriteHandler

toString

public String toString()
Overrides:
toString in class AbstractCollection<byte[]>