From eb23c9d27c84ab7cf2c33f28d2b761673a41b435 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 14 Dec 2012 19:42:58 +0900 Subject: [PATCH] Add missing 'operation(args, future)' for 'operation(args)' - Fixes #818 - Fix inspector warnings --- .../websocketx/WebSocketClientHandshaker.java | 17 +++++++- .../WebSocketClientHandshaker00.java | 4 +- .../WebSocketClientHandshaker08.java | 4 +- .../WebSocketClientHandshaker13.java | 4 +- .../websocketx/WebSocketServerHandshaker.java | 42 +++++++++++++++++-- .../WebSocketServerHandshaker00.java | 27 +++++++----- .../WebSocketServerHandshaker08.java | 12 +++--- .../WebSocketServerHandshaker13.java | 12 +++--- .../io/netty/channel/socket/SctpChannel.java | 12 ++++++ .../netty/channel/socket/SocketChannel.java | 9 +++- .../channel/socket/aio/AioSocketChannel.java | 24 +++++------ .../channel/socket/nio/NioSctpChannel.java | 21 +++++----- .../channel/socket/nio/NioSocketChannel.java | 22 +++++----- .../channel/socket/oio/OioSctpChannel.java | 20 ++++----- .../channel/socket/oio/OioSocketChannel.java | 22 +++++----- 15 files changed, 158 insertions(+), 94 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java index 78ee6bf650..0a95662a99 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java @@ -122,7 +122,22 @@ public abstract class WebSocketClientHandshaker { * @param channel * Channel */ - public abstract ChannelFuture handshake(Channel channel); + public ChannelFuture handshake(Channel channel) { + if (channel == null) { + throw new NullPointerException("channel"); + } + return handshake(channel, channel.newFuture()); + } + + /** + * Begins the opening handshake + * + * @param channel + * Channel + * @param future + * the {@link ChannelFuture} to be notified when the opening handshake is sent + */ + public abstract ChannelFuture handshake(Channel channel, ChannelFuture future); /** * Validates and finishes the opening handshake initiated by {@link #handshake}}. diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java index ebbe33e7b8..736e04dd5d 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java @@ -91,7 +91,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker { * Channel into which we can write our request */ @Override - public ChannelFuture handshake(Channel channel) { + public ChannelFuture handshake(Channel channel, final ChannelFuture handshakeFuture) { // Make keys int spaces1 = WebSocketUtil.randomNumber(1, 12); int spaces2 = WebSocketUtil.randomNumber(1, 12); @@ -173,9 +173,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker { request.setHeader(Names.CONTENT_LENGTH, key3.length); request.setContent(Unpooled.copiedBuffer(key3)); - final ChannelFuture handshakeFuture = channel.newFuture(); ChannelFuture future = channel.write(request); - future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java index 1e528934d7..efa9f3ba02 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java @@ -97,7 +97,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker { * Channel into which we can write our request */ @Override - public ChannelFuture handshake(Channel channel) { + public ChannelFuture handshake(Channel channel, final ChannelFuture handshakeFuture) { // Get path URI wsURL = getWebSocketUrl(); String path = wsURL.getPath(); @@ -151,9 +151,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker { } } - final ChannelFuture handshakeFuture = channel.newFuture(); ChannelFuture future = channel.write(request); - future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java index 474f5a9187..ce3336f25e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java @@ -97,7 +97,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker { * Channel into which we can write our request */ @Override - public ChannelFuture handshake(Channel channel) { + public ChannelFuture handshake(Channel channel, final ChannelFuture handshakeFuture) { // Get path URI wsURL = getWebSocketUrl(); String path = wsURL.getPath(); @@ -151,9 +151,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker { } } - final ChannelFuture handshakeFuture = channel.newFuture(); ChannelFuture future = channel.write(request); - future.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java index 4fbb5848ea..5f69258a24 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java @@ -29,6 +29,8 @@ import java.util.Set; */ public abstract class WebSocketServerHandshaker { + private static final String[] EMPTY_ARRAY = new String[0]; + private final String webSocketUrl; private final String[] subprotocols; @@ -64,7 +66,7 @@ public abstract class WebSocketServerHandshaker { } this.subprotocols = subprotocolArray; } else { - this.subprotocols = new String[0]; + this.subprotocols = EMPTY_ARRAY; } this.maxFramePayloadLength = maxFramePayloadLength; } @@ -109,7 +111,24 @@ public abstract class WebSocketServerHandshaker { * @param req * HTTP Request */ - public abstract ChannelFuture handshake(Channel channel, HttpRequest req); + public ChannelFuture handshake(Channel channel, HttpRequest req) { + if (channel == null) { + throw new NullPointerException("channel"); + } + return handshake(channel, req, channel.newFuture()); + } + + /** + * Performs the opening handshake + * + * @param channel + * Channel + * @param req + * HTTP Request + * @param future + * the {@link ChannelFuture} to be notified when the opening handshake is done + */ + public abstract ChannelFuture handshake(Channel channel, HttpRequest req, ChannelFuture future); /** * Performs the closing handshake @@ -119,7 +138,24 @@ public abstract class WebSocketServerHandshaker { * @param frame * Closing Frame that was received */ - public abstract ChannelFuture close(Channel channel, CloseWebSocketFrame frame); + public ChannelFuture close(Channel channel, CloseWebSocketFrame frame) { + if (channel == null) { + throw new NullPointerException("channel"); + } + return close(channel, frame, channel.newFuture()); + } + + /** + * Performs the closing handshake + * + * @param channel + * Channel + * @param frame + * Closing Frame that was received + * @param future + * the {@link ChannelFuture} to be notified when the closing handshake is done + */ + public abstract ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelFuture future); /** * Selects the first matching supported sub protocol diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java index ddcbafa92d..5cf11f9f22 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java @@ -15,9 +15,6 @@ */ package io.netty.handler.codec.http.websocketx; -import static io.netty.handler.codec.http.HttpHeaders.Names.*; -import static io.netty.handler.codec.http.HttpHeaders.Values.*; -import static io.netty.handler.codec.http.HttpVersion.*; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -36,6 +33,12 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; +import java.util.regex.Pattern; + +import static io.netty.handler.codec.http.HttpHeaders.Names.*; +import static io.netty.handler.codec.http.HttpHeaders.Values.*; +import static io.netty.handler.codec.http.HttpVersion.*; + /** *

* Performs server side opening and closing handshakes for web socket specification version