The Meta-Environment API

toolbus.adapter
Class ToolBridge

java.lang.Object
  extended by toolbus.adapter.ToolBridge
All Implemented Interfaces:
java.lang.Runnable, IDataHandler, IOperations
Direct Known Subclasses:
JavaToolBridge

public abstract class ToolBridge
extends java.lang.Object
implements IDataHandler, java.lang.Runnable, IOperations

This class supplies an interface for the tool towards the ToolBus and handles the invokation of methods on the tool.

Author:
Arnold Lankamp

Nested Class Summary
private static class ToolBridge.Job
          A job.
private  class ToolBridge.JobQueue
          This job queue holds all the jobs that are send from a single source.
private  class ToolBridge.ThreadLocalJobQueue
          This job queue holds all the jobs that are posted by a certain thread.
private static class ToolBridge.WorkerQueue
          The queue that is meant to take care of the asynchroneous execution and queueing of anything that invokes stuff on a tool.
 
Field Summary
private  java.net.InetAddress host
           
private  IIOHandler ioHandler
           
private  int port
           
private  java.util.Map<java.lang.String,ToolBridge.JobQueue> queues
           
private  aterm.pure.PureFactory termFactory
           
private  java.util.Map<java.lang.Long,ToolBridge.ThreadLocalJobQueue> threadLocalQueues
           
private  ToolBus toolbus
           
private  int toolID
           
private  java.lang.String toolName
           
private  java.lang.String type
           
private  ToolBridge.WorkerQueue workerQueue
           
 
Fields inherited from interface toolbus.IOperations
ACKDO, ACKEVENT, CONNECT, DEBUGPERFORMANCESTATS, DISCONNECT, DO, END, EVAL, EVENT, PERFORMANCESTATS, REQUEST, RESPONSE, TERMINATE, UNDEFINED, VALUE
 
Constructor Summary
ToolBridge(aterm.pure.PureFactory termFactory, java.lang.String toolName, int toolID, java.net.InetAddress host, int port)
          Constructor.
ToolBridge(aterm.pure.PureFactory termFactory, java.lang.String toolName, int toolID, ToolBus toolbus)
          Constructor.
 
Method Summary
abstract  boolean checkSignature(aterm.ATerm signature)
          Checks if the tool associated with this tool bridge supplies the given signature.
abstract  void doDo(aterm.ATerm aTerm)
          Executes a DO operation with the given ATerm.
abstract  aterm.ATerm doEval(aterm.ATerm aTerm)
          Executes an EVAL operation with the given ATerm.
abstract  aterm.ATerm doGetPerformanceStats()
          Retrieves performance statistic information from the tool (if possible).
abstract  void doReceiveAckEvent(aterm.ATerm aTerm)
          Executes a RECACKEVENT operation with the given ATerm.
abstract  void doTerminate(aterm.ATerm aTerm)
          Executes a TERMINATE operation with the given ATerm.
 void exceptionOccured()
          Notifies the data handler that an exception has occured so it can take the necessary steps.
 aterm.pure.PureFactory getFactory()
          Returns a reference to the term factory.
protected  java.net.InetAddress getHost()
          Returns the adress of the host the ToolBus is running on.
protected  int getPort()
          Returns the port number the ToolBus is running on.
 int getToolID()
          Returns the tool id of the tool that is associated with this tool bridge.
 java.lang.String getToolName()
          Returns the tool name of the tool that is associated with this tool bridge.
 java.lang.String getType()
          Returns what type of connection we have with the ToolBus.
 void postEvent(aterm.ATerm aTerm)
          Posts the given event.
 aterm.ATermAppl postRequest(aterm.ATerm aTerm)
          Posts the given request.
 void receive(byte operation, aterm.ATerm aTerm)
          Receives a term from the associated ioHandler.
 void run()
          Executes the ToolBridge.
 void send(byte operation, aterm.ATerm aTerm)
          Forwards a term to the associated ioHandler.
 void setIOHandler(IIOHandler ioHandler)
          Associates an I/O handler with this tool bridge.
protected  void setToolID(int toolID)
          Sets the tool id to the given values.
 void shutDown()
          Informs the tool that it was shut down by the toolbus.
 void terminate()
          Requests the termination of this tool, so it can perform an orderly shutdown on the toolbus side.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

termFactory

private final aterm.pure.PureFactory termFactory

threadLocalQueues

private final java.util.Map<java.lang.Long,ToolBridge.ThreadLocalJobQueue> threadLocalQueues

queues

private final java.util.Map<java.lang.String,ToolBridge.JobQueue> queues

workerQueue

private final ToolBridge.WorkerQueue workerQueue

ioHandler

private volatile IIOHandler ioHandler

type

private final java.lang.String type

toolName

private final java.lang.String toolName

toolID

private int toolID

host

private final java.net.InetAddress host

port

private final int port

toolbus

private final ToolBus toolbus
Constructor Detail

ToolBridge

public ToolBridge(aterm.pure.PureFactory termFactory,
                  java.lang.String toolName,
                  int toolID,
                  java.net.InetAddress host,
                  int port)
Constructor.

Parameters:
termFactory - The term factory to use.
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.

ToolBridge

public ToolBridge(aterm.pure.PureFactory termFactory,
                  java.lang.String toolName,
                  int toolID,
                  ToolBus toolbus)
Constructor.

Parameters:
termFactory - The term factory to use.
toolName - The name of the with this bridge associated tool.
toolID - The id of the with this bridge associated tool.
toolbus - The toolbus to connect to.
Method Detail

getType

public java.lang.String getType()
Returns what type of connection we have with the ToolBus.

Returns:
What type of connection we have with the ToolBus.

getToolName

public java.lang.String getToolName()
Returns the tool name of the tool that is associated with this tool bridge.

Returns:
The tool name of the tool that is associated with this tool bridge.

setToolID

protected void setToolID(int toolID)
Sets the tool id to the given values. This method will only be called once, after successfully connecting to the ToolBus.

Parameters:
toolID - The value the toolID has to be set too.

getToolID

public int getToolID()
Returns the tool id of the tool that is associated with this tool bridge.

Returns:
The tool id of the tool that is associated with this tool bridge.

getFactory

public aterm.pure.PureFactory getFactory()
Returns a reference to the term factory.

Returns:
A reference to the term factory.

getHost

protected java.net.InetAddress getHost()
Returns the adress of the host the ToolBus is running on.

Returns:
The adress of the host the ToolBus is running on. Is null when uninitialized.

getPort

protected int getPort()
Returns the port number the ToolBus is running on.

Returns:
The port number the ToolBus is running on. Is -1 when uninitialized.

setIOHandler

public void setIOHandler(IIOHandler ioHandler)
Associates an I/O handler with this tool bridge.

Specified by:
setIOHandler in interface IDataHandler
Parameters:
ioHandler - The I/O handler to associate this tool bridge with.

checkSignature

public abstract boolean checkSignature(aterm.ATerm signature)
Checks if the tool associated with this tool bridge supplies the given signature.

Parameters:
signatures - The signature we need to compare the interface of the tool too.
Returns:
True if the tool supplies the expected interface; false otherwise.

doDo

public abstract void doDo(aterm.ATerm aTerm)
Executes a DO operation with the given ATerm.

Parameters:
aTerm - The ATerm that contains the necessary data to complete the DO request.

doEval

public abstract aterm.ATerm doEval(aterm.ATerm aTerm)
Executes an EVAL operation with the given ATerm.

Parameters:
aTerm - The ATerm that contains the necessary data to complete the EVAL request.
Returns:
The result the EVAL request produced (may not be null).

doReceiveAckEvent

public abstract void doReceiveAckEvent(aterm.ATerm aTerm)
Executes a RECACKEVENT operation with the given ATerm.

Parameters:
aTerm - The ATerm that can potentially contain callback data.

doTerminate

public abstract void doTerminate(aterm.ATerm aTerm)
Executes a TERMINATE operation with the given ATerm.

Parameters:
aTerm - The ATerm that can potentially contain background informantion about the termination request.

doGetPerformanceStats

public abstract aterm.ATerm doGetPerformanceStats()
Retrieves performance statistic information from the tool (if possible).

Returns:
The gathered performance information (may not be null).

send

public void send(byte operation,
                 aterm.ATerm aTerm)
Description copied from interface: IDataHandler
Forwards a term to the associated ioHandler.

Specified by:
send in interface IDataHandler
Parameters:
operation - The operation associated with the term we need to send.
aTerm - The term that needs to be transmitted.
See Also:
IDataHandler.send(byte, ATerm)

postEvent

public void postEvent(aterm.ATerm aTerm)
Posts the given event.

Parameters:
aTerm - The event.

postRequest

public aterm.ATermAppl postRequest(aterm.ATerm aTerm)
Posts the given request.

Parameters:
aTerm - The request.

receive

public void receive(byte operation,
                    aterm.ATerm aTerm)
Description copied from interface: IDataHandler
Receives a term from the associated ioHandler.

Specified by:
receive in interface IDataHandler
Parameters:
operation - The operation associate with the term we received.
aTerm - The term that was received.
See Also:
IDataHandler.receive(byte, ATerm)

terminate

public void terminate()
Requests the termination of this tool, so it can perform an orderly shutdown on the toolbus side.

Specified by:
terminate in interface IDataHandler
See Also:
IDataHandler.terminate()

shutDown

public void shutDown()
Informs the tool that it was shut down by the toolbus.

Specified by:
shutDown in interface IDataHandler
See Also:
IDataHandler.shutDown()

exceptionOccured

public void exceptionOccured()
Description copied from interface: IDataHandler
Notifies the data handler that an exception has occured so it can take the necessary steps.

Specified by:
exceptionOccured in interface IDataHandler
See Also:
IDataHandler.exceptionOccured()

run

public void run()
Executes the ToolBridge.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

The Meta-Environment API