try {
// Install the Security manager
System.setSecurityManager(new ServiceSecurityManager());
// Create the ClassLoader that we'll use to load Service classes.
// The classes should be stored in (or beneath) the directory specified
// as the first command-line argument
LocalClassLoader loader = new LocalClassLoader(args[0]);
// Create a Server object that does no logging and
// has a limit of five concurrent connections at once.
Server server = new Server(null, 5);
// Parse the argument list, which should contain Service name/port pairs.
// For each pair, load the named Service using the class loader, then
// instantiate it with newInstance(), then tell the server to start
// running it.
int i = 1;
while(i < args.length) {
Class serviceClass = loader.loadClass(args[i++]); // dynamic load
Service service = (Service)serviceClass.newInstance(); // instantiate
int port = Integer.parseInt(args[i++]); // get port
server.addService(service, port); // run service
}
}
catch (Exception e) { // Display a message if anything goes wrong
System.err.println(e);
System.err.println("Usage: java SafeServer " +
"<servicedir> <servicename> <port>\n" +
"\t\t[<servicename> <port> ... ]");
System.exit(1);
}