|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.cuni.pogamut.Client.Agent
cz.cuni.pogamut.Client.ScriptedAgent
public class ScriptedAgent
This is class for the agents that are using the ScriptEngine.
You have to specify the file to load and engine to bind before starting the agent.
Field Summary | |
---|---|
protected javax.script.ScriptEngine |
engine
ScriptEngine which contains the file with logic. |
protected javax.script.Invocable |
invocableEngine
E. g. engine but Invocable, allowing us to call methods. |
protected java.lang.String |
scriptFileName
Name of the file which contains the logic. |
Fields inherited from class cz.cuni.pogamut.Client.Agent |
---|
bindedParserType, body, flagLogicTemporalyStopped, gameBotConnection, gameMap, GARBAGE_COLLECTOR_FREQUENCY, instancesAlive, iterationEndListeners, log, logicFrequency, logicFrequencyChanged, memory, oldLogicFrequency, parserLogger, pauseHolders, platformLog, random, rawGBLog |
Constructor Summary | |
---|---|
protected |
ScriptedAgent()
Constructor which is needed when you have to initialize the environment of the scripting language. |
|
ScriptedAgent(java.io.File file)
Bind new instance of scripted agent with source file. |
|
ScriptedAgent(java.lang.String pathToScript)
Bind new instance of scripted agent with source file. |
Method Summary | |
---|---|
void |
bindEngineByExtension(java.lang.String extension)
Bind engine which is needed to process the script. |
void |
bindEngineByFileName(java.lang.String fileName)
Bind engine which is needed to process the script. |
void |
bindEngineByMimeType(java.lang.String mime)
Bind engine which is needed to process the script. |
void |
bindEngineByName(java.lang.String name)
Bind engine which is needed to process the script. |
protected void |
bindScriptFile(java.io.File file)
Sets the file with logic. |
protected void |
bindScriptFile(java.lang.String fileName)
Sets the file with logic. |
private boolean |
callFunction(java.lang.String name)
Calls function without parameters from the ScriptEngine. |
protected static javax.script.ScriptEngineManager |
createScriptEngineManager()
Creates script engine manager that looks for engines in classpath and also in $POGAMUT_PLATFORM/scriptEngines. |
protected void |
doLogic()
This will call function doLogic() from specified scriptFileName. |
protected void |
engineBinded()
This method is called when the engine is binded. |
protected void |
engineIsGoingToBeBinded()
Reserved for use of the descendants, making room for configuring some system properties / paths / etc. |
protected boolean |
evalFile(java.lang.String fileName)
Evaluate the file within the engine. |
protected boolean |
evalStream(java.io.InputStream is)
Evaluates the stream of the script. |
IntrospectableProxy |
getIntrospectableProxy()
Returns union of properties and children from Agent (obtained by Java Reflection) and from script (obtained by corresponding InstrospectionProxy). |
protected boolean |
checkPreconditions()
|
protected void |
postPrepareAgent()
This will call function postPrepareAgent() from specified logicFileName. |
protected void |
prePrepareAgent()
This will call function prePrepareAgent() from specified logicFileName. |
protected void |
scriptFileBinded()
This method is called whenever the script file is binded and evaluated. |
protected void |
setAgentAttributes()
Export important agent variables to the ScriptingEngine. |
protected void |
setAttribute(java.lang.String name,
java.lang.Object attribute)
Sets attribute to the global scope of the engine. |
protected void |
shutdownAgent()
This will call function shutdownAgent() from specified logicFileName. |
java.lang.Thread |
startAgent(java.lang.String botName)
check whether everything is ready startAgent |
Methods inherited from class cz.cuni.pogamut.Client.Agent |
---|
addIterationEndListener, bindLocalParser, bindRemoteParser, clearListeners, disconnect, finalize, getBindedParserType, getBody, getCommunicationState, getFlagLogicTemporalyStopped, getLogger, getLogicThread, getMap, getMediator, getMemory, getMilisecToSleep, getName, getPlatformLog, getRawDataLog, initBody, initGameMap, initLogging, initMemory, isRunning, logicReady, pauseLogic, receiveMessage, removeIterationEndListener, resumeLogic, run, sendMessageToGB, setFlagLogicTemporalyStopped, setLogicStartLatch, startAgent, stopAgentSoft |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String scriptFileName
protected javax.script.ScriptEngine engine
protected javax.script.Invocable invocableEngine
Constructor Detail |
---|
protected ScriptedAgent()
Currently used by SPOSHBot.
public ScriptedAgent(java.lang.String pathToScript) throws ScriptedAgentException
pathToScript
- path to script source file. eg. c:\bot.py
ScriptedAgentException
public ScriptedAgent(java.io.File file) throws ScriptedAgentException
file
- File of the script source file
ScriptedAgentException
Method Detail |
---|
protected static javax.script.ScriptEngineManager createScriptEngineManager()
protected void scriptFileBinded()
protected void bindScriptFile(java.lang.String fileName) throws ScriptedAgentException
If engine is not binded - it will be determined by the file extension.
Script file is then evaluated in the engine.
fileName
-
ScriptedAgentException
protected void bindScriptFile(java.io.File file) throws ScriptedAgentException
If engine is not binded - it will be determined by the file extension.
Script file is then evaluated in the engine.
file
-
ScriptedAgentException
protected void engineBinded()
public void bindEngineByName(java.lang.String name)
Engine may be binded only once.
You have to specify the name of the engine, see ScriptEngineFactory from JavaDoc for more info about the names.
name
- public void bindEngineByExtension(java.lang.String extension)
Engine may be binded only once.
You have to specify the name of the engine, see ScriptEngineFactory from JavaDoc for more info about the names.
extension
- public void bindEngineByMimeType(java.lang.String mime)
Engine may be binded only once.
You have to specify the name of the engine, see ScriptEngineFactory from JavaDoc for more info about the names.
mime
- public void bindEngineByFileName(java.lang.String fileName)
Engine may be binded only once.
You have to specify the fileName of the engine, see ScriptEngineFactory from JavaDoc for more info about the names.
fileName
- protected void engineIsGoingToBeBinded()
protected void setAgentAttributes()
protected void setAttribute(java.lang.String name, java.lang.Object attribute)
name
- attribute
- protected boolean evalStream(java.io.InputStream is) throws ScriptedAgentException
is
-
ScriptedAgentException
protected boolean evalFile(java.lang.String fileName) throws ScriptedAgentException
fileName
-
ScriptedAgentException
protected boolean checkPreconditions()
public java.lang.Thread startAgent(java.lang.String botName)
startAgent
in class Agent
botName
-
private boolean callFunction(java.lang.String name) throws ScriptedAgentException
name
-
ScriptedAgentException
protected void doLogic() throws PogamutException
It should do the logic iteration (assuming you're already connected and prePreparaAgent and postPrepareAgent were already called).
doLogic
in class Agent
PogamutException
protected void prePrepareAgent() throws PogamutException
prepares agent logic to run - like initializing neural networks etc. not for establishing communication!
prePrepareAgent
in class Agent
PogamutException
protected void postPrepareAgent() throws PogamutException
prepare logic according to information gathered from startCommunication like choosing plan/parameters according to game type.
postPrepareAgent
in class Agent
PogamutException
protected void shutdownAgent() throws PogamutException
Clean - up after the end of simulation of agent
shutdownAgent
in class Agent
PogamutException
public IntrospectableProxy getIntrospectableProxy()
getIntrospectableProxy
in interface Introspectable
getIntrospectableProxy
in class Agent
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |