From 278a5924cb530f5b232e5af0f9ab04bd239600c8 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 14 May 2013 14:32:25 -0400 Subject: [PATCH] Remove isLast flag from WebSocketMessage --- .../web/socket/BinaryMessage.java | 46 ++----------------- .../web/socket/WebSocketHandler.java | 5 -- .../adapter/StandardEndpointAdapter.java | 28 ++++------- .../adapter/WebSocketHandlerAdapter.java | 5 -- .../PerConnectionWebSocketHandler.java | 13 ------ .../support/WebSocketHandlerDecorator.java | 5 -- 6 files changed, 12 insertions(+), 90 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/BinaryMessage.java b/spring-websocket/src/main/java/org/springframework/web/socket/BinaryMessage.java index cf6b35594c..5d123abefa 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/BinaryMessage.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/BinaryMessage.java @@ -31,34 +31,15 @@ public final class BinaryMessage extends WebSocketMessage { private byte[] bytes; - private final boolean last; - - - /** - * Create a new {@link BinaryMessage} instance. - * @param payload a non-null payload - */ - public BinaryMessage(ByteBuffer payload) { - this(payload, true); - } /** * Create a new {@link BinaryMessage} instance. * @param payload a non-null payload * @param isLast if the message is the last of a series of partial messages */ - public BinaryMessage(ByteBuffer payload, boolean isLast) { + public BinaryMessage(ByteBuffer payload) { super(payload); this.bytes = null; - this.last = isLast; - } - - /** - * Create a new {@link BinaryMessage} instance. - * @param payload a non-null payload - */ - public BinaryMessage(byte[] payload) { - this(payload, true); } /** @@ -66,18 +47,8 @@ public final class BinaryMessage extends WebSocketMessage { * @param payload a non-null payload * @param isLast if the message is the last of a series of partial messages */ - public BinaryMessage(byte[] payload, boolean isLast) { - this(payload, 0, (payload == null ? 0 : payload.length), isLast); - } - - /** - * Create a new {@link BinaryMessage} instance by wrapping an existing byte array. - * @param payload a non-null payload, NOTE: this value is not copied so care must be - * taken not to modify the array. - * @param isLast if the message is the last of a series of partial messages - */ - public BinaryMessage(byte[] payload, int offset, int len) { - this(payload, offset, len, true); + public BinaryMessage(byte[] payload) { + this(payload, 0, (payload == null ? 0 : payload.length)); } /** @@ -88,20 +59,11 @@ public final class BinaryMessage extends WebSocketMessage { * @param len the length of the array considered for the payload * @param isLast if the message is the last of a series of partial messages */ - public BinaryMessage(byte[] payload, int offset, int len, boolean isLast) { + public BinaryMessage(byte[] payload, int offset, int len) { super(payload != null ? ByteBuffer.wrap(payload, offset, len) : null); if(offset == 0 && len == payload.length) { this.bytes = payload; } - this.last = isLast; - } - - /** - * Returns if this is the last part in a series of partial messages. If this is - * not a partial message this method will return {@code true}. - */ - public boolean isLast() { - return this.last; } /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHandler.java index ffdcdb2cf3..e0b3a2ba22 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHandler.java @@ -72,9 +72,4 @@ public interface WebSocketHandler { */ void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception; - /** - * Whether this WebSocketHandler wishes to receive messages broken up in parts. - */ - boolean isStreaming(); - } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/StandardEndpointAdapter.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/StandardEndpointAdapter.java index 7d27878015..8553bb160f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/StandardEndpointAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/StandardEndpointAdapter.java @@ -75,24 +75,12 @@ public class StandardEndpointAdapter extends Endpoint { handleTextMessage(session, message); } }); - - if (!this.handler.isStreaming()) { - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(ByteBuffer message) { - handleBinaryMessage(session, message, true); - } - }); - } - else { - session.addMessageHandler(new MessageHandler.Partial() { - @Override - public void onMessage(ByteBuffer messagePart, boolean isLast) { - handleBinaryMessage(session, messagePart, isLast); - } - }); - } - + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(ByteBuffer message) { + handleBinaryMessage(session, message); + } + }); } private void handleTextMessage(javax.websocket.Session session, String payload) { @@ -105,8 +93,8 @@ public class StandardEndpointAdapter extends Endpoint { } } - private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload, boolean isLast) { - BinaryMessage binaryMessage = new BinaryMessage(payload, isLast); + private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload) { + BinaryMessage binaryMessage = new BinaryMessage(payload); try { this.handler.handleMessage(this.wsSession, binaryMessage); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/WebSocketHandlerAdapter.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/WebSocketHandlerAdapter.java index 7b97ca5876..8898385029 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/WebSocketHandlerAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/WebSocketHandlerAdapter.java @@ -68,9 +68,4 @@ public class WebSocketHandlerAdapter implements WebSocketHandler { public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { } - @Override - public boolean isStreaming() { - return false; - } - } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/support/PerConnectionWebSocketHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/support/PerConnectionWebSocketHandler.java index 8727f1afaf..c9ad6797df 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/support/PerConnectionWebSocketHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/support/PerConnectionWebSocketHandler.java @@ -57,22 +57,9 @@ public class PerConnectionWebSocketHandler implements WebSocketHandler, BeanFact private final Map handlers = new ConcurrentHashMap(); - private final boolean streaming; - public PerConnectionWebSocketHandler(Class handlerType) { - this(handlerType, false); - } - - public PerConnectionWebSocketHandler(Class handlerType, boolean isStreaming) { this.provider = new BeanCreatingHandlerProvider(handlerType); - this.streaming = isStreaming; - } - - - @Override - public boolean isStreaming() { - return this.streaming; } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHandlerDecorator.java b/spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHandlerDecorator.java index 00c5dcdbcc..e9d7db761d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHandlerDecorator.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHandlerDecorator.java @@ -62,11 +62,6 @@ public class WebSocketHandlerDecorator implements WebSocketHandler { this.delegate.afterConnectionClosed(session, closeStatus); } - @Override - public boolean isStreaming() { - return this.delegate.isStreaming(); - } - @Override public String toString() { return getClass().getSimpleName() + " [delegate=" + this.delegate + "]";