|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.zion.jbuddy.bots.BotEngine
public class BotEngine
Acts as a bot, processing user input and generating responses.
The engine can load bot logic from a Bot Definition File. Its logic can also be set programmatically via this API.
Using the engine typically requires the following steps:
loadDefinition
)
addListener
)
start
)
The engine responds to user input events (such as messages and presence
changes) with outgoing gateway
commands and
engine events
.
The framework includes Run
and Test
utilities,
which are complete implementations of this engine, utilizing the
JBuddy SDK
for client and gateway support. An engine does not
have to be explicity created, unless a custom implementation is needed.
Constructor Summary | |
---|---|
BotEngine()
Creates a bot engine. |
Method Summary | |
---|---|
void |
addClient(BotClient client)
Adds a client to this engine. |
BotClient |
addClient(String protocol,
String name)
Adds a client to this engine. |
void |
addClientConnectionListener(BotClientConnectionListener listener)
Registers a listener to receive client connection events from this engine. |
void |
addListener(BotEngineListener listener)
Registers a listener to receive events from this engine. |
protected ClassLoader |
createClassLoader()
Returns the class loader used by this engine to load resources, such as action tasks , resource bundles, and XSL
transformations. |
static String |
encryptPassword(String password,
String passKey)
Encrypts a password for use in a Bot Definition File. |
List |
getClients()
Returns a List of clients in this engine. |
BotEventHandlerSet |
getEventHandlers()
Returns this engine's event handlers. |
BotLogLevel |
getLogLevel()
Returns this engine's log level. |
PrintStream |
getLogOutput()
Returns this engine's log output. |
int |
getMenuHistorySize()
Returns the user menu history size. |
String |
getPassKey()
Returns this engine's pass key. |
ResourceBundle |
getResourceBundle()
Returns this engine's resource bundle. |
BotStatistics |
getStatistics()
Returns this engine's statistics. |
BotTargetSet |
getTargets()
Returns this engine's targets. |
int |
getThreadPoolSize()
Returns the size of the internal thread pool this bot engine uses to process requests. |
long |
getUserTimeout()
Returns the amount of time, in milliseconds, before idle user sessions are timed-out. |
boolean |
isAutomaticallyConnectClients()
Returns whether this engine automatically connects clients. |
boolean |
isRunning()
Returns true if this engine is running (has been started). |
void |
loadDefinition(InputSource source)
Loads Bot Definition XML from the specified input source. |
void |
loadDefinition(InputStream inputStream)
Loads Bot Definition XML from the specified input stream. |
void |
loadDefinition(String path)
Loads Bot Definition XML from the specified path. |
void |
removeClient(BotClient client)
Removes a client from this engine. |
void |
removeClientConnectionListener(BotClientConnectionListener listener)
Stops a listener from receiving client connection events from this engine. |
void |
removeListener(BotEngineListener listener)
Stops a listener from receiving events from this engine. |
void |
setAutomaticallyConnectClients(boolean automaticallyConnectClients)
Sets whether this engine automatically connects clients. |
void |
setLogLevel(BotLogLevel logLevel)
Sets this engine's log level. |
void |
setLogOutput(PrintStream output)
Sets this engine's log output. |
void |
setMenuHistorySize(int menuHistorySize)
Sets the user menu history size. |
void |
setPassKey(String passKey)
Sets this engine's pass key. |
void |
setResourceBundle(ResourceBundle resourceBundle)
Sets this engine's resource bundle. |
void |
setThreadPoolSize(int size)
Sets the size of the internal thread pool this bot engine uses to process requests. |
void |
setUserTimeout(long userTimeout)
Sets the amount of time, in milliseconds, before idle user sessions are timed-out. |
void |
start()
Starts this engine. |
void |
stop()
Stops this engine. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BotEngine()
Method Detail |
---|
public static String encryptPassword(String password, String passKey)
password
- the passwordpassKey
- the optional pass key (may be null
)
public void addListener(BotEngineListener listener)
public void removeListener(BotEngineListener listener)
public void addClientConnectionListener(BotClientConnectionListener listener)
public void removeClientConnectionListener(BotClientConnectionListener listener)
public void loadDefinition(InputSource source) throws Exception
Existing clients
, targets
,
menus
, and event handlers
in
this engine are removed, and replaced by those in the Bot Definition, if
any. Other properties of this engine may also be modified by the Bot
Definition, depending on any attributes that are set.
For more information on the XML format, consult the XML Schema
Documentation
included with the framework.
Exception
- if something goes wrong loading the Bot Definition
(such as an XML error)public void loadDefinition(InputStream inputStream) throws Exception
Existing clients
, targets
,
menus
, and event handlers
in
this engine are removed, and replaced by those in the Bot Definition, if
any. Other properties of this engine may also be modified by the Bot
Definition, depending on any attributes that are set.
For more information on the XML format, consult the XML Schema
Documentation
included with the framework.
Exception
- if something goes wrong loading the Bot Definition
(such as an XML error)public void loadDefinition(String path) throws Exception
Existing clients
, targets
,
menus
, and event handlers
in
this engine are removed, and replaced by those in the Bot Definition, if
any. Other properties of this engine may also be modified by the Bot
Definition, depending on any attributes that are set.
For more information on the XML format, consult the XML Schema
Documentation
included with the framework.
Exception
- if something goes wrong loading the Bot Definition
(such as an XML error)public boolean isRunning()
public void start()
Statistics compiled since the engine last started are reset. If
automaticallyConnectClients
is true
,
clients
are connected (if they are not already
connected).
This method must be called before any user input can be processed. An
exception is thrown if attempting to send input to a
user
whose associated engine hasn't been started.
setAutomaticallyConnectClients(boolean)
public void stop()
public boolean isAutomaticallyConnectClients()
public void setAutomaticallyConnectClients(boolean automaticallyConnectClients)
If true
, while this engine is running, it will
automatically manage client connections; when a new definition is
loaded, new clients will be connected, removed clients will be
disconnected, and unchanged client connections will be preserved.
If false
, client connections will not be automatically
managed (though clients can always be connected
manually
).
public BotLogLevel getLogLevel()
public void setLogLevel(BotLogLevel logLevel)
public PrintStream getLogOutput()
public void setLogOutput(PrintStream output)
By default, the engine prints log output to System.out
.
public int getMenuHistorySize()
public void setMenuHistorySize(int menuHistorySize)
If a user visits a menu that would cause the associated menu history to grow larger than this size, the oldest menu is removed from the history.
If menuHistorySize < 0
, the history may contain an
infinite number of menus (not recommended).
The default value is 10
.
public String getPassKey()
public void setPassKey(String passKey)
The pass key is used to decrypt encrypted client passwords in the Bot
Definition. To encrypt client passwords, use the
EncryptPassword
utility included with the framework.
public ResourceBundle getResourceBundle()
public void setResourceBundle(ResourceBundle resourceBundle)
The engine normally loads string constants from its built-in resource
bundle. The constants can be overridden here. To see the available
constants, consult the Bots.properties
file
included with the framework.
public int getThreadPoolSize()
public void setThreadPoolSize(int size)
The default value is 5
.
public long getUserTimeout()
public void setUserTimeout(long userTimeout)
If no input is sent by a user for longer than this amount of time, the user's session is considered inactive and is removed from the engine. Further input from the user would then create a new session.
If userTimeout < 1
, user sessions will never time out
(not recommended).
The default value is 900000
(60s * 15min * 1000ms = 15 minutes).
public BotStatistics getStatistics()
public BotTargetSet getTargets()
public BotEventHandlerSet getEventHandlers()
public void addClient(BotClient client) throws Exception
Exception
- if a similar client already existspublic BotClient addClient(String protocol, String name)
If a similar client already exists, it is returned. Otherwise, a new client is created and returned.
protocol
- the client's protocolname
- the client's unique name
public List getClients()
public void removeClient(BotClient client)
protected ClassLoader createClassLoader()
action tasks
, resource bundles, and XSL
transformations.
This should be overridden if a custom implementation is required.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |