org.starhope.appius.util
Class AppiusConfig

java.lang.Object
  extended by org.starhope.appius.util.AppiusConfig

public final class AppiusConfig
extends Object

This static class is the singleton responsible for configuration, factories, etc.

Author:
brpocock@star-hope.org

Field Summary
private static Properties config
          The internal configuration database is really a Java Properties object.
private static ConcurrentSkipListSet<GetsConfigReload> configLoaders
          Set of things that want to know if the configuration changes
private static boolean dbcpActive
          If true, use database connection pooling
private static Map<String,Connection> dbh
          This is the data source for SQL queries.
private static Map<String,DataSource> ds
          JDBC data source
private static ConcurrentHashMap<FilterType,AbstractCensor> filters
          The library of instantiated filters for various purposes
private static Map<String,org.apache.commons.dbcp.PoolableConnectionFactory> poolableConnectionFactory
          This is the container for the poolable connection factory, which is never directly read again, but is used to contain the DBCP pool.
static Random rnd
          A running random number holder
private static boolean tomcatDBCP
          Flag: whether to use Tomcat's DBCP
 
Constructor Summary
AppiusConfig()
           
 
Method Summary
static boolean alwaysRealtime()
           
static boolean confDontKickStaff()
          This is a negative assertion ...
static void configChanged()
          Announce to all interested parties that the configuration has been changed in some way
static boolean disableCache()
           
static int getAdminPort()
          Get the port number on which to listen for administrative commands
static int getBackdoorBufferSize()
           
static com.whirlycott.cache.Cache<String,?> getCache(String cacheID)
           
static String getChatFilterName()
          Deprecated. 
static String getConfig(String key)
          This fetches up a configuration property in general.
static boolean getConfigBool(String string)
           
static boolean getConfigBoolOrFalse(String string)
          The same as getConfigBool(String) but returns a “false” if the key is not found
static boolean getConfigBoolOrTrue(String string)
          The same as getConfigBool(String) but returns a “true” if the key is not found
static String getConfigOrDefault(String key, String defaultValue)
           
static String getConfigOrNull(String string)
          This calls @see(#getConfig), but doesn't throw any exceptions, it just returns a null if the string isn't found in the configuration.
private static Connection getConnectionToArbitraryDatabase(String host, String schema, String user, String password)
          Obtain a connection to an arbitrary schema on the database server
static Connection getDatabaseConnection()
           
static String getDBCPInfo()
          get status information from DBCP pools
private static byte getDBCPWhenExhaustedAction()
          Get the byte values used for DBCP enumeration of whenExhaustedAction from the string forms used in the configuration.
static String getDNS_JNDI()
          This returns the DNS URL to be used in JNDI queries for DNS lookups.
static AbstractCensor getFilter(FilterType filter_type)
          Obtain a filter (censor) object suitable for filtering a certain type of data, e.g.
static int getFutureDatagramsMax()
          Get the number of deferred (future) datagrams permitted to be enqueued for a single user, before the user's connection is decided to be “too laggy” and dropped.
static long getIdleKickTime()
           
static long getIdleWarnTime()
           
static int getInt(String string)
           
static int getIntOrDefault(String string, int defaultValue)
          Get an integer value from the configuration; or, return a given default value if the value is not set, or can't be parsed as an integer.
static int getIntOrZero(String string)
           
static AbstractItem getItemCreationTemplate(int itemID)
           
static Connection getJournalDatabaseConnection()
          get a connection to the journal database
static List<String> getList(String configKey)
          Get a list of strings from a single configuration key, separated by whitespace
static Logger getLogger()
           
static String getLoginFilterName()
           
static javax.mail.Address getMailSender()
          Get a Java mail Address object for sending automated eMails.
static int getMaxInputSize()
          Get the maximum allowed input size for one client
static long getMetronomeTime()
          Get the granularity of the global metronome.
static long getNudgeTime()
           
static boolean getRandomBool()
           
static int getRandomInt(int from, int to)
           
static
<T extends DataRecord>
RecordLoader<T>
getRecordLoaderForClass(Class<T> klass)
          get the record loader type for handling records of a given class
static RecordSetLoader<? extends DataRecordSet<?>> getRecordSetLoaderForClass(Class<? extends DataRecordSet<?>> klass)
          WRITEME: Document this method brpocock@star-hope.org
static String getServerName()
          Deprecated. 
static String getSFSName()
          Deprecated. 
static int getSFSPort()
          Deprecated. 
static String getSMTPHost()
           
static Connection getStoreDatabaseConnection()
           
static String getTLD()
          Get the top-level domain name of the game server(s).
static Class<? extends User> getUserClass()
          WRITEME: document this method (brpocock@star-hope.org, Dec 30, 2009)
static Connection getZonesDatabaseConnection()
          Get a connection to the database containing the Zones table
static void init()
          Initialize the configuration system from the Properties system and any other relevant sources.
private static void initDBCP(String host, String user, String password, String schema)
          WRITEME: document this method (brpocock@star-hope.org, Dec 16, 2009)
static boolean isBackdoorOpen()
          Determine whether the administrative backdoor should be open
static boolean isDebug()
          Return true if the system is set to debugging mode
static void loadConfig()
          Load (or reload) the configuration from the configuration properties file (/etc/appius/config.properties), and notify other classes that can adjust their configuration of that fact.
static boolean mailBugs()
           
static GameWorldMessage newGameWorldMessage()
           
static void setConfig(String key, String value)
           
static void setMailBugs(boolean b)
          Determine whether to mail out bug reports, or not.
static void wantConfigReload(GetsConfigReload thing)
          Add something to the list of things that want configuration reload notifications
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

private static final Properties config
The internal configuration database is really a Java Properties object. This whole class exists to disguise that implementation detail.


configLoaders

private static ConcurrentSkipListSet<GetsConfigReload> configLoaders
Set of things that want to know if the configuration changes


dbcpActive

private static boolean dbcpActive
If true, use database connection pooling


dbh

private static final Map<String,Connection> dbh
This is the data source for SQL queries.


ds

private static final Map<String,DataSource> ds
JDBC data source


filters

private static ConcurrentHashMap<FilterType,AbstractCensor> filters
The library of instantiated filters for various purposes


poolableConnectionFactory

private static final Map<String,org.apache.commons.dbcp.PoolableConnectionFactory> poolableConnectionFactory
This is the container for the poolable connection factory, which is never directly read again, but is used to contain the DBCP pool.


rnd

public static final Random rnd
A running random number holder


tomcatDBCP

private static boolean tomcatDBCP
Flag: whether to use Tomcat's DBCP

Constructor Detail

AppiusConfig

public AppiusConfig()
Method Detail

alwaysRealtime

public static boolean alwaysRealtime()
Returns:
true, if all Data Record Loaders should be treated as realtime

confDontKickStaff

public static boolean confDontKickStaff()
This is a negative assertion ... sorry. If true, then do NOT kick staff members (users with a staff level greater than PUBLIC) for hitting the word filters.

Returns:
true, if we do NOT kick staff members for bad language

configChanged

public static void configChanged()
Announce to all interested parties that the configuration has been changed in some way


disableCache

public static boolean disableCache()
Returns:
True, to disable Nomenclator's internal object caché

getAdminPort

public static int getAdminPort()
Get the port number on which to listen for administrative commands

Returns:
the port number

getBackdoorBufferSize

public static int getBackdoorBufferSize()
Returns:
the size of the receive buffer for the backdoor

getCache

public static com.whirlycott.cache.Cache<String,?> getCache(String cacheID)
Parameters:
cacheID - the name of the cache
Returns:
the Whirley Cache

getChatFilterName

@Deprecated
public static String getChatFilterName()
Deprecated. 

Returns:
The name (database filter title) of the filter to be used for chat

getConfig

public static String getConfig(String key)
                        throws NotFoundException
This fetches up a configuration property in general.

Parameters:
key - The identifier of the configuration value to be queried
Returns:
The configuration string
Throws:
NotFoundException - If the configuration string is not found

getConfigBool

public static boolean getConfigBool(String string)
                             throws NotFoundException
Parameters:
string - the configuration identifier string
Returns:
true or false, based on the configuration string
Throws:
NotFoundException - if the value can't be found or isn't a boolean (literal "true" or "false" only)

getConfigBoolOrFalse

public static boolean getConfigBoolOrFalse(String string)
The same as getConfigBool(String) but returns a “false” if the key is not found

Parameters:
string - the config identifier string
Returns:
false, if not found or not boolean, or configured as false; true, only if configured as “true”

getConfigBoolOrTrue

public static boolean getConfigBoolOrTrue(String string)
The same as getConfigBool(String) but returns a “true” if the key is not found

Parameters:
string - the config identifier string
Returns:
true, if not found or not boolean, or configured as true; false, only if configured as “false”

getConfigOrDefault

public static String getConfigOrDefault(String key,
                                        String defaultValue)
Parameters:
key - configuration key
defaultValue - default value
Returns:
the configured value of the key, or if not found, the default value given

getConfigOrNull

public static String getConfigOrNull(String string)
This calls @see(#getConfig), but doesn't throw any exceptions, it just returns a null if the string isn't found in the configuration.

Parameters:
string - The identifier of the configuration being queries
Returns:
Either the config string, or (if it's not found) a null

getConnectionToArbitraryDatabase

private static Connection getConnectionToArbitraryDatabase(String host,
                                                           String schema,
                                                           String user,
                                                           String password)
Obtain a connection to an arbitrary schema on the database server

Parameters:
host - Database server hostname
schema - Database schema name
user - database user account name
password - database user account password
Returns:
a live connection to the given database

getDatabaseConnection

public static Connection getDatabaseConnection()
                                        throws SQLException
Returns:
Gets a connection to the database.
Throws:
SQLException - (bubbled up from underlying layers)

getDBCPInfo

public static String getDBCPInfo()
                          throws NotFoundException,
                                 SQLException
get status information from DBCP pools

Returns:
Status of all DBCP connection pools
Throws:
NotFoundException - If one of the schema keys can't be found
SQLException - if the driver can't be accessed

getDBCPWhenExhaustedAction

private static byte getDBCPWhenExhaustedAction()
Get the byte values used for DBCP enumeration of whenExhaustedAction from the string forms used in the configuration. Valid string values are grow, fail, or block.

Returns:
a byte (enumeration) value used to configure DBCP

getDNS_JNDI

public static String getDNS_JNDI()
This returns the DNS URL to be used in JNDI queries for DNS lookups.

Returns:
A "dns://" URL for the DNS server which is to be queried.

getFilter

public static AbstractCensor getFilter(FilterType filter_type)
Obtain a filter (censor) object suitable for filtering a certain type of data, e.g. user login names or in-game chat.

Parameters:
filter_type - the type of filter to obtain
Returns:
a filter for the given purpose

getFutureDatagramsMax

public static int getFutureDatagramsMax()
Get the number of deferred (future) datagrams permitted to be enqueued for a single user, before the user's connection is decided to be “too laggy” and dropped.

Returns:
the maximum number of future datagrams to be enqueued for delivery to an user before they are disconnected

getIdleKickTime

public static long getIdleKickTime()
Returns:
the time for an user to sit idle before we kick them offline

getIdleWarnTime

public static long getIdleWarnTime()
Returns:
the time for an user to sit idle before we send a warning

getInt

public static int getInt(String string)
                  throws NumberFormatException,
                         NotFoundException
Parameters:
string - the configuration key
Returns:
the configured value as an integer
Throws:
NotFoundException - if the key isn't found in the configuration
NumberFormatException - if the key can't be parsed as an integer

getIntOrDefault

public static int getIntOrDefault(String string,
                                  int defaultValue)
Get an integer value from the configuration; or, return a given default value if the value is not set, or can't be parsed as an integer.

Parameters:
string - The configuration key
defaultValue - The default value to be returned if the value isn't available
Returns:
The configuration string specified; or, if none is specified in the active configuration (or is not an integer), the default value provided

getIntOrZero

public static int getIntOrZero(String string)
Parameters:
string - the configuration key
Returns:
the configured value as an integer, or if the value is not configured or not parseable as an integer, returns 0 as a ‘safety’ value instead.

getItemCreationTemplate

public static AbstractItem getItemCreationTemplate(int itemID)
Parameters:
itemID - The item whose template is being requested
Returns:
an AbstractItem for that item

getJournalDatabaseConnection

public static Connection getJournalDatabaseConnection()
                                               throws SQLException
get a connection to the journal database

Returns:
journal DB connection
Throws:
SQLException - if the connection can't be made for some reason

getList

public static List<String> getList(String configKey)
Get a list of strings from a single configuration key, separated by whitespace

Parameters:
configKey - the configuration key containing the list
Returns:
The whitespace-split list; or, an empty list if the configuration key was unset.

getLogger

public static Logger getLogger()
Returns:
logger (not used)

getLoginFilterName

public static String getLoginFilterName()
Returns:
The name (database filter title) of the filter to be used for login name selections

getMailSender

public static javax.mail.Address getMailSender()
Get a Java mail Address object for sending automated eMails. This is taken from the $system user's eMail address.

Returns:
The address from which automated mails come

getMaxInputSize

public static int getMaxInputSize()
Get the maximum allowed input size for one client

Returns:
the maximum input size allowed in one packet

getMetronomeTime

public static long getMetronomeTime()
Get the granularity of the global metronome. This is used to drive all NPC, nudge, and idle timeout events.

Returns:
the time between metronome ticks in milliseconds.

getNudgeTime

public static long getNudgeTime()
Returns:
The time between user events before we nudge the user (in milliseconds)

getRandomBool

public static boolean getRandomBool()
Returns:
a random boolean value

getRandomInt

public static int getRandomInt(int from,
                               int to)
Parameters:
from - lower limit
to - upper limit
Returns:
a random integer in the given range (inclusive)

getRecordLoaderForClass

public static <T extends DataRecord> RecordLoader<T> getRecordLoaderForClass(Class<T> klass)
get the record loader type for handling records of a given class

Type Parameters:
T - the type for which a RecordLoader is being sought
Parameters:
klass - the class of the DataRecord type
Returns:
a RecordLoader implementation

getRecordSetLoaderForClass

public static RecordSetLoader<? extends DataRecordSet<?>> getRecordSetLoaderForClass(Class<? extends DataRecordSet<?>> klass)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
klass - WRITEME
Returns:
WRITEME

getServerName

@Deprecated
public static String getServerName()
Deprecated. 

Get the name of the Smart Fox Server to which we connect in SFS mode. This is the string base name, for example, “whitney,” of the login server (containing $Eden)

Returns:
The string base hostname (without domain) of the login server

getSFSName

@Deprecated
public static String getSFSName()
Deprecated. 

Returns:
The IP address of the server (as a string) indicated by getServerName()

getSFSPort

@Deprecated
public static int getSFSPort()
Deprecated. 

Returns:
The SFS server port. Should almost always be 9339.

getSMTPHost

public static String getSMTPHost()
Returns:
the SMTP hostname for outbound eMail

getStoreDatabaseConnection

public static Connection getStoreDatabaseConnection()
                                             throws SQLException
Returns:
Gets a connection to the database.
Throws:
SQLException - (bubbled up from underlying layers)

getTLD

public static String getTLD()
Get the top-level domain name of the game server(s).

Returns:
the top-level domain name of the game server(s)

getUserClass

public static Class<? extends User> getUserClass()
WRITEME: document this method (brpocock@star-hope.org, Dec 30, 2009)

Returns:
the class for users

getZonesDatabaseConnection

public static Connection getZonesDatabaseConnection()
                                             throws SQLException
Get a connection to the database containing the Zones table

Returns:
a connection that can be used to access the Zones table
Throws:
SQLException - if the connection can't be obtained

init

public static void init()
Initialize the configuration system from the Properties system and any other relevant sources. This is normally performed once, at startup.


initDBCP

private static void initDBCP(String host,
                             String user,
                             String password,
                             String schema)
WRITEME: document this method (brpocock@star-hope.org, Dec 16, 2009)

Parameters:
host - WRITEME
user - WRITEME
password - WRITEME
schema - WRITEME

isBackdoorOpen

public static boolean isBackdoorOpen()
Determine whether the administrative backdoor should be open

Returns:
true, if the backdoor should be open

isDebug

public static boolean isDebug()
Return true if the system is set to debugging mode

Returns:
true, if the game is in debugging mode

loadConfig

public static void loadConfig()
Load (or reload) the configuration from the configuration properties file (/etc/appius/config.properties), and notify other classes that can adjust their configuration of that fact.


mailBugs

public static boolean mailBugs()
Returns:
true, if bug reports should be eMailed

newGameWorldMessage

public static GameWorldMessage newGameWorldMessage()
Returns:
WRITEME

setConfig

public static void setConfig(String key,
                             String value)
Parameters:
key - The configuration value to be set
value - The new value

setMailBugs

public static void setMailBugs(boolean b)
Determine whether to mail out bug reports, or not.

Parameters:
b - Whether to mail bug reports

wantConfigReload

public static void wantConfigReload(GetsConfigReload thing)
Add something to the list of things that want configuration reload notifications

Parameters:
thing - The object wanting configuration change notifications