Improve handling of shutdown
@@ -48,6 +48,7 @@ public class AcceptorEventHandler implements EventHandler, Closeable {
private final ServerSocketChannel ssc;
@NotNull
private final Supplier<? extends NetworkContext> ncFactory;
+ private final String hostPort;
private EventLoop eventLoop;
@@ -57,7 +58,8 @@ public class AcceptorEventHandler implements EventHandler, Closeable {
@NotNull final Function<NetworkContext, TcpEventHandler> handlerFactory,
@NotNull final Supplier<? extends NetworkContext> ncFactory) throws IOException {
this.handlerFactory = handlerFactory;
- this.ssc = TCPRegistry.acquireServerSocketChannel(hostPort);
+ this.hostPort = hostPort;
+ this.ssc = TCPRegistry.acquireServerSocketChannel(this.hostPort);
this.ncFactory = ncFactory;
}
@@ -88,20 +90,15 @@ public class AcceptorEventHandler implements EventHandler, Closeable {
eventLoop.addHandler(apply);
}
- } catch (ClosedChannelException e) {
- ServerSocket socket = ssc.socket();
- if (socket != null)
- Jvm.warn().on(getClass(), "port=" + socket.getLocalPort(), e);
- closeSocket();
- throw new InvalidEventHandlerException(e);
} catch (Exception e) {
+ if (!closed) {
ServerSocket socket = ssc.socket();
if (socket != null)
- Jvm.warn().on(getClass(), "port=" + socket.getLocalPort(), e);
- if (!closed) {
- Jvm.fatal().on(getClass(), e);
- closeSocket();
+ Jvm.warn().on(getClass(), hostPort+", port=" + socket.getLocalPort(), e);
+ else
+ Jvm.warn().on(getClass(), hostPort, e);
}
+ closeSocket();
throw new InvalidEventHandlerException(e);
}
return false;
