org.curjent.impl.agent
Class Expirations

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

final class Expirations
extends Object

Helper for Controller to manage message expirations (Expiration).

The typical use of agents will not include expirations. Consequently, expirations are designed to avoid nearly all overhead when not used.

This class manages runtime configuration of expirations but defers background expiration logic to ExpirationsTask.


Field Summary
private  CallInfo[] calls
          Agent's call sites used for configuring site-specific default expirations.
(package private) static long NIL
          Signals that an expiration timeout has not yet been explicitly set.
private  long sequence
          Current sequence value for ExpirationsTimer.
private  ExpirationsTask task
          Manages background processing of timers.
private  long timeout
          Agent's default expiration timeout.
private  TimeUnit unit
          Agent default expiration timeout unit.
 
Constructor Summary
Expirations(Controller controller, ReentrantLock lock)
          Saves the controller and its lock for internal use.
 
Method Summary
(package private)  void finish(Message message)
          Notification that a message has finished executing.
(package private)  long getExpirationTimeout()
          Returns the agent's default expiration timeout value.
(package private)  long getExpirationTimeout(CallInfo info)
          Returns the expiration timeout for a given call site.
(package private)  long getExpirationTimeoutNanos(Message message)
          Returns the number of NANOSECONDS until the given call expires.
(package private)  TimeUnit getExpirationTimeoutUnit()
          Returns the agent's default expiration timeout unit.
(package private)  TimeUnit getExpirationTimeoutUnit(CallInfo info)
          Returns the expiration timeout unit for a given call site.
(package private)  void init(ProxyInfo info, CallInfo[] calls)
          This class is initialized when the controller is initialized.
(package private)  void setExpirationTimeout(CallInfo info, long value, TimeUnit unit)
          Sets an agent call site's expiration time.
(package private)  void setExpirationTimeout(long value, TimeUnit unit)
          Sets the agent's default expiration time.
(package private)  boolean setExpirationTimeout(Message message, long value, TimeUnit unit)
          Sets an agent call's expiration time.
(package private)  void start(Message message)
          Checks if the message is configured for expiration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

calls

private CallInfo[] calls
Agent's call sites used for configuring site-specific default expirations.


timeout

private long timeout
Agent's default expiration timeout.


unit

private TimeUnit unit
Agent default expiration timeout unit.


sequence

private long sequence
Current sequence value for ExpirationsTimer. Increased by one for each new timer. Used to break ties if two timers have the same expiration time.


task

private final ExpirationsTask task
Manages background processing of timers.


NIL

static final long NIL
Signals that an expiration timeout has not yet been explicitly set. This is used to determine if a default value should be used or not. Defaults are only used if the more specific value is not set.

See Also:
Constant Field Values
Constructor Detail

Expirations

Expirations(Controller controller,
            ReentrantLock lock)
Saves the controller and its lock for internal use.

Method Detail

init

void init(ProxyInfo info,
          CallInfo[] calls)
This class is initialized when the controller is initialized.

Called while the controller is locked.

See Also:
Controller.init(Proxy, ProxyInfo, CallInfo[])

start

void start(Message message)
Checks if the message is configured for expiration. Returns immediately if not. Otherwise, initializes a timer and adds it to the expiration queue.

See Also:
ExpirationsTask.enqueue(ExpirationsTimer)

finish

void finish(Message message)
Notification that a message has finished executing. Due to the relatively high cost of removing queued timers, simply clears the timer's message and notifies the background task to clean it up later.


getExpirationTimeout

long getExpirationTimeout()
Returns the agent's default expiration timeout value. Returns Long.MAX_VALUE if not explicity set via a class-level Expiration or setExpirationTimeout(long, TimeUnit).

See Also:
getExpirationTimeoutUnit()

getExpirationTimeoutUnit

TimeUnit getExpirationTimeoutUnit()
Returns the agent's default expiration timeout unit. Returns NANOSECONDS if not explicity set via a class-level Expiration or setExpirationTimeout(long, TimeUnit).

See Also:
getExpirationTimeout()

setExpirationTimeout

void setExpirationTimeout(long value,
                          TimeUnit unit)
Sets the agent's default expiration time. Propagates the default expiration to each call site that is not already explicitly configured.

See Also:
Util.nanos(long, TimeUnit, long)

getExpirationTimeout

long getExpirationTimeout(CallInfo info)
Returns the expiration timeout for a given call site. Returns Long.MAX_VALUE if not explicity set via a method-level Expiration or at runtime via setExpirationTimeout(CallInfo, long, TimeUnit).

See Also:
getExpirationTimeoutUnit(CallInfo)

getExpirationTimeoutUnit

TimeUnit getExpirationTimeoutUnit(CallInfo info)
Returns the expiration timeout unit for a given call site. Returns NANOSECONDS if not explicity set via a method-level Expiration or at runtime via setExpirationTimeout(CallInfo, long, TimeUnit).

See Also:
getExpirationTimeout(CallInfo)

setExpirationTimeout

void setExpirationTimeout(CallInfo info,
                          long value,
                          TimeUnit unit)
Sets an agent call site's expiration time.

See Also:
Util.nanos(long, TimeUnit, long)

setExpirationTimeout

boolean setExpirationTimeout(Message message,
                             long value,
                             TimeUnit unit)
Sets an agent call's expiration time. This overrides the agent's default and call site settings. Attempts to expire the call immediately if value is 0; returns true if successful. Returns false for any other timeout value or if expiration failed because the call is already EXECUTING or FINISHED.

See Also:
Util.nanos(long, TimeUnit, long)

getExpirationTimeoutNanos

long getExpirationTimeoutNanos(Message message)
Returns the number of NANOSECONDS until the given call expires. Returns Long.MAX_VALUE if the call is not configured to expire. Returns 0 if the call has already reached its expiration time (the call may or may not have finished with a CALL_EXPIRED completion).



Copyright 2009-2011 Tom Landon
Apache License 2.0