|
The Meta-Environment API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttoolbus.adapter.ToolBridge
toolbus.adapter.java.JavaToolBridge
public class JavaToolBridge
This class is a specialized ToolBridge version for Java tools. It supplies an interface for the tool to enable it to communicate with the ToolBus and it handles the invokation of methods on the tool.
Nested Class Summary | |
---|---|
protected static class |
JavaToolBridge.CallableMethodSignature
This class represents a signature of a method (Name + return type + params). |
private static class |
JavaToolBridge.MethodInvokationException
Custom exception. |
Field Summary | |
---|---|
private java.util.Map<JavaToolBridge.CallableMethodSignature,java.lang.reflect.Method> |
callableFunctions
|
private aterm.pure.PureFactory |
termFactory
|
private AbstractTool |
tool
|
Fields inherited from interface toolbus.IOperations |
---|
ACKDO, ACKEVENT, CONNECT, DEBUGPERFORMANCESTATS, DISCONNECT, DO, END, EVAL, EVENT, PERFORMANCESTATS, REQUEST, RESPONSE, TERMINATE, UNDEFINED, VALUE |
Constructor Summary | |
---|---|
JavaToolBridge(aterm.pure.PureFactory termFactory,
AbstractTool tool,
java.lang.String toolName,
int toolID,
java.net.InetAddress host,
int port)
Constructor. |
|
JavaToolBridge(aterm.pure.PureFactory termFactory,
AbstractTool tool,
java.lang.String toolName,
int toolID,
ToolBus toolbus)
Constructor. |
Method Summary | |
---|---|
boolean |
checkSignature(aterm.ATerm signatures)
Checks if the tool associated with this tool bridge supplies the given signature. |
private java.lang.Object |
convertArgument(aterm.ATerm aTerm)
Converts the given aterm to its corresponding Java type object (if needed). |
private java.lang.Class<?> |
determainTermType(aterm.ATerm aTerm)
Determain the class type of the given aterm (depending on its signature). |
void |
doDo(aterm.ATerm aTerm)
Executes a DO operation with the given ATerm. |
aterm.ATerm |
doEval(aterm.ATerm aTerm)
Executes an EVAL operation with the given ATerm. |
aterm.ATerm |
doGetPerformanceStats()
Retrieves performance statistic information from the tool (if possible). |
void |
doReceiveAckEvent(aterm.ATerm aTerm)
Executes a RECACKEVENT operation with the given ATerm. |
void |
doTerminate(aterm.ATerm aTerm)
Executes a TERMINATE operation with the given ATerm. |
private java.lang.reflect.Method |
findMethod(byte operation,
java.lang.String methodName,
java.lang.Class<?>[] parameters)
Returns the tool method that matches the given name, arguments and operation. |
private aterm.ATerm |
getPerformanceStats()
Gathers performance statistics about this tool, like memory usage and the user-/system-time spend per thread. |
private void |
initCallableMethods()
Reads all the callable methods of the tool associated with this tool bridge. |
private aterm.ATerm |
invokeMethod(byte operation,
aterm.ATerm aTerm)
Invokes the method associated with the given term and operation. |
protected static boolean |
isImplementationOf(java.lang.Class<?> clazz,
java.lang.Class<?> superInterface)
Checks the the given class satisfies the given interface. |
private static java.lang.String |
toMethodName(java.lang.String str)
|
Methods inherited from class toolbus.adapter.ToolBridge |
---|
exceptionOccured, getFactory, getHost, getPort, getToolID, getToolName, getType, postEvent, postRequest, receive, run, send, setIOHandler, setToolID, shutDown, terminate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final aterm.pure.PureFactory termFactory
private final AbstractTool tool
private final java.util.Map<JavaToolBridge.CallableMethodSignature,java.lang.reflect.Method> callableFunctions
Constructor Detail |
---|
public JavaToolBridge(aterm.pure.PureFactory termFactory, AbstractTool tool, java.lang.String toolName, int toolID, java.net.InetAddress host, int port)
tool
- The tool this bridge needs to be associated with.toolName
- The name of the with this bridge associated tool.toolID
- The id of the with this bridge associated tool.host
- The host on which the ToolBus is running.port
- The port on which the ToolBus is running.public JavaToolBridge(aterm.pure.PureFactory termFactory, AbstractTool tool, java.lang.String toolName, int toolID, ToolBus toolbus)
type
- The type of the tool (Remote of direct).tool
- The tool this bridge needs to be associated with.toolName
- The name of the with this bridge associated tool.toolID
- The id of the with this bridge associated tool.classLoader
- The classLoader to use for loading classes.toolbus
- The toolbus to link this bridge to.Method Detail |
---|
public void doDo(aterm.ATerm aTerm)
ToolBridge
doDo
in class ToolBridge
aTerm
- The ATerm that contains the necessary data to complete the DO request.ToolBridge.doDo(ATerm)
public aterm.ATerm doEval(aterm.ATerm aTerm)
ToolBridge
doEval
in class ToolBridge
aTerm
- The ATerm that contains the necessary data to complete the EVAL request.
ToolBridge.doEval(ATerm)
public void doReceiveAckEvent(aterm.ATerm aTerm)
ToolBridge
doReceiveAckEvent
in class ToolBridge
aTerm
- The ATerm that can potentially contain callback data.ToolBridge.doReceiveAckEvent(ATerm)
public void doTerminate(aterm.ATerm aTerm)
ToolBridge
doTerminate
in class ToolBridge
aTerm
- The ATerm that can potentially contain background informantion about the termination request.ToolBridge.doTerminate(ATerm)
public aterm.ATerm doGetPerformanceStats()
ToolBridge
doGetPerformanceStats
in class ToolBridge
ToolBridge.doGetPerformanceStats()
protected static boolean isImplementationOf(java.lang.Class<?> clazz, java.lang.Class<?> superInterface)
clazz
- The class from which we want to know if it satisfies the given interface.superInterface
- The interface to satisfy.
private void initCallableMethods()
public boolean checkSignature(aterm.ATerm signatures)
ToolBridge
checkSignature
in class ToolBridge
ToolBridge.checkSignature(ATerm)
private aterm.ATerm invokeMethod(byte operation, aterm.ATerm aTerm) throws JavaToolBridge.MethodInvokationException
operation
- Indicates the return type of the method (DO = void, EVAL = ATerm).aTerm
- The ATerm that indicates with method should be invoked.
JavaToolBridge.MethodInvokationException
- Thrown when something goes wrong.private static java.lang.String toMethodName(java.lang.String str)
private java.lang.reflect.Method findMethod(byte operation, java.lang.String methodName, java.lang.Class<?>[] parameters)
operation
- The operation associated with the given term.methodName
- The name of the method we want to find.parameters
- The list of parameters that the method needs be able to accept.
private java.lang.Class<?> determainTermType(aterm.ATerm aTerm)
aTerm
- The aterm of which we need to determain the type.
private java.lang.Object convertArgument(aterm.ATerm aTerm)
aTerm
- The aterm to convert.
private aterm.ATerm getPerformanceStats()
|
The Meta-Environment API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |