|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.curjent.impl.agent.Factory
org.curjent.impl.agent.MessageFactory
final class MessageFactory
Factory for generating and creating an agent's message classes. One class is created for each unique interface method.
TypeInfo
Field Summary | |
---|---|
private static String |
CALL_INFO_DESCRIPTOR
Internal JVM descriptor for CallInfo . |
private static String |
CALL_STATE_DESCRIPTOR
Internal JVM descriptor for CallState . |
private static String |
CALL_STATE_INTERNAL
Internal JVM name for CallState . |
private static String[] |
DISPATCH_EXCEPTION_TYPES
Internal JVM names for the declared exceptions of Message.dispatch(Object) . |
private static String |
FUTURE_INTERNAL
Internal JVM name for Future . |
(package private) static String |
INIT_DESCRIPTOR
Internal JVM descriptor for the generated message's constructor. |
private AgentLoader |
loader
Agent's loader for creating the message classes. |
private static String |
SUPER_MESSAGE_INTERNAL
Internal JVM name for Message . |
private TypeInfo |
typeInfo
Interface and task information for generating classes. |
Constructor Summary | |
---|---|
MessageFactory(AgentLoader loader,
TypeInfo typeInfo)
Initializes the factory. |
Method Summary | |
---|---|
private void |
addConstructor(ClassWriter cw)
Generates the message class's constructor. |
private void |
addDispatcher(MethodInfo method,
ClassWriter cw)
Generates the message class's dispatch method. |
private void |
addGetArgumentMethod(MethodInfo method,
ClassWriter cw)
Generates the get argument method. |
private void |
addGetResultMethod(MethodInfo method,
ClassWriter cw)
Generates the get result method. |
private void |
addSetArgumentMethod(MethodInfo method,
ClassWriter cw)
Generates the set argument method. |
private void |
addSetResultMethod(MethodInfo method,
ClassWriter cw)
Generates the set result method. |
(package private) void |
createClass(MethodInfo method)
Creates the message class for the given interface method. |
private ClassWriter |
startClass(MethodInfo method)
Creates the ASM ClassWriter and starts bytecode generation,
including definition of the message class's fields if any. |
private static void |
visitGetBoxedField(MethodInfo method,
MethodWriter mw,
ParamInfo param)
Generates code for getting a field and boxing it as needed. |
private static void |
visitSetBoxedField(MethodInfo method,
MethodWriter mw,
ParamInfo param)
Generates code for getting a field and boxing it as needed. |
Methods inherited from class org.curjent.impl.agent.Factory |
---|
save |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String SUPER_MESSAGE_INTERNAL
Message
.
private static final String CALL_INFO_DESCRIPTOR
CallInfo
.
private static final String CALL_STATE_INTERNAL
CallState
.
private static final String CALL_STATE_DESCRIPTOR
CallState
.
private static final String[] DISPATCH_EXCEPTION_TYPES
Message.dispatch(Object)
.
private static final String FUTURE_INTERNAL
Future
.
static final String INIT_DESCRIPTOR
private final AgentLoader loader
private final TypeInfo typeInfo
Constructor Detail |
---|
MessageFactory(AgentLoader loader, TypeInfo typeInfo)
Method Detail |
---|
void createClass(MethodInfo method) throws Exception
Exception
private ClassWriter startClass(MethodInfo method)
ClassWriter
and starts bytecode generation,
including definition of the message class's fields if any.
final class {messageName} extends Message { {paramType} {argName}; // for each method parameter {returnType} result; // for the method's result if any ... }
private void addConstructor(ClassWriter cw)
{messageName}(CallInfo info) { super(info); }
private void addDispatcher(MethodInfo method, ClassWriter cw)
protected void dispatch(Object queuedTask) throws Throwable { {taskType} task = ({taskType})queuedTask; {paramType} arg{i}; synchronized (this) { if (state != EXECUTING) return; arg{i} = this.arg{i}; } [{resultType} result =] task.{methodName}(arg{i}, ...); if (result != null) result = ((Future>)result).get(); // task Future synchronized (this) { if (state != EXECUTING) return; this.result = result; cachedResult = this; // primitive type cachedResult = result; // non-primitive type } }
private void addGetArgumentMethod(MethodInfo method, ClassWriter cw)
protected Object getArgumentValue(int index) { // one argument return arg0; // two or more arguments Object value; if (index == 0) { value = {boxedType}.valueOf(arg{i}); // boxed types } else { value = arg{i}; // other types } return value; }
private static void visitGetBoxedField(MethodInfo method, MethodWriter mw, ParamInfo param)
private void addSetArgumentMethod(MethodInfo method, ClassWriter cw)
protected void setArgumentValue(int index, Object value) { // one argument arg0 = ({paramType})value; // two or more arguments if (index == 0) { arg0 = value; // Object type } else if (index == 1) { arg1 = value==null ? {defaultValue} : (({boxedType})value).{unboxingName}Value(); // boxed type } else { arg2 = ({paramType})value; // other types } }
private static void visitSetBoxedField(MethodInfo method, MethodWriter mw, ParamInfo param)
private void addGetResultMethod(MethodInfo method, ClassWriter cw)
protected Object getResultValue() { return {boxedType}.valueOf(result); }
private void addSetResultMethod(MethodInfo method, ClassWriter cw)
protected void setResultValue(Object value) { result = value; // Object type result = (value == null) ? {defaultValue} : (({boxedType})value).{unboxingName}Value(); // boxed types result = ({resultType})value; // other types }
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |