Browse Source

Remove isLast flag from WebSocketMessage

pull/292/head
Rossen Stoyanchev 12 years ago
parent
commit
278a5924cb
  1. 46
      spring-websocket/src/main/java/org/springframework/web/socket/BinaryMessage.java
  2. 5
      spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHandler.java
  3. 28
      spring-websocket/src/main/java/org/springframework/web/socket/adapter/StandardEndpointAdapter.java
  4. 5
      spring-websocket/src/main/java/org/springframework/web/socket/adapter/WebSocketHandlerAdapter.java
  5. 13
      spring-websocket/src/main/java/org/springframework/web/socket/support/PerConnectionWebSocketHandler.java
  6. 5
      spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHandlerDecorator.java

46
spring-websocket/src/main/java/org/springframework/web/socket/BinaryMessage.java

@ -31,34 +31,15 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> { @@ -31,34 +31,15 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> {
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<ByteBuffer> { @@ -66,18 +47,8 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> {
* @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<ByteBuffer> { @@ -88,20 +59,11 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> {
* @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;
}
/**

5
spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHandler.java

@ -72,9 +72,4 @@ public interface WebSocketHandler { @@ -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();
}

28
spring-websocket/src/main/java/org/springframework/web/socket/adapter/StandardEndpointAdapter.java

@ -75,24 +75,12 @@ public class StandardEndpointAdapter extends Endpoint { @@ -75,24 +75,12 @@ public class StandardEndpointAdapter extends Endpoint {
handleTextMessage(session, message);
}
});
if (!this.handler.isStreaming()) {
session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {
@Override
public void onMessage(ByteBuffer message) {
handleBinaryMessage(session, message, true);
}
});
}
else {
session.addMessageHandler(new MessageHandler.Partial<ByteBuffer>() {
@Override
public void onMessage(ByteBuffer messagePart, boolean isLast) {
handleBinaryMessage(session, messagePart, isLast);
}
});
}
session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {
@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 { @@ -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);
}

5
spring-websocket/src/main/java/org/springframework/web/socket/adapter/WebSocketHandlerAdapter.java

@ -68,9 +68,4 @@ public class WebSocketHandlerAdapter implements WebSocketHandler { @@ -68,9 +68,4 @@ public class WebSocketHandlerAdapter implements WebSocketHandler {
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
}
@Override
public boolean isStreaming() {
return false;
}
}

13
spring-websocket/src/main/java/org/springframework/web/socket/support/PerConnectionWebSocketHandler.java

@ -57,22 +57,9 @@ public class PerConnectionWebSocketHandler implements WebSocketHandler, BeanFact @@ -57,22 +57,9 @@ public class PerConnectionWebSocketHandler implements WebSocketHandler, BeanFact
private final Map<WebSocketSession, WebSocketHandler> handlers =
new ConcurrentHashMap<WebSocketSession, WebSocketHandler>();
private final boolean streaming;
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType) {
this(handlerType, false);
}
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean isStreaming) {
this.provider = new BeanCreatingHandlerProvider<WebSocketHandler>(handlerType);
this.streaming = isStreaming;
}
@Override
public boolean isStreaming() {
return this.streaming;
}
@Override

5
spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHandlerDecorator.java

@ -62,11 +62,6 @@ public class WebSocketHandlerDecorator implements WebSocketHandler { @@ -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 + "]";

Loading…
Cancel
Save