lij.runtime
Class AgentInstance

java.lang.Object
  extended by java.lang.Thread
      extended by lij.runtime.AgentInstance
All Implemented Interfaces:
java.lang.Runnable

public class AgentInstance
extends java.lang.Thread

A runtime instance of an Agent definition. Each Agent runs in its own thread.

Author:
Nikolaos Chatzinikolaou

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  ConstraintImplementor constraintImplementor
           
private  ClauseInstance currentClauseInstance
           
private  java.io.Serializable id
           
private  Interpreter interpreter
           
private  Term roleType
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AgentInstance(Term _roleType, java.io.Serializable _id, ConstraintImplementor _constraintImplementor, Interpreter _interpreter)
          Constructor.
 
Method Summary
 ClauseInstanceReturns executeClauseInstance(ClauseInstance clauseInstance)
          This method will cause this AgentInstance to execute the specified ClauseInstance.
 ConstraintImplementor getConstraintImplementor()
          Accessor.
 ClauseInstance getCurrentClauseInstance()
          Accessor.
 java.io.Serializable getCurrentID()
          Returns the ID of the agent encapsulated in this AgentInstance.
 Term getCurrentType()
          Returns the role Term of the agent encapsulated in this AgentInstance.
 void run()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

roleType

private Term roleType

id

private java.io.Serializable id

constraintImplementor

private ConstraintImplementor constraintImplementor

interpreter

private Interpreter interpreter

currentClauseInstance

private ClauseInstance currentClauseInstance
Constructor Detail

AgentInstance

public AgentInstance(Term _roleType,
                     java.io.Serializable _id,
                     ConstraintImplementor _constraintImplementor,
                     Interpreter _interpreter)
Constructor.

Parameters:
_roleType - The agent's role type.
_id - The agent's ID.
_constraintImplementor - The associated ConstraintImplementor instance.
_interpreter - A reference to the currently running Interpreter instance.
Method Detail

getConstraintImplementor

public ConstraintImplementor getConstraintImplementor()
Accessor.

Returns:
The associated ConstraintImplementor object.

getCurrentID

public java.io.Serializable getCurrentID()
Returns the ID of the agent encapsulated in this AgentInstance. This is the ID specified during subscription, if no ClauseInstance is currently executing; or the agent ID specified in the ClauseInstance, if one exists. This stems from the fact that, in the current implementation of the interpreter, it is possible for an agent to change its ID when performing a role switch.

Returns:
The current ID of the agent.

getCurrentType

public Term getCurrentType()
Returns the role Term of the agent encapsulated in this AgentInstance. This is the role specified during subscription, if no ClauseInstance is currently executing; or the role specified in the ClauseInstance, if one exists.

Returns:
The current role of the agent.

getCurrentClauseInstance

public ClauseInstance getCurrentClauseInstance()
Accessor.

Returns:
The currently executing ClauseInstance.

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

executeClauseInstance

public ClauseInstanceReturns executeClauseInstance(ClauseInstance clauseInstance)
                                            throws InterpreterException
This method will cause this AgentInstance to execute the specified ClauseInstance. This method is recursive, in that it can also be called as part of the execution of a DefAgent (i.e. role switch) in the LCC protocol. The method will keep looping while evaluating the root tree node of the ClauseInstance, until a definitive result (i.e. TRUE or FALSE, but not MAYBE) is achieved. This behaviour is part of the parallel processing mechanism of the interpreter.

Parameters:
clauseInstance - The ClauseInstance to execute.
Returns:
The result returned by evaluating the root tree node (and recursively its children) of the clause, as well as any values returned via the clause's input arguments.
Throws:
InterpreterException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Thread