asynctcp
Class ASyncTCPMessageHandle

java.lang.Object
  extended by asynctcp.ASyncTCPMessageHandle
All Implemented Interfaces:
MessageHandle

public class ASyncTCPMessageHandle
extends java.lang.Object
implements MessageHandle

A handle to a Message object either currently or previously enqueued for delivery over TCP.

Author:
Michael Parker

Nested Class Summary
 
Nested classes/interfaces inherited from interface async.common.MessageHandle
MessageHandle.MessageState
 
Method Summary
 boolean cancel()
          Cancels the delivery of this message to the remote host, provided that it is still enqueued and is not in the process of being sent or has been sent already.
 Connection getConnection()
          Returns the Connection in which the message is enqueued or currently being sent across.
 long getEnqueuedTime()
          Returns the time, in milliseconds, at which this message was enqueued for delivery.
 MessageHandleListener getListener()
          Retrieves the listener for this message.
 Message getMessage()
          Returns the message for which this MessageHandle instance is a handle.
 ASyncTCPMessageQueue getMessageQueue()
          Returns the message queue in which this message handle is or was once enqueued.
 int getQueuePosition()
          Returns the position of this message in whatever queue it belongs to, provided the state of this handle is ENQUEUED.
 long getSendingTime()
          Returns the time, in milliseconds, at which this message began sending.
 long getSentTime()
          Returns the time, in milliseconds, at which this message was sent in its entirety.
 MessageHandle.MessageState getState()
          Returns the state of this message.
 boolean moveBackward()
          Moves this message one position backward in the queue.
 boolean moveForward()
          Moves this message one position forward in the queue.
 MessageHandleListener setListener(MessageHandleListener _mhl)
          Sets mhl as the listener on this message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getState

public MessageHandle.MessageState getState()
Description copied from interface: MessageHandle
Returns the state of this message.

Specified by:
getState in interface MessageHandle
Returns:
the state of this message

getMessage

public Message getMessage()
Description copied from interface: MessageHandle
Returns the message for which this MessageHandle instance is a handle.

Specified by:
getMessage in interface MessageHandle
Returns:
the message itself

getMessageQueue

public ASyncTCPMessageQueue getMessageQueue()
Description copied from interface: MessageHandle
Returns the message queue in which this message handle is or was once enqueued.

Specified by:
getMessageQueue in interface MessageHandle
Returns:
the associated message queue

cancel

public boolean cancel()
Description copied from interface: MessageHandle
Cancels the delivery of this message to the remote host, provided that it is still enqueued and is not in the process of being sent or has been sent already.

Specified by:
cancel in interface MessageHandle
Returns:
true if this message was enqueued but is now canceled, false otherwise

getQueuePosition

public int getQueuePosition()
Description copied from interface: MessageHandle
Returns the position of this message in whatever queue it belongs to, provided the state of this handle is ENQUEUED. The next message to be sent in a queue has a position of 0.

Specified by:
getQueuePosition in interface MessageHandle
Returns:
the position of this message in its queue, or -1 if not enqueued

getEnqueuedTime

public long getEnqueuedTime()
Description copied from interface: MessageHandle
Returns the time, in milliseconds, at which this message was enqueued for delivery.

Specified by:
getEnqueuedTime in interface MessageHandle
Returns:
the time this message was enqueued at

getSendingTime

public long getSendingTime()
Description copied from interface: MessageHandle
Returns the time, in milliseconds, at which this message began sending.

Specified by:
getSendingTime in interface MessageHandle
Returns:
the time this message began sending

getSentTime

public long getSentTime()
Description copied from interface: MessageHandle
Returns the time, in milliseconds, at which this message was sent in its entirety.

Specified by:
getSentTime in interface MessageHandle
Returns:
the time this message was sent at, or -1 if it has not yet been sent

getListener

public MessageHandleListener getListener()
Description copied from interface: MessageHandle
Retrieves the listener for this message.

Specified by:
getListener in interface MessageHandle
Returns:
the current listener for this message, or null if there is no listener

setListener

public MessageHandleListener setListener(MessageHandleListener _mhl)
Description copied from interface: MessageHandle
Sets mhl as the listener on this message. The listener can later be retrieved via the getListener method. Only one listener may be set at a time; invoking this method causes any previous listener to be discarded. The current listener may be discarded by passing in null.

Specified by:
setListener in interface MessageHandle
Parameters:
_mhl - the new listener for this message
Returns:
the previous listener, if any; otherwise null

moveForward

public boolean moveForward()
Description copied from interface: MessageHandle
Moves this message one position forward in the queue. If this message is not enqueued, or is the first element in the queue, this method returns false.

Specified by:
moveForward in interface MessageHandle
Returns:
true if this message is moved forward in the queue, false otherwise

moveBackward

public boolean moveBackward()
Description copied from interface: MessageHandle
Moves this message one position backward in the queue. If this message is not enqueued, or is the last element in the queue, this method returns false.

Specified by:
moveBackward in interface MessageHandle
Returns:
true if this message is moved backward in the queue, false otherwise

getConnection

public Connection getConnection()
Returns the Connection in which the message is enqueued or currently being sent across.

Returns:
the Connection object this message is enqueued or sending across, null otherwise