org.curjent.impl.agent
Class Config

java.lang.Object
  extended by org.curjent.impl.agent.Config
All Implemented Interfaces:
AgentConfig

final class Config
extends Object
implements AgentConfig

Returned on behalf of the controller to avoid synchronization conflicts on the controller. This also keeps clients from casually casting and using the controller directly.


Field Summary
(package private)  CallInfo[] calls
          Call site state, metadata, and configuration.
private  Controller controller
          Agent's configured controller.
private  Object data
          Value of AgentConfig.setData(Object).
private static ExceptionHandler DEFAULT_EXCEPTION_HANDLER
          Default handler for unhandled exceptions.
(package private)  ExceptionHandler exceptions
          Handler for unhandled exceptions.
private  List<Class<?>> interfaces
          Interfaces used to create this agent.
private  Object key
          Required key to configure the agent.
private  AgentLoader loader
          Loader used to create this agent.
(package private)  Proxy proxy
          Proxy object returned to the caller of newInstance.
private  HashMap<CallKey,CallInfo> sites
          Map of interface method keys to call sites.
private  Class<?> taskType
          Task class used to create this agent.
 
Constructor Summary
Config(Controller controller, AgentLoader loader, Class<?>[] interfaces, Class<?> taskType)
          Manages many of the controller's configuration requirements directly.
 
Method Summary
 int getAcceptedCapacity()
          Returns the current maximum for accepted messages.
 AgentLoader getAgentLoader()
          Returns the loader used to create the agent.
 AgentTasks getAgentTasks()
          Returns the tasks used to create the agent.
 CallSite getCallSite(String method, Class<?> result, Class<?>... params)
          Returns configuration settings for an agent's method.
 CallStateListener<?> getCallStateListener()
          Returns the agent's default listener.
 CallStateListener<?> getCallStateListener(CallState state)
          Returns the default listener for a specific state.
 Object getData()
          Returns the data previously associated with this agent.
 long getDeadcheckTimeout()
          Returns the length of time synchronous calls wait before checking if the caller's thread has deadlocked.
 TimeUnit getDeadcheckTimeoutUnit()
          Returns the time unit for getDeadcheckTimeout().
 Executor getExecutor()
          Returns the agent's executor.
 long getExpirationTimeout()
          Returns the agent's default expiration timeout value.
 TimeUnit getExpirationTimeoutUnit()
          Returns the agent's default expiration timeout unit.
 List<Class<?>> getInterfaces()
          Returns a read-only list of the interfaces used to create the agent.
 int getPendingCapacity()
          Returns the current maximum for pending messages.
 long getPendingTimeout()
          Returns the current maximum amount of time a caller waits for the agent to accept its call.
 TimeUnit getPendingTimeoutUnit()
          Returns the time unit for getPendingCapacity().
 Class<?> getTaskType()
          Returns the task type used to create the agent.
 ExceptionHandler getUnhandledExceptionHandler()
          Returns the agent's handler for unhandled exceptions.
(package private)  void init(CallInfo[] calls)
          Finishes initialization.
 void setAcceptedCapacity(int value)
          Updates the current maximum for accepted messages.
 void setCallStateListener(CallState state, CallStateListener<?> listener)
          Sets the default listener for a specific state and updates the call sites' effective listeners.
 void setCallStateListener(CallStateListener<?> listener)
          Sets the agent's default listener and updates the call sites' effective listeners.
 void setData(Object data)
          Associates data with this agent.
 void setDeadcheckTimeout(long value, TimeUnit unit)
          Sets the length of time synchronous calls wait before checking if the caller's thread has deadlocked.
 void setExecutor(Executor executor)
          Changes the agent's executor.
 void setExpirationTimeout(long value, TimeUnit unit)
          Sets the agent's default expiration.
 void setPendingCapacity(int value)
          Updates the current maximum for pending messages.
 void setPendingTimeout(long value, TimeUnit unit)
          Updates the current maximum amount of time a caller waits for the agent to accept its call.
 void setUnhandledExceptionHandler(ExceptionHandler handler)
          Changes the agent's handler for unhandled exceptions.
 String toString()
          Returns the list of interfaces.
(package private)  void updateKey(Object oldKey, Object newKey)
          Attempts to update the configuration key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

controller

private final Controller controller
Agent's configured controller.


loader

private final AgentLoader loader
Loader used to create this agent. This is the loader from the newInstance call and the one returned by AgentConfig.getAgentLoader(). This may differ from the loader used to create the generated proxy and message classes. This can occur when newInstance is called with different AgentLoaders that have the same ClassLoader.

See Also:
Agent.newInstance(AgentLoader, Class[], AgentTasks, Class), AgentConfig.getAgentLoader()

interfaces

private final List<Class<?>> interfaces
Interfaces used to create this agent. These are the interfaces the agent's proxy implements. This is a read-only list.

See Also:
Agent.newInstance(AgentLoader, Class[], AgentTasks, Class), AgentConfig.getInterfaces(), Collections.unmodifiableList(List)

taskType

private final Class<?> taskType
Task class used to create this agent.

See Also:
Agent.newInstance(AgentLoader, Class[], AgentTasks, Class), AgentConfig.getTaskType()

proxy

volatile Proxy proxy
Proxy object returned to the caller of newInstance. From the caller's perspective, this is "the agent."

There is a circular dependency between the proxy and controller. The controller is created first. This means we have to initialize the controller's reference to the proxy later in a non-final field. Since it is non-final, we are obligated to provide concurrency control. This field never changes after initialization, so volatile is sufficient. JVM memory semantics makes even this overkill with today's agent implementation, but the agent implementation may change in subtle ways, and there is no performance concern, so explicit concurrency control is safer.

See Also:
Agent.newInstance(AgentLoader, Class[], AgentTasks, Class), CallSite.getAgent()

calls

CallInfo[] calls
Call site state, metadata, and configuration. The length of of the calls array is equal to the number of interface methods implemented by this agent. This array and its elements are created as unique new instances for each agent created by Agent.newInstance.

See Also:
AgentConfig.getCallSite(String, Class, Class...), AgentCall.getCallSite()

sites

private HashMap<CallKey,CallInfo> sites
Map of interface method keys to call sites. This is a comparatively heavy graph of objects, so we defer creation until the first call to getCallSite.

See Also:
AgentConfig.getCallSite(String, Class, Class...)

exceptions

volatile ExceptionHandler exceptions
Handler for unhandled exceptions. See Exceptions in the description for org.curjent.agent.


DEFAULT_EXCEPTION_HANDLER

private static final ExceptionHandler DEFAULT_EXCEPTION_HANDLER
Default handler for unhandled exceptions.

See Also:
exceptions

key

private Object key
Required key to configure the agent.

See Also:
Agent.getConfig(Object, Object, Object)

data

private Object data
Value of AgentConfig.setData(Object).

Constructor Detail

Config

Config(Controller controller,
       AgentLoader loader,
       Class<?>[] interfaces,
       Class<?> taskType)
Manages many of the controller's configuration requirements directly.

Method Detail

init

void init(CallInfo[] calls)
Finishes initialization.


updateKey

void updateKey(Object oldKey,
               Object newKey)
Attempts to update the configuration key.

Throws:
ConfigLockedException - Invalid oldKey
See Also:
Agent.getConfig(Object, Object, Object)

getAgentTasks

public AgentTasks getAgentTasks()
Returns the tasks used to create the agent.

Specified by:
getAgentTasks in interface AgentConfig
See Also:
AgentConfig.getAgentTasks()

getCallSite

public CallSite getCallSite(String method,
                            Class<?> result,
                            Class<?>... params)
Returns configuration settings for an agent's method.

Specified by:
getCallSite in interface AgentConfig
Parameters:
method - The name of the method.
result - The method's return type. For methods returning objects, use the object's class, such as myObject.getClass(). For primitives, use the primitive's class, such as int.class. For void, use void.class.
params - The method's parameter types. May be empty or null for methods without parameters.
See Also:
AgentConfig.getCallSite(String, Class, Class...)

getAcceptedCapacity

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

Specified by:
getAcceptedCapacity in interface AgentConfig
See Also:
AgentConfig.getPendingCapacity(), Capacity

setAcceptedCapacity

public void setAcceptedCapacity(int value)
Updates the current maximum for accepted messages.

Specified by:
setAcceptedCapacity in interface AgentConfig
See Also:
AgentConfig.setPendingCapacity(int), Capacity

getPendingCapacity

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

Specified by:
getPendingCapacity in interface AgentConfig
See Also:
AgentConfig.getAcceptedCapacity(), AgentConfig.getPendingTimeout(), Capacity

setPendingCapacity

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

Specified by:
setPendingCapacity in interface AgentConfig
See Also:
AgentConfig.setAcceptedCapacity(int), AgentConfig.setPendingTimeout(long, TimeUnit), Capacity

getPendingTimeout

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

Specified by:
getPendingTimeout in interface AgentConfig
See Also:
AgentConfig.getPendingTimeoutUnit(), AgentConfig.getAcceptedCapacity(), Capacity

getPendingTimeoutUnit

public TimeUnit getPendingTimeoutUnit()
Returns the time unit for getPendingCapacity().

Specified by:
getPendingTimeoutUnit in interface AgentConfig
See Also:
AgentConfig.getPendingTimeout(), Capacity

setPendingTimeout

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

Specified by:
setPendingTimeout in interface AgentConfig
See Also:
AgentConfig.setPendingCapacity(int), Capacity

getDeadcheckTimeout

public long getDeadcheckTimeout()
Returns the length of time synchronous calls wait before checking if the caller's thread has deadlocked.

Specified by:
getDeadcheckTimeout in interface AgentConfig

getDeadcheckTimeoutUnit

public TimeUnit getDeadcheckTimeoutUnit()
Returns the time unit for getDeadcheckTimeout().

Specified by:
getDeadcheckTimeoutUnit in interface AgentConfig
See Also:
AgentConfig.getDeadcheckTimeout()

setDeadcheckTimeout

public void setDeadcheckTimeout(long value,
                                TimeUnit unit)
Sets the length of time synchronous calls wait before checking if the caller's thread has deadlocked. Defers parameter validation to Messages.setDeadcheckTimeout(long, TimeUnit).

Specified by:
setDeadcheckTimeout in interface AgentConfig
See Also:
AgentConfig.getDeadcheckTimeout()

getData

public Object getData()
Returns the data previously associated with this agent.

Specified by:
getData in interface AgentConfig
See Also:
AgentConfig.setData(Object)

setData

public void setData(Object data)
Associates data with this agent.

Specified by:
setData in interface AgentConfig
See Also:
AgentConfig.getData(), CallSite.setData(Object), AgentCall.setData(Object)

getAgentLoader

public AgentLoader getAgentLoader()
Returns the loader used to create the agent.

Specified by:
getAgentLoader in interface AgentConfig
See Also:
AgentConfig.getAgentLoader()

getInterfaces

public List<Class<?>> getInterfaces()
Returns a read-only list of the interfaces used to create the agent.

Specified by:
getInterfaces in interface AgentConfig
See Also:
AgentConfig.getInterfaces()

getTaskType

public Class<?> getTaskType()
Returns the task type used to create the agent.

Specified by:
getTaskType in interface AgentConfig
See Also:
AgentConfig.getTaskType()

getCallStateListener

public CallStateListener<?> getCallStateListener()
Returns the agent's default listener.

Specified by:
getCallStateListener in interface AgentConfig
See Also:
AgentConfig.getCallStateListener()

getCallStateListener

public CallStateListener<?> getCallStateListener(CallState state)
Returns the default listener for a specific state.

Specified by:
getCallStateListener in interface AgentConfig
See Also:
AgentConfig.getCallStateListener(CallState)

setCallStateListener

public void setCallStateListener(CallStateListener<?> listener)
Sets the agent's default listener and updates the call sites' effective listeners.

Specified by:
setCallStateListener in interface AgentConfig
See Also:
AgentConfig.setCallStateListener(CallStateListener)

setCallStateListener

public void setCallStateListener(CallState state,
                                 CallStateListener<?> listener)
Sets the default listener for a specific state and updates the call sites' effective listeners.

Specified by:
setCallStateListener in interface AgentConfig
See Also:
AgentConfig.setCallStateListener(CallState, CallStateListener)

getExecutor

public Executor getExecutor()
Returns the agent's executor.

Specified by:
getExecutor in interface AgentConfig
See Also:
Agent.getDefaultExecutor()

setExecutor

public void setExecutor(Executor executor)
Changes the agent's executor.

Specified by:
setExecutor in interface AgentConfig

getUnhandledExceptionHandler

public ExceptionHandler getUnhandledExceptionHandler()
Returns the agent's handler for unhandled exceptions.

Specified by:
getUnhandledExceptionHandler in interface AgentConfig
See Also:
AgentConfig.getUnhandledExceptionHandler()

setUnhandledExceptionHandler

public void setUnhandledExceptionHandler(ExceptionHandler handler)
Changes the agent's handler for unhandled exceptions.

Specified by:
setUnhandledExceptionHandler in interface AgentConfig
See Also:
AgentConfig.setUnhandledExceptionHandler(ExceptionHandler)

getExpirationTimeout

public long getExpirationTimeout()
Returns the agent's default expiration timeout value.

Specified by:
getExpirationTimeout in interface AgentConfig
See Also:
AgentConfig.getExpirationTimeout(), getExpirationTimeoutUnit()

getExpirationTimeoutUnit

public TimeUnit getExpirationTimeoutUnit()
Returns the agent's default expiration timeout unit.

Specified by:
getExpirationTimeoutUnit in interface AgentConfig
See Also:
AgentConfig.getExpirationTimeoutUnit(), getExpirationTimeout()

setExpirationTimeout

public void setExpirationTimeout(long value,
                                 TimeUnit unit)
Sets the agent's default expiration.

Specified by:
setExpirationTimeout in interface AgentConfig
See Also:
AgentConfig.setExpirationTimeout(long, TimeUnit)

toString

public String toString()
Returns the list of interfaces.

Overrides:
toString in class Object


Copyright 2009-2011 Tom Landon
Apache License 2.0