Atavism Version 2018.1AGIS API

atavism.server.engine
Class Engine

java.lang.Object
  extended by atavism.server.engine.Engine

public class Engine
extends java.lang.Object

Base Engine class that maintains static properties for all key server properties, connects to database, handles client connections, and performs other key tasks.


Nested Class Summary
protected static class Engine.EngineJMX
           
static interface Engine.EngineJMXMBean
           
 
Field Summary
protected static java.lang.reflect.Method cpuMethod
           
static java.lang.String dumpStacksAndExitIfFileExists
          Scripting should set this to the name of a file which, if the file exists, causes the engine to dump the stacks of all threads and exit the process
static int ExecutorThreadPoolSize
          Determines the size of the scheduled thread pool.
static int MAX_NETWORK_BUF_SIZE
          The maximum size of an RDP or aggregated RDP packet, and the size at which the packet aggregator will send a packet even if the aggregation interval has not expired
 long PersistentObjectSaveIntervalMS
          The current interval in millisecond between periodic saves of modified persistent objects to the database.
protected static int processorCount
           
static java.util.Properties properties
          The Properties instance, typically read from file $AO_HOME/bin/atavism.properties
 
Constructor Summary
Engine()
          Constructor gets the properties; creates the management agent if required; and starts the CPU time thread if required.
 
Method Summary
protected  java.lang.Object createMBeanInstance()
          Return JMX MBean instance object.
static void defaultDispatchMessage(Message message, int flags, MessageCallback callback)
          The default message dispatcher.
static void dumpAllThreadStacks()
          Utility method to dump all the thread stacks of the current process to the log
static void dumpAllThreadStacks(java.lang.StringBuilder stringBuilder, boolean sortThreads)
          Utility method that outputs the set of stack traces to the stringBuilder parameter.
static MessageAgent getAgent()
          Get the MessageAgent instance.
protected static java.lang.reflect.Method getCPUMethod()
          Get method capable of returning process CPU usage.
static EnginePlugin getCurrentPlugin()
          Get the plugin active on the current thread.
static Database getDatabase()
          Get the engine's Database object
static java.lang.String getDBDriver()
          Gets the JDBC driver classname string - default is MySQL driver.
static java.lang.String getDBHostname()
          Gets The database host name.
static java.lang.String getDBName()
          Gets the database name - default is "atavism".
static java.lang.String getDBPassword()
          Gets the database password.
static java.lang.String getDBType()
          Gets the database type - default is "mysql".
static java.lang.String getDBUrl()
          Gets the JDBC connection string (URL).
static java.lang.String getDBUser()
          Gets the database user name.
static java.lang.String getEngineHostName()
          Get the engine host name
static EventServer getEventServer()
          Get the EventServer object, which provides a queue of events.
static java.util.concurrent.ScheduledThreadPoolExecutor getExecutor()
          Return the thread pool that can run operations some time in the future
static Engine getInstance()
          Gets the Engine instance; for now, there are no callers
static Interpolator<?> getInterpolator()
          Return this engine's interpolator object
static java.lang.Integer getIntProperty(java.lang.String propName)
          Get the named property, coercing it to an int.
static java.lang.String getLogLevel()
          Get the log level from the properties file or sys. prop, or default to 1 (debug).
static javax.management.MBeanServer getManagementAgent()
          Get the JMX top-level agent.
static java.lang.String getMessageServerHostname()
          Gets the name of the msgsys domain server.
static java.lang.Integer getMessageServerPort()
          Gets the msgsys domain server listener port.
static OIDManager getOIDManager()
          Get the engine's OIDManager object, which hands out oids, and records the ranges used in the database.
protected static java.lang.Class getParentInterface(java.lang.Class cl, java.lang.String name)
          Common method to get the parent interface
static PersistenceManager getPersistenceManager()
          Returns the persistence manager, used to save objects into the database at regular intervals.
 long getPersistentObjectSaveIntervalMS()
          Get the interval between saves of dirty objects.
static EnginePlugin getPlugin(java.lang.String name)
          Get the named plugin, or return null if it's not part of this server.
protected static long getProcessCpuTime(java.lang.reflect.Method cpuMethod, java.lang.Object mxbean)
          Common method to get the process CPU time.
static java.util.Properties getProperties()
           
static java.lang.String getProperty(java.lang.String propName)
          Get the string property value for the given property name, either from the System property of that name, or from the properties read from the propery file.
static ScriptManager getScriptManager()
          this should only be called by the engine thread
static int getStatusReportingInterval()
          Getter for the status reporting interval
static java.lang.Integer getWorldMgrPort()
          Get the port number of the world manager.
static java.lang.String getWorldName()
          The engine should know the world name. it uses it when it creates characters in the database.
static boolean isManagementEnabled()
          Get whether management is enabled
static void main(java.lang.String[] args)
          The engine main program.
static java.util.Map<java.lang.String,java.lang.String> makeMapOfString(java.lang.String str)
          Make a map from the comma-separated name=value pairs
static java.lang.String makeStringFromMap(java.util.Map<java.lang.String,java.lang.String> propMap)
          Make a string from the map of name/value pairs
static void printStack(java.lang.StringBuilder stringBuilder, java.lang.StackTraceElement[] elements)
           
static void processPostScripts(java.util.List<java.lang.String> postScripts)
          Process a set of startup scripts whose file names are given by array arg.
static java.util.List<java.lang.String> processPreScripts(java.lang.String[] args)
          Process a set of startup scripts whose file names are given by array arg.
static void registerPlugin(EnginePlugin plugin)
          Registers a plugin instance with the engine, and call the plugin's activate method.
static EnginePlugin registerPlugin(java.lang.String className)
          Creates the new plugin instance, and registers the plugin with the engine, and calls the plugin's activate method.
static void registerStatusReportingPlugin(EnginePlugin plugin)
          Register the plugin passed in with Engine for status reporting with the database.
static void setBasicInterpolatorInterval(java.lang.Integer interval)
          Set the time interval between periodic interpolations
static void setCurrentPlugin(EnginePlugin plugin)
          Set the plugin active on the current thread.
static void setDatabase(Database db)
          Set the engine's Database object
static void setDBDriver(java.lang.String driver)
          Sets the JDBC driver classname string.
static void setDBHostname(java.lang.String hostname)
          Sets the database host name.
static void setDBName(java.lang.String name)
          Sets the database name.
static void setDBPassword(java.lang.String password)
          Sets the database password.
static void setDBType(java.lang.String dbtype)
          Sets the database type
static void setDBUrl(java.lang.String url)
          Sets the JDBC connection string (URL).
static void setDBUser(java.lang.String username)
          Sets the database user name.
static void setInterpolator(Interpolator<?> interpolator)
          Set this engine's interpolator object
static void setLogLevel(java.lang.String level)
          Set the log level.
static void setMessageServerHostname(java.lang.String host)
          Sets the name of the msgsys domain server.
static void setMessageServerPort(java.lang.Integer port)
          Set the msgsys domain server listener port.
static void setOIDManager(OIDManager o)
          Set the engine's OIDManager object.
 void setPersistentObjectSaveIntervalMS(long interval)
          Set the interval between saves of dirty objects.
static void setProperty(java.lang.String propName, java.lang.String propValue)
          Set the string property value for the given property name, both in the System property as well as the encached Properties map.
static void setStatusReportingInterval(int statusReportingInterval)
          Setter for the status reporting interval
static void setWorldMgrPort(java.lang.Integer port)
          Sets the port number of the world manager.
static void setWorldName(java.lang.String worldName)
          Set the world name to be used by the engine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cpuMethod

protected static java.lang.reflect.Method cpuMethod

processorCount

protected static int processorCount

properties

public static java.util.Properties properties
The Properties instance, typically read from file $AO_HOME/bin/atavism.properties


ExecutorThreadPoolSize

public static int ExecutorThreadPoolSize
Determines the size of the scheduled thread pool. To take effect, must be defined by a pre-script, e.g., proxy.py


MAX_NETWORK_BUF_SIZE

public static int MAX_NETWORK_BUF_SIZE
The maximum size of an RDP or aggregated RDP packet, and the size at which the packet aggregator will send a packet even if the aggregation interval has not expired


dumpStacksAndExitIfFileExists

public static java.lang.String dumpStacksAndExitIfFileExists
Scripting should set this to the name of a file which, if the file exists, causes the engine to dump the stacks of all threads and exit the process


PersistentObjectSaveIntervalMS

public long PersistentObjectSaveIntervalMS
The current interval in millisecond between periodic saves of modified persistent objects to the database.

Constructor Detail

Engine

public Engine()
Constructor gets the properties; creates the management agent if required; and starts the CPU time thread if required.

Method Detail

getInstance

public static Engine getInstance()
Gets the Engine instance; for now, there are no callers

Returns:
Engine instance

dumpAllThreadStacks

public static void dumpAllThreadStacks()
Utility method to dump all the thread stacks of the current process to the log


dumpAllThreadStacks

public static void dumpAllThreadStacks(java.lang.StringBuilder stringBuilder,
                                       boolean sortThreads)
Utility method that outputs the set of stack traces to the stringBuilder parameter.

Parameters:
stringBuilder - the buffer to which the stack traces will be appended
sortThreads - true if the thread stack traces should be ordered based on the thread names

printStack

public static void printStack(java.lang.StringBuilder stringBuilder,
                              java.lang.StackTraceElement[] elements)

getEventServer

public static EventServer getEventServer()
Get the EventServer object, which provides a queue of events.

Returns:
EventServer The EventServer instance.

getExecutor

public static java.util.concurrent.ScheduledThreadPoolExecutor getExecutor()
Return the thread pool that can run operations some time in the future

Returns:
ScheduledThreadPoolExecutor The ScheduledThreadPoolExecutor instance.

getInterpolator

public static Interpolator<?> getInterpolator()
Return this engine's interpolator object

Returns:
The Interpolator instance.

setInterpolator

public static void setInterpolator(Interpolator<?> interpolator)
Set this engine's interpolator object

Parameters:
interpolator - The interpolator object to associate with this Engine.

setBasicInterpolatorInterval

public static void setBasicInterpolatorInterval(java.lang.Integer interval)
Set the time interval between periodic interpolations

Parameters:
interval - The time interval in milliseconds between interpolations.

getScriptManager

public static ScriptManager getScriptManager()
this should only be called by the engine thread


getDatabase

public static Database getDatabase()
Get the engine's Database object

Returns:
The Database instance associated with this Engine.

setDatabase

public static void setDatabase(Database db)
Set the engine's Database object

Parameters:
db - The Database instance to associate with the Engine.

getOIDManager

public static OIDManager getOIDManager()
Get the engine's OIDManager object, which hands out oids, and records the ranges used in the database.

Returns:
The OIDManager instance.

setOIDManager

public static void setOIDManager(OIDManager o)
Set the engine's OIDManager object.

Parameters:
o - The OIDManager object to associate with this Engine.

getPersistenceManager

public static PersistenceManager getPersistenceManager()
Returns the persistence manager, used to save objects into the database at regular intervals.

Returns:
The PersistenceManager instance associated with this Engine.

main

public static void main(java.lang.String[] args)
The engine main program. Parses the args to determin the scripts to run; connects to the database and reads the namespace mappings; creates a MessageAgent for the process and connects to the domain server; processes startup scripts; and finally loops forever waiting for shutdown or a request to dump the thread stacks.

Parameters:
args - The command-line arguments.

processPreScripts

public static java.util.List<java.lang.String> processPreScripts(java.lang.String[] args)
Process a set of startup scripts whose file names are given by array arg. These scripts are called 'preScripts' because they must run before the Engine object itself is initialized

Parameters:
args - The command-line args passed in from the main program.
Returns:
A list of the "post" scripts to be run after the Engine instance is initialized.

processPostScripts

public static void processPostScripts(java.util.List<java.lang.String> postScripts)
Process a set of startup scripts whose file names are given by array arg. These scripts are called 'postScripts' because they must run after the Engine object itself is initialized

Parameters:
postScripts - A list of the scripts to be run after the Engine object is initialized.

getPersistentObjectSaveIntervalMS

public long getPersistentObjectSaveIntervalMS()
Get the interval between saves of dirty objects.

Returns:
Milliseconds between saves in the PersistenceManager.

setPersistentObjectSaveIntervalMS

public void setPersistentObjectSaveIntervalMS(long interval)
Set the interval between saves of dirty objects.

Parameters:
interval - Milliseconds between saves in the PersistenceManager.

registerPlugin

public static EnginePlugin registerPlugin(java.lang.String className)
Creates the new plugin instance, and registers the plugin with the engine, and calls the plugin's activate method.

Parameters:
className - The class name of the plugin.
Returns:
The newly-created plugin.

registerPlugin

public static void registerPlugin(EnginePlugin plugin)
Registers a plugin instance with the engine, and call the plugin's activate method.

Parameters:
plugin - The engine plugin instance to be registered

getPlugin

public static EnginePlugin getPlugin(java.lang.String name)
Get the named plugin, or return null if it's not part of this server.

Parameters:
name - The name of the plugin to return
Returns:
The plugin with the given name, or null if it can't be found.

getCurrentPlugin

public static EnginePlugin getCurrentPlugin()
Get the plugin active on the current thread.

Returns:
Plugin or null if no active plugin has been set.

setCurrentPlugin

public static void setCurrentPlugin(EnginePlugin plugin)
Set the plugin active on the current thread.


getEngineHostName

public static java.lang.String getEngineHostName()
Get the engine host name

Returns:
The host name of this engine instance.

getDBDriver

public static java.lang.String getDBDriver()
Gets the JDBC driver classname string - default is MySQL driver.

Returns:
The class name of the JDBC driver.

setDBDriver

public static void setDBDriver(java.lang.String driver)
Sets the JDBC driver classname string.

Parameters:
driver - The JDBC driver classname string.

getDBType

public static java.lang.String getDBType()
Gets the database type - default is "mysql".

Returns:
The database type.

setDBType

public static void setDBType(java.lang.String dbtype)
Sets the database type

Parameters:
dbtype - The database type.

setDBUrl

public static void setDBUrl(java.lang.String url)
Sets the JDBC connection string (URL).

Parameters:
url - The JDBC connection string.

getDBUrl

public static java.lang.String getDBUrl()
Gets the JDBC connection string (URL).

Returns:
The JDBC connection string.

getDBUser

public static java.lang.String getDBUser()
Gets the database user name.

Returns:
The database user name.

setDBUser

public static void setDBUser(java.lang.String username)
Sets the database user name.

Parameters:
username - The database user name.

getDBPassword

public static java.lang.String getDBPassword()
Gets the database password.

Returns:
The database password.

setDBPassword

public static void setDBPassword(java.lang.String password)
Sets the database password.

Parameters:
password - The database password.

getDBHostname

public static java.lang.String getDBHostname()
Gets The database host name.

Returns:
The database host name.

setDBHostname

public static void setDBHostname(java.lang.String hostname)
Sets the database host name.

Parameters:
hostname - The database host name.

getDBName

public static java.lang.String getDBName()
Gets the database name - default is "atavism".

Returns:
The database name.

setDBName

public static void setDBName(java.lang.String name)
Sets the database name.

Parameters:
name - The database name.

getMessageServerHostname

public static java.lang.String getMessageServerHostname()
Gets the name of the msgsys domain server.

Returns:
The name of the msgsys domain server.

setMessageServerHostname

public static void setMessageServerHostname(java.lang.String host)
Sets the name of the msgsys domain server.

Parameters:
host - The name of the msgsys domain server.

getMessageServerPort

public static java.lang.Integer getMessageServerPort()
Gets the msgsys domain server listener port.

Returns:
The msgsys domain server listener port.

setMessageServerPort

public static void setMessageServerPort(java.lang.Integer port)
Set the msgsys domain server listener port.

Parameters:
port - The msgsys domain server listener port.

setWorldMgrPort

public static void setWorldMgrPort(java.lang.Integer port)
Sets the port number of the world manager.

Parameters:
port - The port number of the world manager.

getWorldMgrPort

public static java.lang.Integer getWorldMgrPort()
Get the port number of the world manager.

Returns:
The port number of the world manager.

getStatusReportingInterval

public static int getStatusReportingInterval()
Getter for the status reporting interval

Returns:
The number of milliseconds between iterations of the status reporting thread.

setStatusReportingInterval

public static void setStatusReportingInterval(int statusReportingInterval)
Setter for the status reporting interval

Parameters:
statusReportingInterval - The number of milliseconds between iterations of the status reporting thread.

getProperties

public static java.util.Properties getProperties()

getProperty

public static java.lang.String getProperty(java.lang.String propName)
Get the string property value for the given property name, either from the System property of that name, or from the properties read from the propery file.

Parameters:
propName - The name of the property whose value should be returned.
Returns:
The value associated with propName, or null if there is none.

setProperty

public static void setProperty(java.lang.String propName,
                               java.lang.String propValue)
Set the string property value for the given property name, both in the System property as well as the encached Properties map.

Parameters:
propName - The name of the property whose value should be set.
propValue - The value to associate with the propName.

getIntProperty

public static java.lang.Integer getIntProperty(java.lang.String propName)
Get the named property, coercing it to an int.

Parameters:
propName - The property name.
Returns:
The integer property whose name is propName.
See Also:
getProperty(java.lang.String)

getWorldName

public static java.lang.String getWorldName()
The engine should know the world name. it uses it when it creates characters in the database. This is different from the server id.

Returns:
The value associated with property "atavism.worldname".

setWorldName

public static void setWorldName(java.lang.String worldName)
Set the world name to be used by the engine.

Parameters:
worldName - The value to associate with property "atavism.worldname".

getLogLevel

public static java.lang.String getLogLevel()
Get the log level from the properties file or sys. prop, or default to 1 (debug). Plugins are free to subsequently set the log level to a different value.

Returns:
The current log level value.

setLogLevel

public static void setLogLevel(java.lang.String level)
Set the log level.

Parameters:
level - The new log level value.

isManagementEnabled

public static boolean isManagementEnabled()
Get whether management is enabled

Returns:
True if management is enabled.

getAgent

public static MessageAgent getAgent()
Get the MessageAgent instance.

Returns:
The MessageAgent instance.

makeMapOfString

public static java.util.Map<java.lang.String,java.lang.String> makeMapOfString(java.lang.String str)
Make a map from the comma-separated name=value pairs

Parameters:
str - The string containing the comma-separated name=value pairs
Returns:
The map generated from the pairs

makeStringFromMap

public static java.lang.String makeStringFromMap(java.util.Map<java.lang.String,java.lang.String> propMap)
Make a string from the map of name/value pairs

Parameters:
propMap - The map of name/value pairs
Returns:
The string synthesized from the map.

defaultDispatchMessage

public static void defaultDispatchMessage(Message message,
                                          int flags,
                                          MessageCallback callback)
The default message dispatcher.

Parameters:
message - The message to be dispatched.
flags - The message flags.
callback - The MessageCallback instance to run when the message is dequeued.

registerStatusReportingPlugin

public static void registerStatusReportingPlugin(EnginePlugin plugin)
Register the plugin passed in with Engine for status reporting with the database.

Parameters:
plugin - An EnginPlugin instance.

getCPUMethod

protected static java.lang.reflect.Method getCPUMethod()
Get method capable of returning process CPU usage.

Returns:
A Method object

getProcessCpuTime

protected static long getProcessCpuTime(java.lang.reflect.Method cpuMethod,
                                        java.lang.Object mxbean)
Common method to get the process CPU time.

Parameters:
cpuMethod - A Method object that returns the process CPU time.
mxbean - The JavaBean used to get the CPU time.
Returns:
The cumulative CPU time for the Engine process.

getParentInterface

protected static java.lang.Class getParentInterface(java.lang.Class cl,
                                                    java.lang.String name)
Common method to get the parent interface

Parameters:
cl - The class whose parent interface is requested.
name - The name of the interface.
Returns:
The Class object representing the parent interface.

createMBeanInstance

protected java.lang.Object createMBeanInstance()
Return JMX MBean instance object. Over-ride to provide your own MBean implementation.


getManagementAgent

public static javax.management.MBeanServer getManagementAgent()
Get the JMX top-level agent.



Copyright © 2018 Dragonsan Studios Sp. z o.o.