org.micropsi.nodenet.scripting
Class Script

java.lang.Object
  extended byorg.micropsi.nodenet.scripting.Script

public abstract class Script
extends java.lang.Object

Script. Abstract ancestor of all scripts that can be executed by an implementation of ScriptingManagerIF. Scripts are meant to be run in a separate thread, so the run() method defines how long the script is alive. terminate() comes from outside, telling the run() method to stop. run() and terminate must be implemented correctly or you will mess up the ScriptingManagerIF implementation. This abstract baseclass allows the registration of AbstractNetScriptEventListeners that fire upon different net events like netstep changes, gate or slot value changes etc.


Constructor Summary
Script()
           
 
Method Summary
protected  Logger getLogger()
          Returns the logger.
protected  Situation getSituation()
          Returns the agent's current situation
protected  void registerEventListener(org.micropsi.nodenet.scripting.AbstractNetScriptEventListener listener)
          Registern an AbstractNetScriptEventListener.
abstract  void run()
          Runs the script.
abstract  void terminate()
          Called when the run() method should come to an end.
protected  void unregisterAllListeners()
          Unregisters all registered listeners.
protected  void unregisterEventListener(org.micropsi.nodenet.scripting.AbstractNetScriptEventListener listener)
          Unregisters the given listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Script

public Script()
Method Detail

getLogger

protected Logger getLogger()
Returns the logger.

Returns:
the logger.

getSituation

protected Situation getSituation()
Returns the agent's current situation

Returns:
the situation

registerEventListener

protected void registerEventListener(org.micropsi.nodenet.scripting.AbstractNetScriptEventListener listener)
Registern an AbstractNetScriptEventListener. Note that after the run() method has finished, all listeners will automatically removed. So you will have to keep alive run() as long you want to listen for events.

Parameters:
listener - a listener

unregisterEventListener

protected void unregisterEventListener(org.micropsi.nodenet.scripting.AbstractNetScriptEventListener listener)
Unregisters the given listener.

Parameters:
listener - the listener to be unregistered.

unregisterAllListeners

protected void unregisterAllListeners()
Unregisters all registered listeners.


run

public abstract void run()
                  throws MicropsiException,
                         java.lang.InterruptedException
Runs the script. This method must terminate! Pay attention to terminate() calls to get notification of the user's whish to cancel. Keep this method alive as long as you want to listen for events from the registered listeners! When this method finishes, all listeners are removed and the script is done.

Throws:
MicropsiException,InterruptedException
MicropsiException
java.lang.InterruptedException

terminate

public abstract void terminate()
Called when the run() method should come to an end.


(c) by Micropsi Project: http://www.cognitive-agents.org

.