org.aitools.programd.multiplexor
Class FlatFileMultiplexor

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

public class FlatFileMultiplexor
extends Multiplexor

Presently more a proof-of-concept than anything else, for checking the new Multiplexor architecture.

Uses "flat-file" Java properties files, as in Program B, to store predicate data.

Author:
Noel Bush

Field Summary
private static java.lang.String FFM_FILE_LABEL
          The string ""FlatFileMultiplexor predicates file"".
private  java.lang.String ffmDirName
          The name of the subdirectory for the predicate files.
private static java.lang.String PREDICATES_SUFFIX
          The suffix for a predicates storage file.
 
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
FlatFileMultiplexor(Core coreOwner)
          Creates a new FlatFileMultiplexor with the given Core as owner.
 
Method Summary
 void createUser(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Does nothing (FlatFileMultiplexor currently does not support authentication).
 boolean changePassword(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Always returns true (FlatFileMultiplexor currently does not support authentication).
 boolean checkUser(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Always returns true (FlatFileMultiplexor currently does not support authentication).
 void initialize()
          Can do whatever initialization is needed for the particular multiplexor.
 java.lang.String loadPredicate(java.lang.String name, java.lang.String userid, java.lang.String botid)
          Loads the value of a predicate from disk.
private  java.util.Properties loadPredicates(java.lang.String userid, java.lang.String botid)
          Loads the predicates file for a given userid.
 void savePredicate(java.lang.String name, java.lang.String value, java.lang.String userid, java.lang.String botid)
          Saves a predicate to disk.
private  void savePredicates(java.util.Properties predicates, java.lang.String userid, java.lang.String botid)
          Saves the predicates file for a given userid.
 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

ffmDirName

private java.lang.String ffmDirName
The name of the subdirectory for the predicate files.


PREDICATES_SUFFIX

private static final java.lang.String PREDICATES_SUFFIX
The suffix for a predicates storage file.

See Also:
Constant Field Values

FFM_FILE_LABEL

private static final java.lang.String FFM_FILE_LABEL
The string ""FlatFileMultiplexor predicates file"".

See Also:
Constant Field Values
Constructor Detail

FlatFileMultiplexor

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

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

initialize

public void initialize()
Description copied from class: Multiplexor
Can do whatever initialization is needed for the particular multiplexor.

Specified by:
initialize in class Multiplexor
See Also:
Multiplexor.initialize()

checkUser

public boolean checkUser(java.lang.String userid,
                         java.lang.String password,
                         java.lang.String botid)
Always returns true (FlatFileMultiplexor currently does not support authentication).

Specified by:
checkUser in class Multiplexor
Parameters:
userid - the userid to check
password - the password to try
botid - the id of the bot for whom to check the given userid/password combination
Returns:
true always

createUser

public void createUser(java.lang.String userid,
                       java.lang.String password,
                       java.lang.String botid)
Does nothing (FlatFileMultiplexor currently does not support authentication).

Specified by:
createUser in class Multiplexor
Parameters:
userid - the userid to create
password - the password to add
botid - the id of the bot for whom to create the given userid/password combination

changePassword

public boolean changePassword(java.lang.String userid,
                              java.lang.String password,
                              java.lang.String botid)
Always returns true (FlatFileMultiplexor currently does not support authentication).

Specified by:
changePassword in class Multiplexor
Parameters:
userid - the userid for whom to change the passwod
password - the password to change
botid - the id of the bot for whom to change the given userid/password combination
Returns:
true always

savePredicate

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

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 disk.

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

loadPredicates

private java.util.Properties loadPredicates(java.lang.String userid,
                                            java.lang.String botid)
Loads the predicates file for a given userid. Ensures that the directory exists.

Parameters:
userid - the userid to look for
botid - the botid with which to associate the userid in the search
Returns:
the predicates for the userid

savePredicates

private void savePredicates(java.util.Properties predicates,
                            java.lang.String userid,
                            java.lang.String botid)
Saves the predicates file for a given userid. Ensures that the directory exists.

Parameters:
predicates -
userid - the userid for which to save the predicates
botid - the botid for which to save the predicates

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)