Skip to content

Commit 9bf797e

Browse files
committed
Make SslCloseCompletionEventHandler sharable
1 parent 4da238c commit 9bf797e

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/ChannelPipelineInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void channelCreated(Channel ch) {
6565
ChannelPipeline pipeline = ch.pipeline();
6666
if (sslCtx != null) {
6767
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
68-
pipeline.addLast(new SslCloseCompletionEventHandler());
68+
pipeline.addLast(SslCloseCompletionEventHandler.getInstance());
6969
}
7070

7171
if (protocol == Protocol.HTTP2) {

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/SslCloseCompletionEventHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package software.amazon.awssdk.http.nio.netty.internal;
1717

18+
import io.netty.channel.ChannelHandler;
1819
import io.netty.channel.ChannelHandlerContext;
1920
import io.netty.channel.ChannelInboundHandlerAdapter;
2021
import io.netty.handler.ssl.SslCloseCompletionEvent;
@@ -26,8 +27,14 @@
2627
* in this state can't be reused so they must be closed.
2728
*/
2829
@SdkInternalApi
30+
@ChannelHandler.Sharable
2931
public final class SslCloseCompletionEventHandler extends ChannelInboundHandlerAdapter {
3032

33+
private static final SslCloseCompletionEventHandler INSTANCE = new SslCloseCompletionEventHandler();
34+
35+
private SslCloseCompletionEventHandler() {
36+
}
37+
3138
@Override
3239
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
3340
if (evt instanceof SslCloseCompletionEvent) {
@@ -36,4 +43,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
3643
ctx.fireUserEventTriggered(evt);
3744
}
3845
}
46+
47+
public static SslCloseCompletionEventHandler getInstance() {
48+
return INSTANCE;
49+
}
3950
}

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/internal/SslCloseCompletionEventHandlerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public void setup() {
3535

3636
@Test
3737
public void userEventTriggered_ClosesChannel() {
38-
SslCloseCompletionEventHandler handler = new SslCloseCompletionEventHandler();
38+
SslCloseCompletionEventHandler handler = SslCloseCompletionEventHandler.getInstance();
3939
handler.userEventTriggered(ctx, new SslCloseCompletionEvent(new ClosedChannelException()));
4040

4141
verify(ctx).close();
4242
}
4343

4444
@Test
4545
public void userEventTriggered_StaticVariable_ClosesChannel() {
46-
SslCloseCompletionEventHandler handler = new SslCloseCompletionEventHandler();
46+
SslCloseCompletionEventHandler handler = SslCloseCompletionEventHandler.getInstance();
4747
handler.userEventTriggered(ctx, SslCloseCompletionEvent.SUCCESS);
4848

4949
verify(ctx).close();

0 commit comments

Comments
 (0)