|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectcz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController<BOT>
cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicController
cz.cuni.amis.pogamut.ut2004.bot.sposh.StreamScriptLogic
public abstract class StreamScriptLogic
This is class for the agents that are using the ScriptEngine. ScriptEngine is a part of Java API that allows execution of scripting file using integrated engine.
This basically allows us to create a agent with logic implemented in some scripting language (like JavaScript or Python). Beware, Java has currently implemented only one engine and that is JavaScript, for others it is necessary to provide custom binding library for the language (like jython).
The script that will be executed shoudl contain all the normal functions that are expected, i.e.:
You have to specify the file to load and engine to bind before
starting the agent.
Subclasses has to implement StreamScriptedAgent.getScriptFile() to
specify the script. This is done mostly because of google Guice.
Also, if subclass is utilizing some script that is not available as default,
it should override StreamScriptedAgent.engineIsGoingToBeBinded() to set it up.
TODO: this class is rather ugly, it deserves some clean up.
It should go approx. like this * Create a new instance * Create ScriptEngineManager * call engineIsGoingToBeBinded() * get engine from manager based on extension or something How to get data: get file get stream from file What can be done:
| Field Summary | |
|---|---|
protected ScriptEngine |
engine
ScriptEngine which contains the file with logic. |
protected Invocable |
invocableEngine
Same engine as in engine, but recasted as Invocable, allowing us to call methods. |
protected ScriptEngineManager |
scriptEngineManager
|
| Fields inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicController |
|---|
logicModule |
| Fields inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController |
|---|
bot, log, USER_LOG_CATEGORY_ID |
| Constructor Summary | |
|---|---|
StreamScriptLogic()
|
|
| Method Summary | |
|---|---|
protected boolean |
callFunction(String name)
Calls function without parameters from the ScriptEngine. |
protected abstract ScriptEngine |
createScriptEngine(ScriptEngineManager manager)
Return correct ScriptEngine for script this bot is going to run. |
protected abstract void |
engineBinded()
This method is called when the engine is binded. |
protected boolean |
evalStream(Reader reader)
Evaluates the stream of the script. |
UT2004Bot |
getBot()
|
protected abstract Reader |
getScriptStream()
Return stream for script that this class should execute. |
void |
initializeController(UT2004Bot bot)
Constructor which is needed when you have to initialize the environment of the scripting language. |
protected abstract void |
scriptBinded()
This method is called after the script is evaluated. |
protected void |
setAttribute(String name,
Object attribute)
Sets attribute to the global scope of the engine. |
| Methods inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicController |
|---|
beforeFirstLogic, getLogicInitializeTime, getLogicShutdownTime, initializeLogic, logic, logicInitialize, logicShutdown |
| Methods inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController |
|---|
botFirstSpawn, botInitialized, botKilled, botShutdown, finishControllerInitialization, getAct, getInitializeCommand, getLog, getPassword, getWorldView, prepareBot |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController |
|---|
botFirstSpawn, botInitialized, botKilled, botShutdown, finishControllerInitialization, getAct, getInitializeCommand, getLog, getPassword, getWorldView, prepareBot |
| Field Detail |
|---|
protected ScriptEngineManager scriptEngineManager
protected ScriptEngine engine
protected Invocable invocableEngine
engine, but recasted as Invocable, allowing us to call methods.
| Constructor Detail |
|---|
public StreamScriptLogic()
| Method Detail |
|---|
public void initializeController(UT2004Bot bot)
Currently used by SPOSHBot.
initializeController in interface IUT2004BotControllerinitializeController in class UT2004BotLogicControllerprotected abstract ScriptEngine createScriptEngine(ScriptEngineManager manager)
Because this class is using stream instead of file we don't know what is scripting language of processed script. That is what this function is for.
manager - ScriptEngineManager that is used to manage engines.
ScriptEngine for this agent.
protected abstract Reader getScriptStream()
throws IOException
IOExceptionprotected abstract void scriptBinded()
protected abstract void engineBinded()
protected final void setAttribute(String name,
Object attribute)
name - attribute -
protected final boolean evalStream(Reader reader)
throws ScriptedAgentException
is -
ScriptedAgentException
protected final boolean callFunction(String name)
throws ScriptedAgentException
name -
ScriptedAgentExceptionpublic UT2004Bot getBot()
getBot in interface IUT2004BotControllergetBot in class UT2004BotController
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||