[#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:
parent
ee2558bdf3
commit
a2732c6542
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx.extensions.compression;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
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.
|
||||
*/
|
||||
public class WebSocketClientCompressionHandler extends WebSocketClientExtensionHandler {
|
||||
@ChannelHandler.Sharable
|
||||
public final class WebSocketClientCompressionHandler extends WebSocketClientExtensionHandler {
|
||||
|
||||
/**
|
||||
* Constructor with default configuration.
|
||||
*/
|
||||
public WebSocketClientCompressionHandler() {
|
||||
public static final WebSocketClientCompressionHandler INSTANCE = new WebSocketClientCompressionHandler();
|
||||
|
||||
private WebSocketClientCompressionHandler() {
|
||||
super(new PerMessageDeflateClientExtensionHandshaker(),
|
||||
new DeflateFrameClientExtensionHandshaker(false),
|
||||
new DeflateFrameClientExtensionHandshaker(true));
|
||||
|
@ -113,7 +113,7 @@ public final class WebSocketClient {
|
||||
p.addLast(
|
||||
new HttpClientCodec(),
|
||||
new HttpObjectAggregator(8192),
|
||||
new WebSocketClientCompressionHandler(),
|
||||
WebSocketClientCompressionHandler.INSTANCE,
|
||||
handler);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user