org.curjent.impl.agent
Class Messages

java.lang.Object
  extended by org.curjent.impl.agent.Messages

final class Messages
extends Object

Custom linked list for queuing instances of Message. This implementation eliminates the need to allocated list nodes. Instead, the message instances are used as list nodes. They are linked together with the Message.next and Message.prev fields.

Pending messages are queued separately from accepted messages. This class coordinates the pending and accepted states described for Capacity.


Field Summary
private  Queue accepted
          Queue of accepted messages.
private static long DEADCHECK_TIMEOUT
          Default timeout in seconds before a waiting thread checks for deadlock.
private static long DEADCHECK_TIMEOUT_NANOS
          DEADCHECK_TIMEOUT in nanosecond units.
private  long deadcheckNanos
          deadcheckTimeout in nanosecond units.
private  long deadcheckTimeout
          Timeout before a waiting thread checks for deadlock.
private  TimeUnit deadcheckUnit
          Time unit for deadcheckTimeout.
private  int executing
          Number of accepted messages executing.
private  Queue pending
          Queue of pending messages.
private  long pendingNanos
          Nanosecond equivalent of the pending message timeout value.
private  long pendingTimeout
          Pending message timeout value.
private  TimeUnit pendingUnit
          Pending message timeout unit.
 
Constructor Summary
Messages()
           
 
Method Summary
(package private)  Message dequeue(Message message)
          Called in the controller's message pump loop to remove the current message for processing and evaluate the next message for processing.
(package private)  void dispatched(Message message)
          Notification from the controller that a message has finished executing.
(package private)  void dispatching(Message message)
          Notification from the controller that it has selected a message to execute.
(package private)  boolean empty()
          Returns true if there are no messages queued, accepted or waiting.
(package private)  long enqueue(Mark mark, Message message)
          Adds a message to the end of the queue, assigned the given mark to it, and increments the mark's count.
(package private)  void finish(Message message)
          The controller has finished processing the given message.
(package private)  int getAcceptedCapacity()
          Returns the current maximum for accepted messages.
(package private)  int getCurrentAccepted()
          Returns the current number of messages accepted, including executing messages.
(package private)  int getCurrentExecuting()
          Returns the number of executing messages.
(package private)  int getCurrentPending()
          Returns the number of messages currently pending.
(package private)  long getDeadcheckNanos()
          Returns getDeadcheckTimeout() in nanosecond units.
(package private)  long getDeadcheckTimeout()
          Returns the deadcheck timeout value.
(package private)  TimeUnit getDeadcheckUnit()
          Returns the deadcheck timeout unit.
(package private)  int getPendingCapacity()
          Returns the current maximum for pending messages.
(package private)  long getPendingTimeout()
          Returns the current maximum amount of time a caller waits for the agent to accept its call.
(package private)  TimeUnit getPendingUnit()
          Returns the time unit for getPendingCapacity().
(package private)  void init(ProxyInfo info)
          Initializes the capacity values.
(package private)  Message next(Message message)
          Returns a references to the next accepted message without removing it.
(package private)  Message peek()
          Returns a reference to the first accepted message without removing it.
private  void pump()
          Transitions pending messages to the accepted queue as availability and capacity permits.
(package private)  void setAcceptedCapacity(int value)
          Updates the current maximum for accepted messages and calls pump().
(package private)  void setDeadcheckTimeout(long value, TimeUnit unit)
          Sets the amount of time a thread waits before it checks for deadlock.
(package private)  void setPendingCapacity(int value)
          Updates the current maximum for pending messages.
(package private)  void setPendingTimeout(long value, TimeUnit unit)
          Updates the current maximum amount of time a caller waits for the agent to accept its call.
 String toString()
          Returns the number of pending, accepted, and exeucting messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pending

private final Queue pending
Queue of pending messages.


accepted

private final Queue accepted
Queue of accepted messages.


executing

private int executing
Number of accepted messages executing.


pendingTimeout

private long pendingTimeout
Pending message timeout value.


pendingUnit

private TimeUnit pendingUnit
Pending message timeout unit.


pendingNanos

private long pendingNanos
Nanosecond equivalent of the pending message timeout value.


DEADCHECK_TIMEOUT

private static final long DEADCHECK_TIMEOUT
Default timeout in seconds before a waiting thread checks for deadlock.

See Also:
Constant Field Values

DEADCHECK_TIMEOUT_NANOS

private static final long DEADCHECK_TIMEOUT_NANOS
DEADCHECK_TIMEOUT in nanosecond units.

See Also:
Constant Field Values

deadcheckTimeout

private long deadcheckTimeout
Timeout before a waiting thread checks for deadlock.


deadcheckUnit

private TimeUnit deadcheckUnit
Time unit for deadcheckTimeout.


deadcheckNanos

private long deadcheckNanos
deadcheckTimeout in nanosecond units.

Constructor Detail

Messages

Messages()
Method Detail

init

void init(ProxyInfo info)
Initializes the capacity values.


empty

boolean empty()
Returns true if there are no messages queued, accepted or waiting.


peek

Message peek()
Returns a reference to the first accepted message without removing it. Returns null when empty.


next

Message next(Message message)
Returns a references to the next accepted message without removing it. Returns null if the given message is the last message.


dispatching

void dispatching(Message message)
Notification from the controller that it has selected a message to execute.

See Also:
AgentStats.getCurrentExecuting()

dispatched

void dispatched(Message message)
Notification from the controller that a message has finished executing.


enqueue

long enqueue(Mark mark,
             Message message)
Adds a message to the end of the queue, assigned the given mark to it, and increments the mark's count. Returns 0L if the message was accepted. Returns a value greater than OL if the message is pending acceptance. The returned non-zero value is the current number of nanoseconds the caller can wait for the message to be accepted before the agent throws a CapacityExceededException.

Throws:
CapacityExceededException - The accepted and pending queues are both full. The mark's count is unchanged in this case.

dequeue

Message dequeue(Message message)
Called in the controller's message pump loop to remove the current message for processing and evaluate the next message for processing.


finish

void finish(Message message)
The controller has finished processing the given message. The message mark's count is decremented, and the message is dequeued if needed. Lastly, a pending message is transitioned to the accepted queue if available.


pump

private void pump()
Transitions pending messages to the accepted queue as availability and capacity permits. Moved messages are also transitioned from their pending state to the ready state which releases callers from their waiting state.


getAcceptedCapacity

int getAcceptedCapacity()
Returns the current maximum for accepted messages.


setAcceptedCapacity

void setAcceptedCapacity(int value)
Updates the current maximum for accepted messages and calls pump().

Throws:
IllegalArgumentException - Invalid value

getCurrentAccepted

int getCurrentAccepted()
Returns the current number of messages accepted, including executing messages.

See Also:
AgentStats.getCurrentAccepted()

getCurrentExecuting

int getCurrentExecuting()
Returns the number of executing messages.

See Also:
AgentStats.getCurrentExecuting()

getPendingCapacity

int getPendingCapacity()
Returns the current maximum for pending messages.


setPendingCapacity

void setPendingCapacity(int value)
Updates the current maximum for pending messages.

Throws:
IllegalArgumentException - Invalid value

getPendingTimeout

long getPendingTimeout()
Returns the current maximum amount of time a caller waits for the agent to accept its call.


getPendingUnit

TimeUnit getPendingUnit()
Returns the time unit for getPendingCapacity().


setPendingTimeout

void setPendingTimeout(long value,
                       TimeUnit unit)
Updates the current maximum amount of time a caller waits for the agent to accept its call.

Throws:
IllegalArgumentException - Invalid value
NullPointerException - unit is required but null

getCurrentPending

int getCurrentPending()
Returns the number of messages currently pending.

See Also:
AgentStats.getCurrentPending()

getDeadcheckTimeout

long getDeadcheckTimeout()
Returns the deadcheck timeout value.

See Also:
AgentConfig.setDeadcheckTimeout(long, TimeUnit)

getDeadcheckUnit

TimeUnit getDeadcheckUnit()
Returns the deadcheck timeout unit.

See Also:
AgentConfig.setDeadcheckTimeout(long, TimeUnit)

getDeadcheckNanos

long getDeadcheckNanos()
Returns getDeadcheckTimeout() in nanosecond units.


setDeadcheckTimeout

void setDeadcheckTimeout(long value,
                         TimeUnit unit)
Sets the amount of time a thread waits before it checks for deadlock.

Throws:
IllegalArgumentException - value < 0
NullPointerException - unit is required but null
See Also:
AgentConfig.setDeadcheckTimeout(long, TimeUnit)

toString

public String toString()
Returns the number of pending, accepted, and exeucting messages.

Overrides:
toString in class Object


Copyright 2009-2011 Tom Landon
Apache License 2.0