org.alicebot.server.core
Class PredicateMaster

java.lang.Object
  extended by org.alicebot.server.core.PredicateMaster

public class PredicateMaster
extends java.lang.Object

Maintains in-memory predicate values for userids. Every public set and get method checks the size of the cache, and saves out part of it if it has exceeded a configurable limit.

This currently has the defect that it doesn't choose intelligently which userids' predicates to cache (it should do this for the ones who have not been heard from the longest). The HashMap that contains the predicates (keyed by userid) makes no guarantees about order. :-(

Since:
4.1.4'
Author:
Noel Bush

Field Summary
protected static int cacheSize
          A counter for tracking the number of predicate value cache operations.
protected static java.lang.String PREDICATE_EMPTY_DEFAULT
          The predicate empty default.
 
Method Summary
protected  java.lang.Object clone()
          Prohibits cloning this class.
static java.lang.String get(java.lang.String name, int index, java.lang.String userid, java.lang.String botid)
          Gets the predicate value associated with a name at a given index for a given userid.
static java.lang.String get(java.lang.String name, java.lang.String userid, java.lang.String botid)
          Gets the predicate value associated with a name for a given userid.
static java.lang.String push(java.lang.String name, java.lang.String value, java.lang.String userid, java.lang.String botid)
          Pushes a value onto an indexed predicate name for a given userid, and returns either the name or the value, depending on the predicate type.
(package private) static void saveAll()
          Dumps the entire cache.
static java.lang.String set(java.lang.String name, int index, java.lang.String value, java.lang.String userid, java.lang.String botid)
          Sets a value against an indexed predicate name for a given userid, and returns either the name or the value, depending on the predicate type.
static java.lang.String set(java.lang.String name, java.lang.String value, java.lang.String userid, java.lang.String botid)
          Sets a predicate value against a predicate name for a given userid, and returns either the name or the value, depending on the predicate type.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheSize

protected static int cacheSize
A counter for tracking the number of predicate value cache operations.


PREDICATE_EMPTY_DEFAULT

protected static final java.lang.String PREDICATE_EMPTY_DEFAULT
The predicate empty default.

Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Prohibits cloning this class.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

set

public static java.lang.String set(java.lang.String name,
                                   java.lang.String value,
                                   java.lang.String userid,
                                   java.lang.String botid)
Sets a predicate value against a predicate name for a given userid, and returns either the name or the value, depending on the predicate type.

Parameters:
name - the predicate name
value - the predicate value
userid - the userid
botid -
Returns:
the name or the value, depending on the predicate type

set

public static java.lang.String set(java.lang.String name,
                                   int index,
                                   java.lang.String value,
                                   java.lang.String userid,
                                   java.lang.String botid)
Sets a value against an indexed predicate name for a given userid, and returns either the name or the value, depending on the predicate type.

Parameters:
name - the predicate name
index - the index
value - the predicate value
userid - the userid
botid -
Returns:
the name or the value, depending on the predicate type

push

public static java.lang.String push(java.lang.String name,
                                    java.lang.String value,
                                    java.lang.String userid,
                                    java.lang.String botid)
Pushes a value onto an indexed predicate name for a given userid, and returns either the name or the value, depending on the predicate type.

Parameters:
name - the predicate name
value - the predicate value
userid - the userid
botid -
Returns:
the name or the value, depending on the predicate type

get

public static java.lang.String get(java.lang.String name,
                                   java.lang.String userid,
                                   java.lang.String botid)
Gets the predicate value associated with a name for a given userid.

Parameters:
name - the predicate name
userid - the userid
botid -
Returns:
the value associated with the given name, for the given userid

get

public static java.lang.String get(java.lang.String name,
                                   int index,
                                   java.lang.String userid,
                                   java.lang.String botid)
Gets the predicate value associated with a name at a given index for a given userid.

Parameters:
name - the predicate name
index - the index
userid - the userid
botid -
Returns:
the value associated with the given name at the given index, for the given userid

saveAll

static void saveAll()
Dumps the entire cache.