/**
* Adapts the current configuration to the specified persistent server.
*/
public void configure(A3CMLServer root) throws Exception {
short rootid = root.sid;
Vector toExplore = new Vector();
// Temporary fix, reset visited and gateway fields
reset();
// Search alls directly accessible domains.
for (Enumeration n = root.networks.elements(); n.hasMoreElements();) {
A3CMLNetwork network = (A3CMLNetwork) n.nextElement();
A3CMLDomain domain = (A3CMLDomain) domains.get(network.domain);
domain.gateway = rootid;
domain.hops = 1;
toExplore.addElement(domain);
Log.logger.log(BasicLevel.DEBUG,
"configure - toExplore.add(" + domain + ")");
}
root.visited = true;
root.gateway = -1;
root.hops = 0;
root.domain = "local";
while (toExplore.size() > 0) {
A3CMLDomain domain = (A3CMLDomain) toExplore.elementAt(0);
toExplore.removeElementAt(0);
A3CMLServer gateway = (A3CMLServer) servers.get(new Short(domain.gateway));
if (Log.logger.isLoggable(BasicLevel.DEBUG))
Log.logger.log(BasicLevel.DEBUG, "configure - explore(" + domain + ")");
// Parse all nodes of this domain
for (Enumeration s = domain.servers.elements();
s.hasMoreElements();) {
A3CMLServer server = (A3CMLServer) s.nextElement();
if (server.visited) continue;
if (Log.logger.isLoggable(BasicLevel.DEBUG))
Log.logger.log(BasicLevel.DEBUG, "configure - explore(" + server + ")");
server.visited = true;
if (domain.gateway == rootid) {
// The server is directly accessible from root
server.gateway = -1;
server.domain = domain.name;
} else {
server.gateway = domain.gateway;
server.domain = gateway.domain;
}
server.hops = domain.hops;
// If the server is a router then add the accessible domains
// to the list.
for (Enumeration n = server.networks.elements();
n.hasMoreElements();) {
A3CMLNetwork network = (A3CMLNetwork) n.nextElement();
A3CMLDomain d2 = (A3CMLDomain) domains.get(network.domain);
if (Log.logger.isLoggable(BasicLevel.DEBUG))
Log.logger.log(BasicLevel.DEBUG, "configure - parse(" + d2 + ")");
if (d2 == domain) {
if (Log.logger.isLoggable(BasicLevel.DEBUG))
Log.logger.log(BasicLevel.DEBUG, "configure - setPort(" + network.port + ")");
// The server is directly accessible from root server by
// this network interface; fixes the communication port
// for this server.
// AF 03/11/2004 - It seems in fact the domain is the one we are
// exploring, so if the server is directly accessible its listen
// port is the one of this network...
server.port = network.port;
continue;
}
// If the domain is already explored then there is more
// than one route to this domain.
//if (d2.gateway != -1)
// throw new Exception("more than one route to: " + domain);
// if (d2.hops != -1)
// throw new Exception("more than one route to: " + domain);
d2.hops = domain.hops +1;
// The domain is not already explored.
if (server.gateway == -1)
d2.gateway = server.sid; // the server is directly accessible
else
d2.gateway = server.gateway; // the server itself is routed
toExplore.addElement(d2);
if (Log.logger.isLoggable(BasicLevel.DEBUG))
Log.logger.log(BasicLevel.DEBUG, "configure - toExplore.add(" + d2 + ")");
}
}