标签:
/* ------------------------------------------------------------ */
public HandlerCollection()
{
_mutableWhenRunning=false;
}
/* ------------------------------------------------------------ */
public HandlerCollection(boolean mutableWhenRunning)
{
_mutableWhenRunning=mutableWhenRunning;
private HandlerCollection handlers = new HandlerCollection(true);
List<Handler> handlerList = new LinkedList<>();
if (handlers.getHandlers() != null) {
for(Handler temp : handlers.getHandlers()) {
handlerList.add(temp);
}
}
MockHandler handler = new MockHandler(port, sysCode, mockDao);
handler.setServer(server);
handler.start();
handlerList.add(handler);
handlers.setHandlers(handlerList.toArray(new MockHandler[0]));
Connector connector = getConnector(port);
server.addConnector(connector);
connector.start();
private ServerConnector getConnector(int port) {
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
return connector;
}
for (Connector connector : server.getConnectors()) {
ServerConnector serverConnector = (ServerConnector) connector;
if (codePort == serverConnector.getPort()) {
connector.stop();
server.removeConnector(connector);
List<Handler> mockHandlers = new LinkedList<>();
for(Handler tempHandler : handlers.getHandlers()) {
MockHandler mockTempHandler = (MockHandler) tempHandler;
if (!mockTempHandler.getSysCode().equals(sysCode)) {
mockHandlers.add(tempHandler);
} else {
mockTempHandler.stop();
}
}
handlers.setHandlers(mockHandlers.toArray(new MockHandler[0]));
break;
} else {
continue;
}
}
@Override
public void destroy() throws Exception {
if (server != null) {
server.stop();
server.destroy();
}
}
@Override
public void afterPropertiesSet() throws Exception {
new Thread() {
@Override
public void run() {
server = new Server();
server.setHandler(handlers);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
标签:
原文地址:http://www.cnblogs.com/asfeixue/p/4278271.html