asynctcp
Class ASyncTCPMessageQueue

java.lang.Object
  extended by asynctcp.ASyncTCPMessageQueue
All Implemented Interfaces:
MessageQueue

public class ASyncTCPMessageQueue
extends java.lang.Object
implements MessageQueue

A queue of messages ready to be delivered over a given connection.

Author:
Michael Parker

Method Summary
 ASyncTCPMessageHandle enqueue(Message msg)
          Enqueues the Message argument for delivery to the destination.
 int getCapacity()
          Returns the capacity of the queue; attempting to enqueue a message in a queue whose length meets or exceeds its capacity will fail.
 Connection getConnection()
          Returns the Connection object with which this queue is associated.
 java.util.List<ASyncTCPMessageHandle> getEnqueued()
          Returns handles to the enqueued messages.
 int getLength()
          Returns the number of messages enqueued to the destination.
 ASyncTCPMessageHandle getSending()
          Returns the handle to the message currently being sent.
 boolean isEmpty()
          Returns whether any messages present in this queue.
 boolean isFull()
          Returns whether the queue is already at its capacity; if so, any attempts to enqueue new messages will fail until this is not the case.
 boolean setCapacity(int new_capacity)
          Sets the capacity of this queue to the provided non-negative integer new_capacity.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConnection

public Connection getConnection()
Returns the Connection object with which this queue is associated.

Returns:
the associated connection

getCapacity

public int getCapacity()
Returns the capacity of the queue; attempting to enqueue a message in a queue whose length meets or exceeds its capacity will fail. If the returned value equals -1, no capacity is enforced.

Returns:
the capacity of the queue

setCapacity

public boolean setCapacity(int new_capacity)
Sets the capacity of this queue to the provided non-negative integer new_capacity. If new_capacity equals -1, no capacity will be enforced. If this method is invoked with a new capacity less than the current queue length, then no messages are evicted from the queue. Instead, we wait for the queue to reduce in length over time as messages are transmitted until it is below the new capacity.

Parameters:
new_capacity - the new capacity of the queue
Returns:
true if new_capacity is greater than or equal to -1 and set correctly, false otherwise

isFull

public boolean isFull()
Returns whether the queue is already at its capacity; if so, any attempts to enqueue new messages will fail until this is not the case.

Returns:
true if the queue is at full capacity, false otherwise

getEnqueued

public java.util.List<ASyncTCPMessageHandle> getEnqueued()
Returns handles to the enqueued messages. Note that the returned list is backed by the queue for this connection, but cannot be modified. The elements in the list are returned in the order in which they are enqueued, so that the first element is the next message to be sent.

Returns:
a list of handles to the enqueued messages

enqueue

public ASyncTCPMessageHandle enqueue(Message msg)
Description copied from interface: MessageQueue
Enqueues the Message argument for delivery to the destination.

Specified by:
enqueue in interface MessageQueue
Parameters:
msg - the Message to enqueue for delivery
Returns:
a handle to the enqueued message

getLength

public int getLength()
Description copied from interface: MessageQueue
Returns the number of messages enqueued to the destination.

Specified by:
getLength in interface MessageQueue
Returns:
the number of enqueued messages

isEmpty

public boolean isEmpty()
Description copied from interface: MessageQueue
Returns whether any messages present in this queue. This message returns true if and only if method getLength returns 0.

Specified by:
isEmpty in interface MessageQueue
Returns:
true if no messages are enqueued, false otherwise

getSending

public ASyncTCPMessageHandle getSending()
Description copied from interface: MessageQueue
Returns the handle to the message currently being sent.

Specified by:
getSending in interface MessageQueue
Returns:
handle to the message being sent