我使用码头服务器来处理客户端请求,并且有一个要求,我需要根据需要启动或停止一个或几个ServerConnectors,而无需重新启动连接这些连接器的服务器。
例如。
ServerConnector httpConnector;
ServerConnector httpsConnector;
Server server;
server.addConnector(httpConnector);
server.addConnector(httpsConnector);
server.start()
需要启动/停止/取消特定的连接器,而不必强制服务器重新启动。
答案 0 :(得分:1)
您将必须执行以下操作...
// TODO: Have a reference to the Connector you are going to work with
// Remove from server first.
server.removeConnector(connector);
// Stop the connector.
// NOTE: Existing connections will still live on.
// This will only stop accepting new connections.
connector.stop(); // might take a while (waiting for acceptors to close)
// TODO: do what you want with this connector
// Eg: harshly close existing connections
connector.getConnectedEndPoints().forEach((endpoint)-> {
endpoint.close();
});
// Re-add stopped connector if you want
// This will start connector as well
// This can fail (eg: if port is already in use)
server.addConnector(connector);
答案 1 :(得分:0)
您可以调用连接器上的stop
使其停止,并调用start
重新启动它。要获得相关的连接器,有两种解决方案:
getConnectors
来获取服务器的所有连接器,对其进行迭代,找到要停止的连接器,然后在其上调用stop
或start
来停止或启动它。< / li>