fr.dyade.aaa.agent
Class AgentServer

java.lang.Object
  extended by fr.dyade.aaa.agent.AgentServer

public final class AgentServer
extends java.lang.Object

The AgentServer class manages the global configuration of an agent server. It reads the configuration file, then it creates and configure Engine, Channel, Networks. 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.


To start the agents server an XML configuration file describing the architecture of the agent platform is needed. By default, this file is the a3servers.xml file and it should be located inside the running directory where the server is launched. Each server must use the same configuration file.

The configuration file contains a config element, that is essentially made up of domains elements, and servers (servers elements):

Each server that is part of two domains is named a "router", be careful, it should have only one route between two domains. If it is not true the configuration failed.


A simple example of a3servers.xml follows:

 <?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:

At the beginning of the file, there is a global property that defines the maximum number of connection handled by each server of domain D2.

See Also:
Engine, Channel, Network, MessageQueue, Transaction

Nested Class Summary
(package private) static class AgentServer.ServerStopper
           
static class AgentServer.Status
           
 
Field Summary
static java.lang.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 java.lang.String ADMIN_DOMAIN
           
static java.lang.String ADMIN_SERVER
           
static java.lang.String CFG_DIR_PROPERTY
          Name of property allowing to configure the directory to search the XML server configuration.
static java.lang.String CFG_FILE_PROPERTY
          Name of property allowing to configure the filename of the XML server configuration.
static java.lang.String CFG_NAME_PROPERTY
           
private static short clusterId
           
private static java.util.Hashtable consumers
          Static references to all messages consumers initialized in this agent server (including Engine).
static java.lang.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 java.lang.String DEFAULT_CFG_DIR
          Default value of the directory to search the XML server configuration, value is null.
static java.lang.String DEFAULT_CFG_FILE
          Default value of the filename of the XML server configuration, value is a3servers.xml.
static java.lang.String DEFAULT_CFG_NAME
           
static java.lang.String DEFAULT_SER_CFG_FILE
          Default value of the filename of the serialized server configuration in the persistence directory, value is a3cmlconfig.
static java.lang.String ENDSTRING
           
(package private) static Engine engine
          Static reference to the engine.
static java.lang.String ERRORSTRING
           
private static MonitoringTimerTask fileMonitoringTimerTask
          Task for file monitoring if configured.
private static JGroups jgroups
           
private static org.objectweb.util.monolog.api.Logger logmon
           
private static MonitoringTimerTask logMonitoringTimerTask
          Task for log monitoring if configured.
private static java.lang.String name
           
static short NULL_ID
           
static java.lang.String OKSTRING
           
private static short serverId
           
private static ServersHT servers
          Static description of all known agent servers in ascending order.
private static AgentServer.Status status
           
(package private) static java.lang.ThreadGroup tgroup
           
private static java.util.Timer timer
          Timer provided by the agent server.
(package private) static Transaction transaction
          Static reference to the transactional monitor.
 
Constructor Summary
AgentServer()
           
 
Method Summary
static void addConsumer(java.lang.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 java.util.Enumeration elementsServerDesc()
           
static A3CMLConfig getAppConfig(java.lang.String[] domains)
          Gets configuration of agent servers for a domain from the current A3CMLConfig object.
static boolean getBoolean(java.lang.String key)
          Determines the boolean value of the server property with the specified name.
static short getClusterId()
           
static A3CMLConfig getConfig()
          Returns the agent server configuration.
(package private) static MessageConsumer getConsumer(short sid)
          Gets the message consumer for the corresponding server.
(package private) static MessageConsumer getConsumer(java.lang.String domain)
           
(package private) static java.util.Enumeration getConsumers()
           
static Engine 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 java.lang.String getHostname(short sid)
          Get the host name of an agent server.
static java.lang.Integer getInteger(java.lang.String key)
          Determines the integer value of the server property with the specified name.
static java.lang.Integer getInteger(java.lang.String key, int value)
          Determines the integer value of the server property with the specified name.
static java.lang.Long getLong(java.lang.String key)
          Determines the integer value of the server property with the specified name.
static java.lang.Long getLong(java.lang.String key, long value)
          Determines the long value of the server property with the specified name.
static java.lang.String getName()
           
static java.lang.String getProperty(java.lang.String key)
          Searches for the property with the specified key in the server property list.
static java.lang.String getProperty(java.lang.String key, java.lang.String value)
          Searches for the property with the specified key in the server property list.
static ServerDesc getServerDesc(short sid)
          Gets the characteristics of the corresponding server.
static short getServerId()
           
static short getServerIdByName(java.lang.String name)
          Returns the identifier of the agent server which name is specified.
static java.lang.String getServerName()
           
(package private) static int getServerNb()
          Gets the number of server known on the current server.
static java.util.Enumeration getServersIds()
           
static java.lang.String getServiceArgs(short sid, java.lang.String classname)
          Get the argument strings for a particular service.
static java.lang.String getServiceArgs(java.lang.String hostname, java.lang.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 java.lang.String getStatusInfo()
           
static java.lang.ThreadGroup getThreadGroup()
           
static java.util.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, java.lang.String path, org.objectweb.util.monolog.api.LoggerFactory loggerFactory)
          Initializes this agent server.
static void init(short sid, java.lang.String path, org.objectweb.util.monolog.api.LoggerFactory loggerFactory, short cid)
          Initializes this agent server.
static int init(java.lang.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 isHAServer()
          Test HA server.
static boolean isMasterHAServer()
          Test if the server is a master (coordinator).
static void main(java.lang.String[] args)
          Main for a standard agent server.
(package private) static void removeConsumer(java.lang.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 setConfig(A3CMLConfig a3config)
          Set the agent server configuration.
static void setConfig(A3CMLConfig a3config, boolean force)
           
private static void setProperties(short sid, short cid)
           
static java.lang.String start()
          Causes this AgentServer to begin its execution.
(package private) static java.lang.String startConsumers()
           
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_ID

public static final short NULL_ID
See Also:
Constant Field Values

ADMIN_DOMAIN

public static final java.lang.String ADMIN_DOMAIN
See Also:
Constant Field Values

ADMIN_SERVER

public static final java.lang.String ADMIN_SERVER
See Also:
Constant Field Values

serverId

private static short serverId

logmon

private static org.objectweb.util.monolog.api.Logger logmon

CFG_DIR_PROPERTY

public static final java.lang.String CFG_DIR_PROPERTY
Name of property allowing to configure the directory to search the XML server configuration.

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 either from java launching command.

See Also:
Constant Field Values

DEFAULT_CFG_DIR

public static final java.lang.String DEFAULT_CFG_DIR
Default value of the directory to search the XML server configuration, value is null.


CFG_FILE_PROPERTY

public static final java.lang.String CFG_FILE_PROPERTY
Name of property allowing to configure the filename of the XML server configuration.

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 either from java launching command.

See Also:
Constant Field Values

DEFAULT_CFG_FILE

public static final java.lang.String DEFAULT_CFG_FILE
Default value of the filename of the XML server configuration, value is a3servers.xml.

See Also:
Constant Field Values

DEFAULT_SER_CFG_FILE

public static final java.lang.String DEFAULT_SER_CFG_FILE
Default value of the filename of the serialized server configuration in the persistence directory, value is 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.

See Also:
Constant Field Values

CFG_NAME_PROPERTY

public static final java.lang.String CFG_NAME_PROPERTY
See Also:
Constant Field Values

DEFAULT_CFG_NAME

public static final java.lang.String DEFAULT_CFG_NAME
See Also:
Constant Field Values

A3CMLWRP_PROPERTY

public static final java.lang.String A3CMLWRP_PROPERTY
Name of property allowing to configure the XML wrapper used to read the server configuration.

This property can only be fixed either from java launching command.

See Also:
Constant Field Values

DEFAULT_A3CMLWRP

public static final java.lang.String DEFAULT_A3CMLWRP
Default value of the XML wrapper used to read server configuration, this default value implies the use of the default SaxWrapper.

See Also:
Constant Field Values

fileMonitoringTimerTask

private static MonitoringTimerTask fileMonitoringTimerTask
Task for file monitoring if configured.


logMonitoringTimerTask

private static MonitoringTimerTask logMonitoringTimerTask
Task for log monitoring if configured.


tgroup

static java.lang.ThreadGroup tgroup

engine

static Engine engine
Static reference to the engine. Used in Channel.sendTo to know if the method is called from a react or no.


AF: I think we must suppress this dependency in order to be able to run multiples engine.


transaction

static Transaction transaction
Static reference to the transactional monitor.


jgroups

private static JGroups jgroups

clusterId

private static short clusterId

consumers

private static java.util.Hashtable consumers
Static references to all messages consumers initialized in this agent server (including Engine).


timer

private static java.util.Timer timer
Timer provided by the agent server.


a3config

private static A3CMLConfig a3config
Static reference to the configuration.


name

private static java.lang.String name

servers

private static ServersHT servers
Static description of all known agent servers in ascending order.


status

private static AgentServer.Status status

OKSTRING

public static final java.lang.String OKSTRING
See Also:
Constant Field Values

ERRORSTRING

public static final java.lang.String ERRORSTRING
See Also:
Constant Field Values

ENDSTRING

public static final java.lang.String ENDSTRING
See Also:
Constant Field Values
Constructor Detail

AgentServer

public AgentServer()
Method Detail

getThreadGroup

public static java.lang.ThreadGroup getThreadGroup()

getEngine

public static Engine getEngine()
Returns the agent server engine.


getEngineAverageLoad1

public static float getEngineAverageLoad1()
Returns the load averages for the last minute.

Returns:
the load averages for the last minute.

getEngineAverageLoad5

public static float getEngineAverageLoad5()
Returns the load averages for the past 5 minutes.

Returns:
the load averages for the past 5 minutes.

getEngineAverageLoad15

public static float getEngineAverageLoad15()
Returns the load averages for the past 15 minutes.

Returns:
the load averages for the past 15 minutes.

getTransaction

public static Transaction getTransaction()
Returns the agent server transaction context.


isHAServer

public static boolean isHAServer()
Test HA server.

Returns:
true if the server is HA.

isMasterHAServer

public static boolean isMasterHAServer()
Test if the server is a master (coordinator).

Returns:
true if the server HA is a master.

addConsumer

public static void addConsumer(java.lang.String domain,
                               MessageConsumer cons)
                        throws java.lang.Exception
Throws:
java.lang.Exception

getConsumers

static java.util.Enumeration getConsumers()

getConsumer

static MessageConsumer getConsumer(java.lang.String domain)
                            throws java.lang.Exception
Throws:
java.lang.Exception

removeConsumer

static void removeConsumer(java.lang.String domain)

getTimer

public static final java.util.Timer getTimer()
Returns a shared timer provided by the agent server.


setConfig

public static final void setConfig(A3CMLConfig a3config)
                            throws java.lang.Exception
Set the agent server configuration. Be careful, this method cannot be called after initialization.

Parameters:
a3config - A3CMLConfig
Throws:
java.lang.Exception - Server is already initialized.

setConfig

public static final void setConfig(A3CMLConfig a3config,
                                   boolean force)
                            throws java.lang.Exception
Throws:
java.lang.Exception

getConfig

public static final A3CMLConfig getConfig()
                                   throws java.lang.Exception
Returns the agent server configuration.

Returns:
agent server configuration (A3CMLConfig)
Throws:
java.lang.Exception

getAppConfig

public static A3CMLConfig getAppConfig(java.lang.String[] domains)
                                throws java.lang.Exception
Gets configuration of agent servers for a domain from the current A3CMLConfig object. This method fills the object graph configuration in a A3CMLConfig object.

Parameters:
domains - list of domain's names
Returns:
a A3CMLConfig object.
Throws:
java.lang.Exception

getServerId

public static final short getServerId()

getClusterId

public static final short getClusterId()

getName

public static final java.lang.String getName()

getServerName

public static final java.lang.String getServerName()

getServerIdByName

public static short getServerIdByName(java.lang.String name)
                               throws java.lang.Exception
Returns the identifier of the agent server which name is specified.

Parameters:
name - the name of the agent server
Returns:
the identifier of the agent server
Throws:
java.lang.Exception - if the server name is unknown.

getProperty

public static java.lang.String getProperty(java.lang.String key)
Searches for the property with the specified key in the server property list.

Parameters:
key - the hashtable key.
Returns:
the value with the specified key value.

getProperty

public static java.lang.String getProperty(java.lang.String key,
                                           java.lang.String value)
Searches for the property with the specified key in the server property list.

Parameters:
key - the hashtable key.
value - a default value.
Returns:
the value with the specified key value.

getInteger

public static java.lang.Integer getInteger(java.lang.String key)
Determines the integer value of the server property with the specified name.

Parameters:
key - property name.
Returns:
the Integer value of the property.

getInteger

public static java.lang.Integer getInteger(java.lang.String key,
                                           int value)
Determines the integer value of the server property with the specified name.

Parameters:
key - property name.
value - a default value.
Returns:
the Integer value of the property.

getLong

public static java.lang.Long getLong(java.lang.String key)
Determines the integer value of the server property with the specified name.

Parameters:
key - property name.
Returns:
the Integer value of the property.

getLong

public static java.lang.Long getLong(java.lang.String key,
                                     long value)
Determines the long value of the server property with the specified name.

Parameters:
key - property name.
value - a default value.
Returns:
the Integer value of the property.

getBoolean

public static boolean getBoolean(java.lang.String key)
Determines the boolean value of the server property with the specified name.

Parameters:
key - property name.
value - a default value.
Returns:
the boolean value of the property.

addServerDesc

public static void addServerDesc(ServerDesc desc)
                          throws java.lang.Exception
Throws:
java.lang.Exception

removeServerDesc

public static ServerDesc removeServerDesc(short sid)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

elementsServerDesc

public static java.util.Enumeration elementsServerDesc()

getServersIds

public static java.util.Enumeration getServersIds()

getServerNb

static final int getServerNb()
Gets the number of server known on the current server.

Returns:
the number of server.

getServerDesc

public static final ServerDesc getServerDesc(short sid)
                                      throws UnknownServerException
Gets the characteristics of the corresponding server.

Parameters:
sid - agent server id.
Returns:
the server's descriptor.
Throws:
UnknownServerException

getConsumer

static final MessageConsumer getConsumer(short sid)
                                  throws UnknownServerException
Gets the message consumer for the corresponding server.

Parameters:
sid - agent server id.
Returns:
the corresponding message consumer.
Throws:
UnknownServerException

getHostname

public static final java.lang.String getHostname(short sid)
                                          throws UnknownServerException
Get the host name of an agent server.

Parameters:
sid - agent server id
Returns:
server host name as declared in configuration file
Throws:
UnknownServerException

getServices

static final ServiceDesc[] getServices()
                                throws UnknownServerException
Get the description of all services of the current agent server.

Returns:
server host name as declared in configuration file
Throws:
UnknownServerException

getServiceArgs

public static final java.lang.String getServiceArgs(short sid,
                                                    java.lang.String classname)
                                             throws java.lang.Exception
Get the argument strings for a particular service. The information provides from the A3 configuration file, so it's only available if this file contains service's informations for all nodes.

Parameters:
sid - agent server id
classname - the service class name
Returns:
the arguments as declared in configuration file
Throws:
UnknownServerException - The specified server does not exist.
UnknownServiceException - The specified service is not declared on this server.
java.lang.Exception - Probably there is no configuration defined.
See Also:
A3CMLConfig.getServiceArgs(short,String)

getServiceArgs

public static final java.lang.String getServiceArgs(java.lang.String hostname,
                                                    java.lang.String classname)
                                             throws java.lang.Exception
Get the argument strings for a particular service running on a server identified by its host. The information provides from the A3 configuration file, so it's only available if this file contains service's informations for all nodes.

Parameters:
hostname - hostname
classname - the service class name
Returns:
the arguments as declared in configuration file
Throws:
UnknownServiceException - The specified service is not declared on this server.
java.lang.Exception - Probably there is no configuration defined.
See Also:
A3CMLConfig.getServiceArgs(String, String)

configure

private static void configure()
                       throws java.lang.Exception
The second step of initialization. It needs the Transaction component be up, then it initializes all AgentServer structures from the A3CMLConfig ones. In particular the servers array is initialized.

Throws:
java.lang.Exception

createConsumers

private static void createConsumers(A3CMLServer root)
                             throws java.lang.Exception
Throws:
java.lang.Exception

initServerDesc

public static void initServerDesc(ServerDesc desc,
                                  A3CMLServer server)
                           throws java.lang.Exception
Throws:
java.lang.Exception

createServerDesc

private static ServerDesc createServerDesc(A3CMLServer server)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

initServices

private static void initServices(A3CMLServer server,
                                 ServerDesc desc)

setProperties

private static void setProperties(short sid,
                                  short cid)
                           throws java.lang.Exception
Throws:
java.lang.Exception

getStatus

public static int getStatus()

getStatusInfo

public static java.lang.String getStatusInfo()

init

public static int init(java.lang.String[] args)
                throws java.lang.Exception
Parses agent server arguments, then initializes this agent server. The 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.

Parameters:
args - launching arguments, the first one is the server id and the second one the persistency directory.
Returns:
number of arguments consumed in args
Throws:
java.lang.Exception - unspecialized exception

reset

public static void reset(boolean force)

reset

public static void reset()
Cleans an AgentServer configuration in order to restart it from persistent storage.


init

public static void init(short sid,
                        java.lang.String path,
                        org.objectweb.util.monolog.api.LoggerFactory loggerFactory)
                 throws java.lang.Exception
Initializes this agent server. 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.

Parameters:
sid - the server id
path - the persistency directory.
loggerFactory - the monolog LoggerFactory;
Throws:
java.lang.Exception - unspecialized exception

init

public static void init(short sid,
                        java.lang.String path,
                        org.objectweb.util.monolog.api.LoggerFactory loggerFactory,
                        short cid)
                 throws java.lang.Exception
Initializes this agent server. 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.

Parameters:
sid - the server id
path - the persistency directory.
loggerFactory - the monolog LoggerFactory;
cid - the cluster id
Throws:
java.lang.Exception - unspecialized exception

startConsumers

static java.lang.String startConsumers()
                                throws java.lang.Exception
Throws:
java.lang.Exception

start

public static java.lang.String start()
                              throws java.lang.Exception
Causes this AgentServer to begin its execution. This method starts all MessageConsumer (i.e. the engine and the network components).

Throws:
java.lang.Exception

stop

public static void stop(boolean sync)
Forces this AgentServer to stop executing. This method stops all consumers and services. Be careful, if you specify a synchronous process, this method wait for all server's thread to terminate; so if this method is called from a server's thread it should result a dead-lock.

Parameters:
sync - If true the stop is processed synchronously, otherwise a thread is created and the method returns.

stop

public static void stop(boolean sync,
                        long delay,
                        boolean reset)
Forces this AgentServer to stop executing. This method stops all consumers and services. Be careful, if you specify a synchronous process, this method wait for all server's thread to terminate; so if this method is called from a server's thread it should result a dead-lock.

Parameters:
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.

stop

public static void stop()
Forces this AgentServer to stop executing. This method stops all consumers and services. Be careful, the stop process is now synchronous and wait for all server's thread to terminate ; If this method is called from a server's thread it should result a dead-lock.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Main for a standard agent server. The start arguments include in first position the identifier of the agent server to start, and in second position the directory name where the agent server stores its persistent data.

Parameters:
args - start arguments
Throws:
java.lang.Exception - unspecialized exception


Copyright © 2010 ScalAgent D.T.. All Rights Reserved.