org.curjent.impl.agent
Class MarkCall

java.lang.Object
  extended by org.curjent.impl.agent.MarkCall
All Implemented Interfaces:
AgentMark

public final class MarkCall
extends Object
implements AgentMark

Implementation for configuring synthetic marks. This class is not loaded unless synthetic marks are used, and most data structures are lazily initialized on first use.

Prototype call sites are initialized and stored in this class, but runtime call sites are lazily initialized and stored in each agent. This is consistent with standard call sites which are configured per agent instance.

See Also:
Agent.mark(Object)

Field Summary
private  CallStateListener<Void>[] assigned
          Call state listeners.
private  Controller controller
          The agent's controller.
private  CallStateListener<Void> listener
          Default call listener.
private static HashMap<MarkerType,CallInfo> markerPrototype
          Map of marker types to prototype call sites for each synthetic interface and task method specific to marks.
private  MarkerType markerType
          The type of marker send to the agent.
 
Constructor Summary
MarkCall(Proxy proxy)
          Saves the proxy's controller to controller for later use by call().
 
Method Summary
private static void addMarker(MarkerType marker, String method)
          Initializes a prototype call site and adds it to markerPrototype.
static boolean await(Proxy proxy, long timeout, TimeUnit unit)
          Helper method for Agent.await(Object) and related methods.
 AgentCall<Void> call()
          Creates and initializes a new synthetic message with the current configuration settings.
static Message call(Proxy proxy)
          Helper method for Agent.await(Object) and related methods.
 CallStateListener<Void> getCallStateListener()
          Returns the default call state listener or null if none.
 CallStateListener<Void> getCallStateListener(CallState state)
          Returns a call state listener or null if none.
 MarkerType getMarkerType()
          Returns the (possibly null) marker type.
private static CallInfo getSyntheticSite(Controller controller, CallInfo prototype)
          Returns configuration settings for an agent's synthetic method.
private static Message newMessage(Controller controller, MarkerType marker)
          Creates and returns a new synthetic message for the given type of marker.
private static void send(Message message)
          Sends the given message to its controller and wraps checked exceptions.
 void setCallStateListener(CallState state, CallStateListener<Void> listener)
          Sets or clears a call state listener.
 void setCallStateListener(CallStateListener<Void> listener)
          Sets or clears the default call state listener.
 void setMarkerType(MarkerType markerType)
          Sets or clears the marker type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

markerPrototype

private static final HashMap<MarkerType,CallInfo> markerPrototype
Map of marker types to prototype call sites for each synthetic interface and task method specific to marks.


controller

private final Controller controller
The agent's controller. Marker messages are initialized by call() and sent to the controller. Runtime call sites are also stored in the controller.

See Also:
Controller.send(Message)

markerType

private MarkerType markerType
The type of marker send to the agent. May be null for standard, non-marker calls.


listener

private CallStateListener<Void> listener
Default call listener. Assigned to newly created messages by call() prior to sending the call to the agent's controller.

See Also:
AgentCall.setCallStateListener(CallStateListener)

assigned

private CallStateListener<Void>[] assigned
Call state listeners. Assigned to newly created messages by call() prior to sending the call to the agent's controller.

See Also:
AgentCall.setCallStateListener(CallState, CallStateListener)
Constructor Detail

MarkCall

public MarkCall(Proxy proxy)
Saves the proxy's controller to controller for later use by call().

See Also:
Agent.mark(Object)
Method Detail

addMarker

private static void addMarker(MarkerType marker,
                              String method)
                       throws Throwable
Initializes a prototype call site and adds it to markerPrototype.

Throws:
Throwable

newMessage

private static Message newMessage(Controller controller,
                                  MarkerType marker)
Creates and returns a new synthetic message for the given type of marker. Looks up the call site prototype in markerPrototype and defers creation of the runtime call site to the given controller.

See Also:
getSyntheticSite(Controller, CallInfo)

getSyntheticSite

private static CallInfo getSyntheticSite(Controller controller,
                                         CallInfo prototype)
Returns configuration settings for an agent's synthetic method. Unlike standard call sites, synthetic call sites are not initialized until needed.


call

public static Message call(Proxy proxy)
Helper method for Agent.await(Object) and related methods. It avoids unnecessary creation and configuration of an instance of MarkCall since the await methods use the default settings.


await

public static boolean await(Proxy proxy,
                            long timeout,
                            TimeUnit unit)
                     throws InterruptedException
Helper method for Agent.await(Object) and related methods. It avoids unnecessary creation and configuration of instances of MarkCall and MessageCall since the await methods use the default settings.

Throws:
InterruptedException

send

private static void send(Message message)
Sends the given message to its controller and wraps checked exceptions.


call

public AgentCall<Void> call()
Creates and initializes a new synthetic message with the current configuration settings. Sends it to the associated controller and returns the call object.

Specified by:
call in interface AgentMark

getMarkerType

public MarkerType getMarkerType()
Returns the (possibly null) marker type.

Specified by:
getMarkerType in interface AgentMark

setMarkerType

public void setMarkerType(MarkerType markerType)
Sets or clears the marker type. This is used later by call().

Specified by:
setMarkerType in interface AgentMark

getCallStateListener

public CallStateListener<Void> getCallStateListener()
Returns the default call state listener or null if none.

Specified by:
getCallStateListener in interface AgentMark
See Also:
AgentCall.getCallStateListener()

setCallStateListener

public void setCallStateListener(CallStateListener<Void> listener)
Sets or clears the default call state listener. This is used later by call().

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

getCallStateListener

public CallStateListener<Void> getCallStateListener(CallState state)
Returns a call state listener or null if none.

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

setCallStateListener

public void setCallStateListener(CallState state,
                                 CallStateListener<Void> listener)
Sets or clears a call state listener. This is used later by call().

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


Copyright 2009-2011 Tom Landon
Apache License 2.0