org.aitools.programd.multiplexor
Class DBMultiplexor

java.lang.Object
  extended by org.aitools.programd.multiplexor.Multiplexor
      extended by org.aitools.programd.multiplexor.DBMultiplexor

public class DBMultiplexor
extends Multiplexor

A database-oriented Multiplexor . Uses a database for storage and retrieval of predicates.

This is adapted from Classifier , to use a better database structure and to support user authentication.

Author:
Richard Wallace, Jon Baer, Thomas Ringate/Pedro Colla, Noel Bush

Field Summary
private  org.apache.log4j.Logger dbLogger
          The logger for database activity.
private  DbAccessRefsPoolMgr dbManager
          A manager for database access.
private static java.lang.String ENC_UTF8
          The string ""UTF-8"" (for character encoding conversion).
private  java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> userCacheForBots
           
 
Fields inherited from class org.aitools.programd.multiplexor.Multiplexor
ASTERISK, avgResponseTime, bots, core, EMPTY_STRING, graphmaster, INPUT, logger, matchLogger, predicateEmptyDefault, predicateMaster, responseCount, STAR, startTime, THAT, TOPIC, totalTime, VALUE
 
Constructor Summary
DBMultiplexor(Core coreOwner)
          Creates a new DBMultiplexor with the given Core as owner.
 
Method Summary
 void createUser(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Creates a userid with a given password.
 boolean changePassword(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Changes the password associated with a userid.
 boolean checkUser(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Checks whether a given userid and password combination is valid.
private  boolean checkUserInDB(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Checks a userid/password combination in the database.
 void initialize()
          Loads the database properties from the server configuration.
 java.lang.String loadPredicate(java.lang.String name, java.lang.String userid, java.lang.String botid)
          Loads the value of a predicate from a database.
 void savePredicate(java.lang.String name, java.lang.String value, java.lang.String userid, java.lang.String botid)
          Saves a predicate in a database.
 int useridCount(java.lang.String botid)
          Returns a count of known userids.
 
Methods inherited from class org.aitools.programd.multiplexor.Multiplexor
attach, averageResponseTime, getInternalResponse, getResponse, queriesPerHour
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbManager

private DbAccessRefsPoolMgr dbManager
A manager for database access.


dbLogger

private org.apache.log4j.Logger dbLogger
The logger for database activity.


userCacheForBots

private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> userCacheForBots

ENC_UTF8

private static final java.lang.String ENC_UTF8
The string ""UTF-8"" (for character encoding conversion).

See Also:
Constant Field Values
Constructor Detail

DBMultiplexor

public DBMultiplexor(Core coreOwner)
Creates a new DBMultiplexor with the given Core as owner.

Parameters:
coreOwner - the Core that owns this DBMultiplexor
Method Detail

initialize

public void initialize()
Loads the database properties from the server configuration.

Specified by:
initialize in class Multiplexor

savePredicate

public void savePredicate(java.lang.String name,
                          java.lang.String value,
                          java.lang.String userid,
                          java.lang.String botid)
Saves a predicate in a database.

Specified by:
savePredicate in class Multiplexor
Parameters:
name - the name of the predicate to save
value - the value to save for the predicate
userid - the userid with which to associate this predicate
botid - the botid with which to associate this predicate

loadPredicate

public java.lang.String loadPredicate(java.lang.String name,
                                      java.lang.String userid,
                                      java.lang.String botid)
                               throws NoSuchPredicateException
Loads the value of a predicate from a database.

Specified by:
loadPredicate in class Multiplexor
Parameters:
name - the name of the predicate to locate
userid - the userid whose value of the given predicate is desired
botid - the botid whose userid-associated value of the given predicate is desired
Returns:
the value of the predicate
Throws:
NoSuchPredicateException - if no such predicate has been defined for the given userid and botid pair

createUser

public void createUser(java.lang.String userid,
                       java.lang.String password,
                       java.lang.String botid)
                throws DuplicateUserIDError
Creates a userid with a given password. If the userid already exists, returns false.

Specified by:
createUser in class Multiplexor
Parameters:
userid - the userid to create
password - the password to associate with the userid
botid - the botid with whom to associate this userid/password combination
Throws:
DuplicateUserIDError - if the given userid was already found in the database

checkUser

public boolean checkUser(java.lang.String userid,
                         java.lang.String password,
                         java.lang.String botid)
Description copied from class: Multiplexor
Checks whether a given userid and password combination is valid. Multiplexors for which this makes no sense should just return true.

Specified by:
checkUser in class Multiplexor
Parameters:
userid - the userid to check
password - the password to check
Returns:
whether the userid and password combination is valid
See Also:
Multiplexor.checkUser(java.lang.String, java.lang.String, java.lang.String)

checkUserInDB

private boolean checkUserInDB(java.lang.String userid,
                              java.lang.String password,
                              java.lang.String botid)
Checks a userid/password combination in the database.

Parameters:
userid - the userid to check
password - the password to check
botid - the botid for which to check this combination
Returns:
whether the userid and password combination is valid

changePassword

public boolean changePassword(java.lang.String userid,
                              java.lang.String password,
                              java.lang.String botid)
Description copied from class: Multiplexor
Changes the password associated with a userid. Multiplexors for which this makes no sense should just return true.

Specified by:
changePassword in class Multiplexor
Parameters:
userid - the userid
password - the new password
Returns:
whether the change was successful
See Also:
Multiplexor.changePassword(java.lang.String, java.lang.String, java.lang.String)

useridCount

public int useridCount(java.lang.String botid)
Description copied from class: Multiplexor
Returns a count of known userids. This may be defined differently for different multiplexors.

Specified by:
useridCount in class Multiplexor
Parameters:
botid - the botid for which we want a count of known userids
Returns:
a count of known userids
See Also:
Multiplexor.useridCount(java.lang.String)