[#4755] Make WebSocketClientCompressionHandler @Sharable

Motivation:

WebSocketClientCompressionHandler is stateless so it should be @Sharable.

Modifications:

Add @Sharable annotation to WebSocketClientCompressionHandler, make constructor private and add static field to get the instance.

Result:

Less object creation.
This commit is contained in:
Norman Maurer 2016-01-26 15:03:59 +01:00
parent ee2558bdf3
commit a2732c6542
2 changed files with 7 additions and 6 deletions

View File

@ -15,6 +15,7 @@
*/ */
package io.netty.handler.codec.http.websocketx.extensions.compression; package io.netty.handler.codec.http.websocketx.extensions.compression;
import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler; import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler;
/** /**
@ -23,12 +24,12 @@ import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensio
* *
* See <tt>io.netty.example.http.websocketx.client.WebSocketClient</tt> for usage. * See <tt>io.netty.example.http.websocketx.client.WebSocketClient</tt> for usage.
*/ */
public class WebSocketClientCompressionHandler extends WebSocketClientExtensionHandler { @ChannelHandler.Sharable
public final class WebSocketClientCompressionHandler extends WebSocketClientExtensionHandler {
/** public static final WebSocketClientCompressionHandler INSTANCE = new WebSocketClientCompressionHandler();
* Constructor with default configuration.
*/ private WebSocketClientCompressionHandler() {
public WebSocketClientCompressionHandler() {
super(new PerMessageDeflateClientExtensionHandshaker(), super(new PerMessageDeflateClientExtensionHandshaker(),
new DeflateFrameClientExtensionHandshaker(false), new DeflateFrameClientExtensionHandshaker(false),
new DeflateFrameClientExtensionHandshaker(true)); new DeflateFrameClientExtensionHandshaker(true));

View File

@ -113,7 +113,7 @@ public final class WebSocketClient {
p.addLast( p.addLast(
new HttpClientCodec(), new HttpClientCodec(),
new HttpObjectAggregator(8192), new HttpObjectAggregator(8192),
new WebSocketClientCompressionHandler(), WebSocketClientCompressionHandler.INSTANCE,
handler); handler);
} }
}); });