public final class AgentServer extends Object
AgentServer
class manages the global configuration
of an agent server. It reads the configuration file, then it creates
and configure Engine
, Channel
and Network
components.
This class contains the main method for AgentServer, for example to
activate a server you have to run this class with two parameters: the
server id. and the path of the root of persistency. You can also use
a specialized main calling methods init and start.
The configuration file contains a config
element, that
is essentially made up of domain
s elements, and servers
(server
s elements):
Network
implementation (class SimpleNetwork
by default).
hostname
attribute describes the name or the IP address of this node)
network
element with attributes
giving the domain's name (domain
attribute) and the
communication port (port
attribute).
service
element describing it.
config
element or in a server one.
<?xml version="1.0"?> <!DOCTYPE config SYSTEM "a3config.dtd"> <config> <domain name="D1"/> <domain name="D2" class="fr.dyade.aaa.agent.PoolNetwork"/> <property name="D2.nbMaxCnx" value="1"/> <server id="0" name="S0" hostname="acores"> <network domain="D1" port="16300"/> <service class="fr.dyade.aaa.agent.AdminProxy" args="8090"/> <property name="A3DEBUG_PROXY" value="true"/> </server> <server id="2" name="S2" hostname="bermudes"> <network domain="D1" port="16310"/> <network domain="D2" port="16312"/> </server> <server id="3" name="S3" hostname="baleares"> <network domain="D2" port="16320"/> </server> </config>
This file described a 2 domains configuration D1 and D2, D1 with default
network protocol and D2 with the PoolNetwork
one, and 4
servers:
Engine
,
Channel
,
Network
,
MessageQueue
,
Transaction
Modifier and Type | Class and Description |
---|---|
(package private) static class |
AgentServer.ServerLock |
(package private) static class |
AgentServer.ServerStopper |
static class |
AgentServer.Status |
Modifier and Type | Field and Description |
---|---|
static String |
A3CMLWRP_PROPERTY
Name of property allowing to configure the XML wrapper used to read the server
configuration.
|
private static A3CMLConfig |
a3config
Static reference to the configuration.
|
static String |
ADMIN_DOMAIN |
static String |
ADMIN_SERVER |
static String |
BACKUP_FILE
Name of the property defining the backup file to restore.
|
static String |
CFG_ADMINPWD_PROPERTY
Name of property allowing to configure the administrator password when using the
default server configuration, by default it is the same that the administrator user
name.
|
static String |
CFG_ADMINUID_PROPERTY
Name of property allowing to configure the administrator user name when using the
default server configuration, by default "root".
|
static String |
CFG_CHECK_PERIOD_PROPERTY
Name of property allowing to configure the checking period of the server (in ms).
|
static String |
CFG_DIR_PROPERTY
Name of property allowing to configure the directory to search the XML
server configuration.
|
static String |
CFG_EXIT_ON_SERVICE_FAILURE_PROPERTY
Name of the property specifying that the server should stop if any of the services can
not start correctly.
|
static String |
CFG_FILE_PROPERTY
Name of property allowing to configure the filename of the XML server
configuration.
|
static int |
CFG_JMS_PORT_DFLT
Default value for JMS listening port: 16010.
|
static String |
CFG_JMS_PORT_PROPERTY
Name of property allowing to configure the listening port of the JMS server when
using the default server configuration, by default CFG_JMS_PORT_DFLT.
|
static int |
CFG_JNDI_PORT_DFLT
Default value for JNDI listening port: 16400.
|
static String |
CFG_JNDI_PORT_PROPERTY
Name of property allowing to configure the listening port of the JNDI server when
using the default server configuration, by default CFG_JNDI_PORT_PROPERTY.
|
static int |
CFG_MAX_JORAM_PORT_DFLT
Default value for maximum JMS listening port: 16100.
|
static String |
CFG_MAX_JORAM_PORT_PROPERTY
Name of property allowing to configure the maximum value for listening port of the JMS
server when using the default server configuration with random port choice (if listening
port is set to -3).
|
static int |
CFG_MIN_JORAM_PORT_DFLT
Default value for minimum JMS listening port: 16000.
|
static String |
CFG_MIN_JORAM_PORT_PROPERTY
Name of property allowing to configure the minimum value for listening port of the JMS
server when using the default server configuration with random port choice (if listening
port is set to -3).
|
static String |
CFG_NAME_PROPERTY |
(package private) static CheckServerTask |
checkServerTask |
private static Hashtable<String,MessageConsumer> |
consumers
Static references to all messages consumers initialized in this
agent server (including
Engine ). |
static org.osgi.framework.BundleContext |
context
Reference to OSGi root activator (bundle #0) if any.
|
static String |
DEFAULT_A3CMLWRP
Default value of the XML wrapper used to read server configuration, this default
value implies the use of the default SaxWrapper.
|
static String |
DEFAULT_BACKUP_FILE
Default name of the backup file to restore if it exists.
|
static String |
DEFAULT_CFG_DIR
Default value of the directory to search the XML server configuration,
value is null.
|
static String |
DEFAULT_CFG_FILE
Default value of the filename of the XML server configuration, value is
a3servers.xml . |
static String |
DEFAULT_CFG_NAME |
static String |
DEFAULT_SER_CFG_FILE
Default value of the filename of the serialized server configuration in the
persistence directory, value is
a3cmlconfig . |
static String |
DEFAULT_USE_DEFAULT_CONFIG
Default value for the USE_DEFAULT_CONFIG property.
|
static String |
defaultConfig
Default configuration used if no other configuration is found, by default empty.
|
static int |
ENCODABLE_CLASS_ID_AREA |
static String |
ENDSTRING |
(package private) static AgentEngine |
engine
Static reference to the engine.
|
static String |
ERRORSTRING |
private static AgentServer.ServerLock |
lock |
private static Logger |
logmon |
static int |
MESSAGE_CLASS_ID |
private static String |
name |
static short |
NULL_ID |
static String |
OKSTRING |
private static short |
serverId |
private static ServersHT |
servers
Static description of all known agent servers in ascending order.
|
static long |
startDate |
private static AgentServer.Status |
status |
(package private) static ThreadGroup |
tgroup |
private static Timer |
timer
Timer provided by the agent server.
|
(package private) static Transaction |
transaction
Static reference to the transactional monitor.
|
static String |
UPDATE_CONF_TX_NAME
Name of the transaction object indicating that the configuration object has been
updated in the transaction base.
|
static ServerUpdate |
updatecfg
Object indicating that the configuration object has been updated in the transaction
base (see UpdateConfTxName).
|
static String |
USE_DEFAULT_CONFIG_PROPERTY
Name of property allowing to use a default configuration when no configuration
file can be found.
|
Constructor and Description |
---|
AgentServer() |
Modifier and Type | Method and Description |
---|---|
static void |
addConsumer(String domain,
MessageConsumer cons) |
static void |
addServerDesc(ServerDesc desc) |
private static void |
configure()
The second step of initialization.
|
private static void |
createConsumers(A3CMLServer root) |
private static ServerDesc |
createServerDesc(A3CMLServer server) |
static Enumeration<ServerDesc> |
elementsServerDesc() |
static int |
externalUpdateConfFromFile(String serverConfigFilePath,
String serverDataDirPath)
Updates the stored configuration of an external server from a file
|
static int |
externalUpdateConfFromString(String serverConfig,
String serverDataDirPath)
Updates the stored configuration of an external server from a String
|
static A3CMLConfig |
getAppConfig(String[] domains)
Gets configuration of agent servers for a domain from the current
A3CMLConfig object.
|
static boolean |
getBoolean(String key)
Determines the boolean value of the server property with the specified name.
|
static long |
getCommitTime()
Return the total agent commit time.
|
static A3CMLConfig |
getConfig()
Returns the agent server configuration.
|
(package private) static MessageConsumer |
getConsumer(short sid)
Gets the message consumer for the corresponding server.
|
static MessageConsumer |
getConsumer(String domain) |
(package private) static Enumeration<MessageConsumer> |
getConsumers() |
static AgentEngine |
getEngine()
Returns the agent server engine.
|
static float |
getEngineAverageLoad1()
Returns the load averages for the last minute.
|
static float |
getEngineAverageLoad15()
Returns the load averages for the past 15 minutes.
|
static float |
getEngineAverageLoad5()
Returns the load averages for the past 5 minutes.
|
static int |
getEngineLoad()
Returns the immediate engine load.
|
static String |
getHostname(short sid)
Get the host name of an agent server.
|
static Integer |
getInteger(String key)
Determines the integer value of the server property with the
specified name.
|
static Integer |
getInteger(String key,
int value)
Determines the integer value of the server property with the
specified name.
|
static Long |
getLong(String key)
Determines the integer value of the server property with the specified
name.
|
static Long |
getLong(String key,
long value)
Determines the long value of the server property with the specified name.
|
static String |
getName() |
static String |
getProperty(String key)
Searches for the property with the specified key in the server property
list.
|
static String |
getProperty(String key,
String value)
Searches for the property with the specified key in the server property
list.
|
static long |
getReactTime()
Return the total agent reaction time.
|
static ServerDesc |
getServerDesc(short sid)
Gets the characteristics of the corresponding server.
|
static short |
getServerId() |
static short |
getServerIdByName(String name)
Returns the identifier of the agent server which name is specified.
|
static String |
getServerName() |
(package private) static int |
getServerNb()
Gets the number of server known on the current server.
|
static Enumeration<Short> |
getServersIds() |
static String |
getServiceArgs(short sid,
String classname)
Get the argument strings for a particular service.
|
static String |
getServiceArgs(String hostname,
String classname)
Get the argument strings for a particular service running on a server
identified by its host.
|
(package private) static ServiceDesc[] |
getServices()
Get the description of all services of the current agent server.
|
static int |
getStatus() |
static String |
getStatusInfo() |
static ThreadGroup |
getThreadGroup() |
static Timer |
getTimer()
Returns a shared timer provided by the agent server.
|
static Transaction |
getTransaction()
Returns the agent server transaction context.
|
static void |
init(short sid,
String path,
boolean update,
LoggingFactory loggerFactory) |
static void |
init(short sid,
String path,
LoggingFactory loggerFactory)
Initializes this agent server.
|
static int |
init(String[] args)
Parses agent server arguments, then initializes this agent server.
|
static void |
initServerDesc(ServerDesc desc,
A3CMLServer server) |
private static void |
initServices(A3CMLServer server,
ServerDesc desc) |
static boolean |
isAgentProfiling()
Returns true if the agent profiling is on.
|
static boolean |
isEngineThread() |
static void |
main(String[] args)
Main for a standard agent server.
|
static void |
registerCheckServerListener(CheckServerListener listener) |
static void |
removeConsumer(String domain) |
static ServerDesc |
removeServerDesc(short sid) |
static void |
reset()
Cleans an AgentServer configuration in order to restart it from
persistent storage.
|
static void |
reset(boolean force) |
static void |
resetEngineAverageLoad() |
static void |
restoreServer(String fname)
Restores the server persistence from a backup file.
|
static void |
setAgentProfiling(boolean agentProfiling)
Sets the agent profiling.
|
static void |
setConfig(A3CMLConfig a3config)
Set the agent server configuration.
|
static void |
setConfig(A3CMLConfig a3config,
boolean force) |
static void |
setDefaultConfig(int sid)
Set default configuration for the specified server.
|
static void |
setDefaultConfig(int sid,
String host,
String adminuid,
String adminpwd,
int joram,
int jndi)
Set default configuration for the specified server.
|
static void |
setDefaultConfig(int sid,
String host,
String adminuid,
String adminpwd,
int joram,
int jndi,
Properties props)
Set default configuration for the specified server.
|
static void |
setDefaultConfig(String config) |
private static void |
setProperties(short sid) |
(package private) static void |
shutdown() |
static String |
start()
Causes this AgentServer to begin its execution.
|
static void |
stop()
Forces this AgentServer to stop executing.
|
static void |
stop(boolean sync)
Forces this AgentServer to stop executing.
|
static void |
stop(boolean sync,
long delay,
boolean reset)
Forces this AgentServer to stop executing.
|
static void |
unregisterCheckServerListener(CheckServerListener listener) |
(package private) static int |
updateConf(A3CMLConfig a3cmlConfig,
String serverDataDirPath)
Updates the stored configuration
|
static int |
updateConfFromFile(String serverConfigFilePath,
String serverDataDirPath)
Updates the stored configuration from a file
|
static int |
updateConfFromString(String serverConfig,
String serverDataDirPath)
Updates the stored configuration from a String
|
private static Logger logmon
public static final short NULL_ID
public static final String ADMIN_DOMAIN
public static final String ADMIN_SERVER
public static final int ENCODABLE_CLASS_ID_AREA
public static final int MESSAGE_CLASS_ID
public static final String UPDATE_CONF_TX_NAME
public static final String BACKUP_FILE
public static final String DEFAULT_BACKUP_FILE
public static ServerUpdate updatecfg
public static String defaultConfig
public static final String CFG_ADMINUID_PROPERTY
Be careful, this configuration is normally used only for the initial starting of the server, the configuration is then atomically maintained in the persistence directory.
This property can only be fixed from java
launching command.
public static final String CFG_ADMINPWD_PROPERTY
Be careful, this configuration is normally used only for the initial starting of the server, the configuration is then atomically maintained in the persistence directory.
This property can only be fixed from java
launching command.
public static final String CFG_JMS_PORT_PROPERTY
Be careful, this configuration is normally used only for the initial starting of the server, the configuration is then atomically maintained in the persistence directory.
This property can only be fixed from java
launching command.
public static final int CFG_JMS_PORT_DFLT
public static final String CFG_MIN_JORAM_PORT_PROPERTY
This property can only be fixed from java
launching command.
public static final int CFG_MIN_JORAM_PORT_DFLT
public static final String CFG_MAX_JORAM_PORT_PROPERTY
This property can only be fixed from java
launching command.
public static final int CFG_MAX_JORAM_PORT_DFLT
public static final String CFG_JNDI_PORT_PROPERTY
Be careful, this configuration is normally used only for the initial starting of the server, the configuration is then atomically maintained in the persistence directory.
This property can only be fixed from java
launching command.
public static final int CFG_JNDI_PORT_DFLT
private static short serverId
public static org.osgi.framework.BundleContext context
public static final String CFG_DIR_PROPERTY
Be careful, the XML server configuration file is normally used only for the initial starting of the server, the configuration is then atomically maintained in the persistence directory.
This property can only be fixed from java
launching command.
public static final String DEFAULT_CFG_DIR
public static final String CFG_FILE_PROPERTY
Be careful, the XML server configuration file is normally used only for the initial starting of the server, the configuration is then atomically maintained in the persistence directory.
This property can only be fixed from java
launching command.
public static final String DEFAULT_CFG_FILE
a3servers.xml
.public static final String USE_DEFAULT_CONFIG_PROPERTY
public static final String DEFAULT_USE_DEFAULT_CONFIG
public static final String DEFAULT_SER_CFG_FILE
a3cmlconfig
.
Removing this file allows to load anew the XML configuration file at the next starting of the server. Be careful, doing this can generate incoherence in the global configuration.
public static final String CFG_NAME_PROPERTY
public static final String DEFAULT_CFG_NAME
public static final String A3CMLWRP_PROPERTY
This property can only be fixed from java
launching command.
public static final String DEFAULT_A3CMLWRP
public static final String CFG_CHECK_PERIOD_PROPERTY
This property can be fixed either from XML configuration file or Java launching command.
static CheckServerTask checkServerTask
static ThreadGroup tgroup
static AgentEngine engine
Channel.sendTo
to
know if the method is called from a react or no.static Transaction transaction
private static Hashtable<String,MessageConsumer> consumers
Engine
).private static Timer timer
private static A3CMLConfig a3config
private static String name
private static ServersHT servers
private static AgentServer.Status status
private static AgentServer.ServerLock lock
public static final long startDate
public static final String CFG_EXIT_ON_SERVICE_FAILURE_PROPERTY
This property can be fixed either from XML configuration file or Java launching command.
public static final String OKSTRING
public static final String ERRORSTRING
public static final String ENDSTRING
public static void setDefaultConfig(int sid)
sid
- the server identifier.public static void setDefaultConfig(int sid, String host, String adminuid, String adminpwd, int joram, int jndi)
sid
- the server identifier.host
- the hostname (or IP adress) hosting the severadminuid
- the administration loginadminpwd
- the administration passwordjoram
- the JMS TCP connector portjndi
- the JNDI TCP portpublic static void setDefaultConfig(int sid, String host, String adminuid, String adminpwd, int joram, int jndi, Properties props)
sid
- Unique identifier of the server.host
- Host name or IP address of the physical machine.adminuid
- User name of the administrator.adminpwd
- Password of the administrator.joram
- Listen port for JMS connector. If set to 0 the listen port is first searched
through the CFG_JMS_PORT_PROPERTY property, then set to default value if not
defined. If less than 0..jndi
- Listen port for JNDI connector. If set to 0 the listen port is first searched
through the CFG_NDI_PORT_PROPERTY property, then set to default value if not
defined. If less than 0 the Joram/JNDI service is not started.props
- Set of properties to define in the built configuration.public static void setDefaultConfig(String config)
static void shutdown()
public static void registerCheckServerListener(CheckServerListener listener)
public static void unregisterCheckServerListener(CheckServerListener listener)
public static ThreadGroup getThreadGroup()
public static AgentEngine getEngine()
public static boolean isEngineThread()
public static void resetEngineAverageLoad()
public static float getEngineAverageLoad1()
public static float getEngineAverageLoad5()
public static float getEngineAverageLoad15()
public static int getEngineLoad()
public static boolean isAgentProfiling()
public static void setAgentProfiling(boolean agentProfiling)
agentProfiling
- true to turn on agent profiling.public static long getReactTime()
public static long getCommitTime()
public static Transaction getTransaction()
public static void addConsumer(String domain, MessageConsumer cons) throws Exception
Exception
static Enumeration<MessageConsumer> getConsumers()
public static MessageConsumer getConsumer(String domain) throws Exception
Exception
public static void removeConsumer(String domain)
public static final Timer getTimer()
public static final void setConfig(A3CMLConfig a3config) throws Exception
a3config
- A3CMLConfigException
- Server is already initialized.public static final void setConfig(A3CMLConfig a3config, boolean force) throws Exception
Exception
public static final A3CMLConfig getConfig() throws Exception
Exception
- an error occurs.public static A3CMLConfig getAppConfig(String[] domains) throws Exception
A3CMLConfig
object.domains
- list of domain's namesA3CMLConfig
object.Exception
- an error occurs.public static final short getServerId()
public static final String getName()
public static final String getServerName()
public static short getServerIdByName(String name) throws Exception
name
- the name of the agent serverException
- if the server name is unknown.public static String getProperty(String key)
key
- the hashtable key.public static String getProperty(String key, String value)
key
- the hashtable key.value
- a default value.public static Integer getInteger(String key)
key
- property name.public static Integer getInteger(String key, int value)
key
- property name.value
- a default value.public static Long getLong(String key)
key
- property name.public static Long getLong(String key, long value)
key
- property name.value
- a default value.public static boolean getBoolean(String key)
key
- property name.public static void addServerDesc(ServerDesc desc) throws Exception
Exception
public static ServerDesc removeServerDesc(short sid) throws Exception
Exception
public static Enumeration<ServerDesc> elementsServerDesc()
public static Enumeration<Short> getServersIds()
static final int getServerNb()
public static final ServerDesc getServerDesc(short sid) throws UnknownServerException
sid
- agent server id.UnknownServerException
- the server is not defined.static final MessageConsumer getConsumer(short sid) throws UnknownServerException
sid
- agent server id.UnknownServerException
- the server is not defined.public static final String getHostname(short sid) throws UnknownServerException
sid
- agent server idUnknownServerException
- the server is not defined.static final ServiceDesc[] getServices() throws UnknownServerException
UnknownServerException
- the server is not defined.public static final String getServiceArgs(short sid, String classname) throws Exception
sid
- agent server idclassname
- the service class nameUnknownServerException
- The specified server does not exist.UnknownServiceException
- The specified service is not declared on this server.Exception
- Probably there is no configuration defined.A3CMLConfig.getServiceArgs(short,String)
public static final String getServiceArgs(String hostname, String classname) throws Exception
hostname
- hostnameclassname
- the service class nameUnknownServiceException
- The specified service is not declared on this server.Exception
- Probably there is no configuration defined.A3CMLConfig.getServiceArgs(String, String)
private static void configure() throws Exception
AgentServer
structures from
the A3CMLConfig
ones. In particular the servers array is
initialized.Exception
- an error occurs.private static void createConsumers(A3CMLServer root) throws Exception
Exception
public static void initServerDesc(ServerDesc desc, A3CMLServer server) throws Exception
Exception
private static ServerDesc createServerDesc(A3CMLServer server) throws Exception
Exception
private static void initServices(A3CMLServer server, ServerDesc desc) throws Exception
Exception
public static int getStatus()
public static String getStatusInfo()
public static int init(String[] args) throws Exception
start
function is then called to start this agent server
execution. Between the init
and start
calls,
agents may be created and deployed, and notifications may be sent using
the Channel
sendTo
function.args
- launching arguments, the first one is the server id
and the second one the persistency directory.Exception
- unspecialized exceptionpublic static void reset(boolean force)
public static void reset()
public static int externalUpdateConfFromFile(String serverConfigFilePath, String serverDataDirPath) throws Exception
serverConfigFilePath
- pathname of file containing the XML configuration.serverDataDirPath
- pathname of the persistence repository to update.Exception
- an error occurred during updatepublic static int externalUpdateConfFromString(String serverConfig, String serverDataDirPath) throws Exception
serverConfig
- the XML configuration.serverDataDirPath
- pathname of the persistence repository to update.Exception
- an error occurred during updatepublic static int updateConfFromFile(String serverConfigFilePath, String serverDataDirPath) throws Exception
serverConfigFilePath
- pathname of file containing the server configuration.serverDataDirPath
- pathname of the persistence repository to update.Exception
- an error occurred during updatepublic static int updateConfFromString(String serverConfig, String serverDataDirPath) throws Exception
serverConfig
- the XML configuration.serverDataDirPath
- pathname of the persistence repository to update.Exception
- an error occurred during updatestatic int updateConf(A3CMLConfig a3cmlConfig, String serverDataDirPath) throws Exception
a3cmlConfig
- the configuration up-to-date.serverDataDirPath
- pathname of the persistence repository to update.Exception
- an error occurred during updatepublic static void restoreServer(String fname) throws IOException
backupFile
- The path of backup file.IOException
- An error occurs.public static void init(short sid, String path, LoggingFactory loggerFactory) throws Exception
start
function is then called to start this agent server
execution. Between the init
and start
calls,
agents may be created and deployed, and notifications may be sent using
the Channel
sendTo
function.sid
- the server idpath
- the persistency directory.loggerFactory
- the monolog LoggerFactory;Exception
- unspecialized exceptionpublic static void init(short sid, String path, boolean update, LoggingFactory loggerFactory) throws Exception
sid
- the server idpath
- the persistency directory.update
- If true updates persistence from configurationloggerFactory
- the monolog LoggerFactory;Exception
- unspecialized exceptionpublic static String start() throws Exception
MessageConsumer
(i.e. the engine and the network components).Exception
- an error occurs.public static void stop(boolean sync)
sync
- If true the stop is processed synchronously, otherwise
a thread is created and the method returns.public static void stop(boolean sync, long delay, boolean reset)
sync
- If true the stop is processed synchronously, otherwise
a thread is created and the method returns.delay
- if sync is false then the thread in charge of
stopping the server waits this delay before
initiating the stop.reset
- If true the server is stopped then reseted.public static void stop()
public static void main(String[] args) throws Exception
args
- start argumentsException
- unspecialized exceptionCopyright © 2023 ScalAgent D.T.. All rights reserved.