lij.runtime
Class Interpreter

java.lang.Object
  extended by lij.runtime.Interpreter

public class Interpreter
extends java.lang.Object

The main interpreter class. This is the starting point for loading and executing an IM.

Author:
Nikolaos Chatzinikolaou

Field Summary
private  java.util.ArrayList<AgentInstance> agents
           
private  Framework framework
           
private  boolean isRunning
           
private  LetterBox letterBox
           
private  Monitor monitor
           
 
Constructor Summary
Interpreter(java.io.InputStream is)
          Constructor.
Interpreter(java.io.InputStream is, boolean enableMonitor)
          Constructor.
 
Method Summary
 AgentInstance getAgent(java.io.Serializable id)
          Locates and returns a pointer to the AgentInstance with the specified id.
 java.util.ArrayList<AgentInstance> getAgents()
          Accessor.
 Framework getFramework()
          Accessor.
private  java.util.ArrayList<Term> getMissingRoles()
          Returns a list of all the roles that are necessary for the execution of the IM, that still need a subscriber.
 Monitor getMonitor()
          Accessor.
 ClauseInstance instantiateClause(Term newType, java.io.Serializable newID, java.io.Serializable[] arguments)
          Creates and returns a ClauseInstance object.
 Letter receiveLetter(LetterPostData postData)
          Searches for the proper recepient agent of the specified letter, and posts it to it.
 void run()
          Starts the execution of the IM.
 void sendLetter(Letter letter)
          Searches for the proper recepient agent of the specified letter, and posts it to it.
 void subscribe(java.lang.String roleName, ConstraintImplementor constraintImplementor)
          Creates and adds a new agent subscription, using the default ID.
 void subscribe(java.lang.String roleName, ConstraintImplementor constraintImplementor, java.io.Serializable id)
          Creates and adds a new agent subscription.
private  void waitForRequiredImplementors()
          This method will block until agents for all of the necessary roles specified in the IM have been subscribed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

monitor

private Monitor monitor

framework

private Framework framework

agents

private java.util.ArrayList<AgentInstance> agents

letterBox

private LetterBox letterBox

isRunning

private boolean isRunning
Constructor Detail

Interpreter

public Interpreter(java.io.InputStream is)
            throws java.io.FileNotFoundException,
                   ParseException,
                   InterpreterException
Constructor.

Parameters:
is - An InputStream that will provide the LCC protocol file.
Throws:
java.io.FileNotFoundException
ParseException
InterpreterException

Interpreter

public Interpreter(java.io.InputStream is,
                   boolean enableMonitor)
            throws java.io.FileNotFoundException,
                   ParseException,
                   InterpreterException
Constructor.

Parameters:
is - An InputStream that will provide the LCC protocol file.
enableMonitor - If true, the interpreter monitor GUI frame will be activated and displayed.
Throws:
java.io.FileNotFoundException
ParseException
InterpreterException
Method Detail

getMonitor

public Monitor getMonitor()
Accessor.

Returns:
The interpreter's monitor.

getFramework

public Framework getFramework()
Accessor.

Returns:
The interpreter's framework model.

getAgents

public java.util.ArrayList<AgentInstance> getAgents()
Accessor.

Returns:
The interpreter's current list of agents.

getAgent

public AgentInstance getAgent(java.io.Serializable id)
Locates and returns a pointer to the AgentInstance with the specified id.

Parameters:
id - The ID of the required agent.
Returns:
The required AgentInstance, or null if it was not found.

subscribe

public void subscribe(java.lang.String roleName,
                      ConstraintImplementor constraintImplementor)
               throws InterpreterException
Creates and adds a new agent subscription, using the default ID.

Parameters:
roleName - The role name.
constraintImplementor - A ConstraintImplementor implementation, that will provide implementations for the constraint methods.
Throws:
InterpreterException

subscribe

public void subscribe(java.lang.String roleName,
                      ConstraintImplementor constraintImplementor,
                      java.io.Serializable id)
               throws InterpreterException
Creates and adds a new agent subscription.

Parameters:
roleName - The role name.
constraintImplementor - A ConstraintImplementor implementation, that will provide implementations for the constraint methods.
id - The ID of the agent being subscribed.
Throws:
InterpreterException

run

public void run()
         throws InterpreterException
Starts the execution of the IM. Before doing so, this method will wait until agents for all the required roles specified in the LCC program have been subscribed.

Throws:
InterpreterException

instantiateClause

public ClauseInstance instantiateClause(Term newType,
                                        java.io.Serializable newID,
                                        java.io.Serializable[] arguments)
                                 throws InterpreterException
Creates and returns a ClauseInstance object.

Parameters:
newType - The type of the Clause to instantiate.
newID - The ID of the agent executing the clause.
arguments - The arguments to be passed to the ClauseInstance.
Returns:
The instantiated ClauseInstance.
Throws:
InterpreterException

sendLetter

public void sendLetter(Letter letter)
                throws InterpreterException
Searches for the proper recepient agent of the specified letter, and posts it to it.

Parameters:
letter - The letter to send.
Throws:
InterpreterException

receiveLetter

public Letter receiveLetter(LetterPostData postData)
                     throws InterpreterException
Searches for the proper recepient agent of the specified letter, and posts it to it.

Parameters:
postData - The post data of the message of the expected Letter.
Returns:
The incoming Letter, if found; null otherwise.
Throws:
InterpreterException

waitForRequiredImplementors

private void waitForRequiredImplementors()
This method will block until agents for all of the necessary roles specified in the IM have been subscribed.


getMissingRoles

private java.util.ArrayList<Term> getMissingRoles()
Returns a list of all the roles that are necessary for the execution of the IM, that still need a subscriber.

Returns:
The list of the missing required roles.