3636public final class DefaultServerNetwork <C extends Connection <?, ?>> extends AbstractNetwork <C > implements
3737 ServerNetwork <C > {
3838
39- private static final Logger LOGGER = LoggerManager .getLogger (DefaultServerNetwork .class );
40-
4139 private interface ServerCompletionHandler <C extends Connection <?, ?>> extends
4240 CompletionHandler <AsynchronousSocketChannel , DefaultServerNetwork <C >> {}
4341
@@ -54,7 +52,7 @@ public void completed(@NotNull AsynchronousSocketChannel channel, @NotNull Defau
5452 @ Override
5553 public void failed (@ NotNull Throwable exc , @ NotNull DefaultServerNetwork <C > network ) {
5654 if (exc instanceof AsynchronousCloseException ) {
57- LOGGER .warning ("Server network was closed. " );
55+ LOGGER .warning ("Server network was closed" );
5856 } else {
5957 LOGGER .error ("Got exception during accepting new connection:" );
6058 LOGGER .error (exc );
@@ -78,28 +76,34 @@ public DefaultServerNetwork(
7876 super (config , channelToConnection );
7977
8078 var threadFactory = new GroupThreadFactory (
81- config .getGroupName (),
79+ config .getThreadGroupName (),
8280 config .getThreadConstructor (),
8381 config .getThreadPriority (),
84- true
82+ false
8583 );
8684
87- var executor = config .getGroupSize () < config .getGroupMaxSize () ? new ThreadPoolExecutor (
88- config .getGroupSize (),
89- config .getGroupMaxSize (),
85+ var executor = config .getThreadGroupMinSize () < config .getThreadGroupMaxSize () ? new ThreadPoolExecutor (
86+ config .getThreadGroupMinSize (),
87+ config .getThreadGroupMaxSize (),
9088 120 ,
9189 TimeUnit .SECONDS ,
9290 new SynchronousQueue <>(),
9391 threadFactory ,
9492 new ThreadPoolExecutor .CallerRunsPolicy ()
95- ) : Executors .newFixedThreadPool (config .getGroupSize (), threadFactory );
93+ ) : Executors .newFixedThreadPool (config .getThreadGroupMinSize (), threadFactory );
9694
9795 // activate the executor
9896 executor .submit (() -> {});
9997
100- LOGGER .info ("Executor configuration:" );
101- LOGGER .info (config , conf -> "Min threads: " + conf .getGroupSize ());
102- LOGGER .info (config , conf -> "Max threads: " + conf .getGroupMaxSize ());
98+ LOGGER .info (config , conf -> "Server network configuration: {\n " +
99+ " minThreads: " + conf .getThreadGroupMinSize () + ",\n " +
100+ " maxThreads: " + conf .getThreadGroupMaxSize () + ",\n " +
101+ " priority: " + conf .getThreadPriority () + ",\n " +
102+ " groupName: \" " + conf .getThreadGroupName () + "\" ,\n " +
103+ " readBufferSize: " + conf .getReadBufferSize () + ",\n " +
104+ " pendingBufferSize: " + conf .getPendingBufferSize () + ",\n " +
105+ " writeBufferSize: " + conf .getWriteBufferSize () + "\n " +
106+ "}" );
103107
104108 this .group = uncheckedGet (executor , AsynchronousChannelGroup ::withThreadPool );
105109 this .channel = uncheckedGet (group , AsynchronousServerSocketChannel ::open );
@@ -121,7 +125,7 @@ public DefaultServerNetwork(
121125 }
122126 }
123127
124- LOGGER .info (address , adr -> "Started server on address: " + adr );
128+ LOGGER .info (address , adr -> "Started server socket on address: " + adr );
125129
126130 if (!subscribers .isEmpty ()) {
127131 acceptNext ();
@@ -134,23 +138,21 @@ public DefaultServerNetwork(
134138 public <S extends ServerNetwork <C >> @ NotNull S start (@ NotNull InetSocketAddress serverAddress ) {
135139 Utils .unchecked (channel , serverAddress , AsynchronousServerSocketChannel ::bind );
136140
137- LOGGER .info (serverAddress , addr -> "Started server on address: " + addr );
141+ LOGGER .info (serverAddress , addr -> "Started server socket on address: " + addr );
138142
139143 if (!subscribers .isEmpty ()) {
140144 acceptNext ();
141145 }
142146
143- return ClassUtils .unsafeCast (this );
147+ return ClassUtils .unsafeNNCast (this );
144148 }
145149
146150 protected void acceptNext () {
147151 if (channel .isOpen ()) {
148- try {
149- channel .accept (this , acceptHandler );
150- } catch (AcceptPendingException ignored ) {
151- }
152+ try { channel .accept (this , acceptHandler ); }
153+ catch (AcceptPendingException ignored ) {}
152154 } else {
153- LOGGER .warning ("Cannot accept a next connection because server channel is already closed. " );
155+ LOGGER .warning ("Cannot accept a next connection because server channel is already closed" );
154156 }
155157 }
156158
0 commit comments