if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
"ServerConfigHelper.addDomain(" + domainName + ',' + network + ',' + routerId + ',' + port + ')');
// Check configuration consistency (may fail)
A3CMLConfig a3cmlConfig = AgentServer.getConfig();
if (a3cmlConfig.domains.get(domainName) != null)
throw new NameAlreadyUsedException("Domain name already used: " + domainName);
if (a3cmlConfig.servers.get(new Short((short)routerId)) == null)
throw new Exception("Server not found: " + routerId);
// Update the configuration (can't fail)
A3CMLDomain domain = new A3CMLDomain(domainName, network);
a3cmlConfig.addDomain(domain);
A3CMLServer a3cmlServer = a3cmlConfig.getServer((short) routerId);
domain.addServer(a3cmlServer);
A3CMLNetwork a3cmlNetwork = new A3CMLNetwork(domainName, port);
a3cmlServer.addNetwork(a3cmlNetwork);
A3CMLServer root = a3cmlConfig.getServer(AgentServer.getServerId());
a3cmlConfig.configure(root);
boolean res = false;
if (routerId == AgentServer.getServerId()) {
// Create and start the run-time entities (may fail)
Network net = (Network) Class.forName(network).newInstance();
// GS: Network name is set earlier than normal to have a well formed name
// for the MBean in addConsumer method.
net.name = AgentServer.getName() + '.' + domainName;
AgentServer.addConsumer(domainName, net);
try {
short[] sids = new short[1];
sids[0] = (short) routerId;
net.init(domainName, port, sids);
net.start();
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "", exc);
// Rollback the network addition
AgentServer.removeConsumer(domainName);
a3cmlServer.removeNetwork(domainName);
a3cmlConfig.removeDomain(domainName);
a3cmlConfig.configure(root);
throw new StartFailureException(exc.getMessage());
}
res = true;