From cb124e6fdee765dd233e22b96f489c688e3742ed Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 25 Jul 2016 09:38:44 +1000 Subject: [PATCH] UNDERTOW-779 Ability to pass context objects for WebSocketCallback in Websockets helper class --- .../undertow/websockets/core/WebSockets.java | 439 ++++++++++++++---- 1 file changed, 340 insertions(+), 99 deletions(-) diff --git a/core/src/main/java/io/undertow/websockets/core/WebSockets.java b/core/src/main/java/io/undertow/websockets/core/WebSockets.java index 466c701b43..485d1b6a35 100644 --- a/core/src/main/java/io/undertow/websockets/core/WebSockets.java +++ b/core/src/main/java/io/undertow/websockets/core/WebSockets.java @@ -40,56 +40,104 @@ public class WebSockets { /** * Sends a complete text message, invoking the callback when complete * - * @param message - * @param wsChannel - * @param callback + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendText(final String message, final WebSocketChannel wsChannel, final WebSocketCallback callback) { + sendText(message, wsChannel, callback, null); + } + + /** + * Sends a complete text message, invoking the callback when complete + * + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendText(final String message, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { final ByteBuffer data = ByteBuffer.wrap(message.getBytes(StandardCharsets.UTF_8)); - sendInternal(data, WebSocketFrameType.TEXT, wsChannel, callback, -1); + sendInternal(data, WebSocketFrameType.TEXT, wsChannel, callback, context, -1); } /** * Sends a complete text message, invoking the callback when complete * - * @param message - * @param wsChannel - * @param callback + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion * @param timeoutmillis the timeout in milliseconds */ public static void sendText(final String message, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { + sendText(message, wsChannel, callback, null, timeoutmillis); + } + + /** + * Sends a complete text message, invoking the callback when complete + * + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + * @param timeoutmillis the timeout in milliseconds + */ + public static void sendText(final String message, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { final ByteBuffer data = ByteBuffer.wrap(message.getBytes(StandardCharsets.UTF_8)); - sendInternal(data, WebSocketFrameType.TEXT, wsChannel, callback, timeoutmillis); + sendInternal(data, WebSocketFrameType.TEXT, wsChannel, callback, context, timeoutmillis); } /** * Sends a complete text message, invoking the callback when complete * - * @param message - * @param wsChannel - * @param callback + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendText(final ByteBuffer message, final WebSocketChannel wsChannel, final WebSocketCallback callback) { - sendInternal(message, WebSocketFrameType.TEXT, wsChannel, callback, -1); + sendInternal(message, WebSocketFrameType.TEXT, wsChannel, callback, null, -1); } /** * Sends a complete text message, invoking the callback when complete * - * @param message - * @param wsChannel - * @param callback + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendText(final ByteBuffer message, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendInternal(message, WebSocketFrameType.TEXT, wsChannel, callback, context, -1); + } + + /** + * Sends a complete text message, invoking the callback when complete + * + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendText(final ByteBuffer message, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { - sendInternal(message, WebSocketFrameType.TEXT, wsChannel, callback, timeoutmillis); + sendInternal(message, WebSocketFrameType.TEXT, wsChannel, callback, null, timeoutmillis); } + /** + * Sends a complete text message, invoking the callback when complete + * + * @param message The text to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendText(final ByteBuffer message, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { + sendInternal(message, WebSocketFrameType.TEXT, wsChannel, callback, context, timeoutmillis); + } /** * Sends a complete text message, invoking the callback when complete * - * @param message - * @param wsChannel + * @param message The text to send + * @param wsChannel The web socket channel */ public static void sendTextBlocking(final String message, final WebSocketChannel wsChannel) throws IOException { final ByteBuffer data = ByteBuffer.wrap(message.getBytes(StandardCharsets.UTF_8)); @@ -99,8 +147,8 @@ public static void sendTextBlocking(final String message, final WebSocketChannel /** * Sends a complete text message, invoking the callback when complete * - * @param message - * @param wsChannel + * @param message The text to send + * @param wsChannel The web socket channel */ public static void sendTextBlocking(final ByteBuffer message, final WebSocketChannel wsChannel) throws IOException { sendBlockingInternal(message, WebSocketFrameType.TEXT, wsChannel); @@ -109,52 +157,100 @@ public static void sendTextBlocking(final ByteBuffer message, final WebSocketCha /** * Sends a complete ping message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPing(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { - sendInternal(data, WebSocketFrameType.PING, wsChannel, callback, -1); + sendInternal(data, WebSocketFrameType.PING, wsChannel, callback, null, -1); } /** * Sends a complete ping message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPing(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendInternal(data, WebSocketFrameType.PING, wsChannel, callback, context, -1); + } + + /** + * Sends a complete ping message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPing(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { - sendInternal(data, WebSocketFrameType.PING, wsChannel, callback, timeoutmillis); + sendInternal(data, WebSocketFrameType.PING, wsChannel, callback, null, timeoutmillis); + } + + /** + * Sends a complete ping message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPing(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { + sendInternal(data, WebSocketFrameType.PING, wsChannel, callback, context, timeoutmillis); } /** * Sends a complete ping message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPing(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { - sendInternal(mergeBuffers(data), WebSocketFrameType.PING, wsChannel, callback, -1); + sendInternal(mergeBuffers(data), WebSocketFrameType.PING, wsChannel, callback, null, -1); + } + + /** + * Sends a complete ping message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPing(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendInternal(mergeBuffers(data), WebSocketFrameType.PING, wsChannel, callback, context, -1); } /** * Sends a complete ping message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPing(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { - sendInternal(mergeBuffers(data), WebSocketFrameType.PING, wsChannel, callback, timeoutmillis); + sendInternal(mergeBuffers(data), WebSocketFrameType.PING, wsChannel, callback, null, timeoutmillis); + } + + /** + * Sends a complete ping message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPing(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { + sendInternal(mergeBuffers(data), WebSocketFrameType.PING, wsChannel, callback, context, timeoutmillis); } /** * Sends a complete ping message using blocking IO * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendPingBlocking(final ByteBuffer data, final WebSocketChannel wsChannel) throws IOException { sendBlockingInternal(data, WebSocketFrameType.PING, wsChannel); @@ -163,8 +259,8 @@ public static void sendPingBlocking(final ByteBuffer data, final WebSocketChanne /** * Sends a complete ping message using blocking IO * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendPingBlocking(final ByteBuffer[] data, final WebSocketChannel wsChannel) throws IOException { sendBlockingInternal(mergeBuffers(data), WebSocketFrameType.PING, wsChannel); @@ -173,52 +269,100 @@ public static void sendPingBlocking(final ByteBuffer[] data, final WebSocketChan /** * Sends a complete pong message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPong(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { - sendInternal(data, WebSocketFrameType.PONG, wsChannel, callback, -1); + sendInternal(data, WebSocketFrameType.PONG, wsChannel, callback, null, -1); + } + + /** + * Sends a complete pong message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPong(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendInternal(data, WebSocketFrameType.PONG, wsChannel, callback, context, -1); } /** * Sends a complete pong message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPong(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { - sendInternal(data, WebSocketFrameType.PONG, wsChannel, callback, timeoutmillis); + sendInternal(data, WebSocketFrameType.PONG, wsChannel, callback, null, timeoutmillis); } + /** + * Sends a complete pong message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPong(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { + sendInternal(data, WebSocketFrameType.PONG, wsChannel, callback, context, timeoutmillis); + } /** * Sends a complete pong message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPong(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { - sendInternal(mergeBuffers(data), WebSocketFrameType.PONG, wsChannel, callback, -1); + sendInternal(mergeBuffers(data), WebSocketFrameType.PONG, wsChannel, callback, null, -1); } /** * Sends a complete pong message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPong(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendInternal(mergeBuffers(data), WebSocketFrameType.PONG, wsChannel, callback, context, -1); + } + + /** + * Sends a complete pong message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendPong(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { - sendInternal(mergeBuffers(data), WebSocketFrameType.PONG, wsChannel, callback, timeoutmillis); + sendInternal(mergeBuffers(data), WebSocketFrameType.PONG, wsChannel, callback, null, timeoutmillis); + } + + /** + * Sends a complete pong message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendPong(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { + sendInternal(mergeBuffers(data), WebSocketFrameType.PONG, wsChannel, callback, context, timeoutmillis); } + /** * Sends a complete pong message using blocking IO * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendPongBlocking(final ByteBuffer data, final WebSocketChannel wsChannel) throws IOException { sendBlockingInternal(data, WebSocketFrameType.PONG, wsChannel); @@ -227,8 +371,8 @@ public static void sendPongBlocking(final ByteBuffer data, final WebSocketChanne /** * Sends a complete pong message using blocking IO * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendPongBlocking(final ByteBuffer[] data, final WebSocketChannel wsChannel) throws IOException { sendBlockingInternal(mergeBuffers(data), WebSocketFrameType.PONG, wsChannel); @@ -237,52 +381,100 @@ public static void sendPongBlocking(final ByteBuffer[] data, final WebSocketChan /** * Sends a complete text message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendBinary(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { - sendInternal(data, WebSocketFrameType.BINARY, wsChannel, callback, -1); + sendInternal(data, WebSocketFrameType.BINARY, wsChannel, callback, null, -1); + } + + /** + * Sends a complete text message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendBinary(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendInternal(data, WebSocketFrameType.BINARY, wsChannel, callback, context, -1); } /** * Sends a complete text message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendBinary(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { - sendInternal(data, WebSocketFrameType.BINARY, wsChannel, callback, timeoutmillis); + sendInternal(data, WebSocketFrameType.BINARY, wsChannel, callback, null, timeoutmillis); } /** * Sends a complete text message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendBinary(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { + sendInternal(data, WebSocketFrameType.BINARY, wsChannel, callback, context, timeoutmillis); + } + + /** + * Sends a complete text message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendBinary(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { - sendInternal(mergeBuffers(data), WebSocketFrameType.BINARY, wsChannel, callback, -1); + sendInternal(mergeBuffers(data), WebSocketFrameType.BINARY, wsChannel, callback, null, -1); } /** * Sends a complete text message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendBinary(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendInternal(mergeBuffers(data), WebSocketFrameType.BINARY, wsChannel, callback, context, -1); + } + + /** + * Sends a complete text message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendBinary(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { - sendInternal(mergeBuffers(data), WebSocketFrameType.BINARY, wsChannel, callback, timeoutmillis); + sendInternal(mergeBuffers(data), WebSocketFrameType.BINARY, wsChannel, callback, null, timeoutmillis); + } + + /** + * Sends a complete text message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendBinary(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { + sendInternal(mergeBuffers(data), WebSocketFrameType.BINARY, wsChannel, callback, context, timeoutmillis); } /** * Sends a complete binary message using blocking IO * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendBinaryBlocking(final ByteBuffer data, final WebSocketChannel wsChannel) throws IOException { sendBlockingInternal(data, WebSocketFrameType.BINARY, wsChannel); @@ -291,8 +483,8 @@ public static void sendBinaryBlocking(final ByteBuffer data, final WebSocketChan /** * Sends a complete binary message using blocking IO * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendBinaryBlocking(final ByteBuffer[] data, final WebSocketChannel wsChannel) throws IOException { sendBlockingInternal(mergeBuffers(data), WebSocketFrameType.BINARY, wsChannel); @@ -301,9 +493,9 @@ public static void sendBinaryBlocking(final ByteBuffer[] data, final WebSocketCh /** * Sends a complete close message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendClose(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { CloseMessage sm = new CloseMessage(data); @@ -313,45 +505,94 @@ public static void sendClose(final ByteBuffer data, final WebSocketChannel wsCha /** * Sends a complete close message, invoking the callback when complete * - * @param data - * @param wsChannel - * @param callback + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendClose(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + CloseMessage sm = new CloseMessage(data); + sendClose(sm, wsChannel, callback, context); + } + + /** + * Sends a complete close message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendClose(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback) { CloseMessage sm = new CloseMessage(data); sendClose(sm, wsChannel, callback); } + /** + * Sends a complete close message, invoking the callback when complete + * + * @param data The data to send + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendClose(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + CloseMessage sm = new CloseMessage(data); + sendClose(sm, wsChannel, callback, context); + } /** * Sends a complete close message, invoking the callback when complete * * @param code The close code - * @param wsChannel - * @param callback + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendClose(final int code, String reason, final WebSocketChannel wsChannel, final WebSocketCallback callback) { sendClose(new CloseMessage(code, reason), wsChannel, callback); } + /** + * Sends a complete close message, invoking the callback when complete + * + * @param code The close code + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendClose(final int code, String reason, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { + sendClose(new CloseMessage(code, reason), wsChannel, callback, context); + } + /** * Sends a complete close message, invoking the callback when complete * * @param closeMessage The close message - * @param wsChannel - * @param callback + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion */ public static void sendClose(final CloseMessage closeMessage, final WebSocketChannel wsChannel, final WebSocketCallback callback) { + sendClose(closeMessage, wsChannel, callback, null); + } + + /** + * Sends a complete close message, invoking the callback when complete + * + * @param closeMessage The close message + * @param wsChannel The web socket channel + * @param callback The callback to invoke on completion + * @param context The context object that will be passed to the callback on completion + */ + public static void sendClose(final CloseMessage closeMessage, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context) { wsChannel.setCloseCode(closeMessage.getCode()); wsChannel.setCloseReason(closeMessage.getReason()); - sendInternal(closeMessage.toByteBuffer(), WebSocketFrameType.CLOSE, wsChannel, callback, -1); + sendInternal(closeMessage.toByteBuffer(), WebSocketFrameType.CLOSE, wsChannel, callback, context, -1); } /** * Sends a complete close message, invoking the callback when complete * * @param closeMessage the close message - * @param wsChannel + * @param wsChannel The web socket channel */ public static void sendCloseBlocking(final CloseMessage closeMessage, final WebSocketChannel wsChannel) throws IOException { wsChannel.setCloseReason(closeMessage.getReason()); @@ -362,7 +603,7 @@ public static void sendCloseBlocking(final CloseMessage closeMessage, final WebS * Sends a complete close message, invoking the callback when complete * * @param code - * @param wsChannel + * @param wsChannel The web socket channel */ public static void sendCloseBlocking(final int code, String reason, final WebSocketChannel wsChannel) throws IOException { sendCloseBlocking(new CloseMessage(code, reason), wsChannel); @@ -370,8 +611,8 @@ public static void sendCloseBlocking(final int code, String reason, final WebSoc /** * Sends a complete close message, invoking the callback when complete * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendCloseBlocking(final ByteBuffer data, final WebSocketChannel wsChannel) throws IOException { sendCloseBlocking(new CloseMessage(data), wsChannel); @@ -380,21 +621,21 @@ public static void sendCloseBlocking(final ByteBuffer data, final WebSocketChann /** * Sends a complete close message, invoking the callback when complete * - * @param data - * @param wsChannel + * @param data The data to send + * @param wsChannel The web socket channel */ public static void sendCloseBlocking(final ByteBuffer[] data, final WebSocketChannel wsChannel) throws IOException { sendCloseBlocking(new CloseMessage(data), wsChannel); } - private static void sendInternal(final ByteBuffer data, WebSocketFrameType type, final WebSocketChannel wsChannel, final WebSocketCallback callback, long timeoutmillis) { + private static void sendInternal(final ByteBuffer data, WebSocketFrameType type, final WebSocketChannel wsChannel, final WebSocketCallback callback, T context, long timeoutmillis) { try { StreamSinkFrameChannel channel = wsChannel.send(type); // TODO chunk data into some MTU-like thing to control packet size if(!channel.send(new ImmediatePooledByteBuffer(data))) { throw WebSocketMessages.MESSAGES.unableToSendOnNewChannel(); } - flushChannelAsync(wsChannel, callback, channel, null, timeoutmillis); + flushChannelAsync(wsChannel, callback, channel, context, timeoutmillis); } catch (IOException e) { if (callback != null) { callback.onError(wsChannel, null, e);