* it uses that server to create a context. Otherwise, it creates a new
* HTTP server. This sever is added to servers Map.
*/
/*package*/ HttpContext createContext(String address) {
try {
HttpServer server;
ServerState state;
URL url = new URL(address);
int port = url.getPort();
if (port == -1) {
port = url.getDefaultPort();
}
InetSocketAddress inetAddress = new InetSocketAddress(url.getHost(),
port);
synchronized(servers) {
state = servers.get(inetAddress);
if (state == null) {
logger.fine("Creating new HTTP Server at "+inetAddress);
server = HttpServer.create(inetAddress, 5);
server.setExecutor(Executors.newCachedThreadPool());
String path = url.toURI().getPath();
logger.fine("Creating HTTP Context at = "+path);
HttpContext context = server.createContext(path);
server.start();
logger.fine("HTTP server started = "+inetAddress);
state = new ServerState(server);
servers.put(inetAddress, state);
return context;
}
}
server = state.getServer();
logger.fine("Creating HTTP Context at = "+url.getPath());
HttpContext context = server.createContext(url.getPath());
state.oneMoreContext();
return context;
} catch(Exception e) {
throw new ServerRtException("server.rt.err",e );
}