Skip to content

Commit 278a592

Browse files
committed
Remove isLast flag from WebSocketMessage
1 parent 9ca03cf commit 278a592

File tree

6 files changed

+12
-90
lines changed

6 files changed

+12
-90
lines changed

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

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,53 +31,24 @@ public final class BinaryMessage extends WebSocketMessage<ByteBuffer> {
3131

3232
private byte[] bytes;
3333

34-
private final boolean last;
35-
36-
37-
/**
38-
* Create a new {@link BinaryMessage} instance.
39-
* @param payload a non-null payload
40-
*/
41-
public BinaryMessage(ByteBuffer payload) {
42-
this(payload, true);
43-
}
4434

4535
/**
4636
* Create a new {@link BinaryMessage} instance.
4737
* @param payload a non-null payload
4838
* @param isLast if the message is the last of a series of partial messages
4939
*/
50-
public BinaryMessage(ByteBuffer payload, boolean isLast) {
40+
public BinaryMessage(ByteBuffer payload) {
5141
super(payload);
5242
this.bytes = null;
53-
this.last = isLast;
54-
}
55-
56-
/**
57-
* Create a new {@link BinaryMessage} instance.
58-
* @param payload a non-null payload
59-
*/
60-
public BinaryMessage(byte[] payload) {
61-
this(payload, true);
6243
}
6344

6445
/**
6546
* Create a new {@link BinaryMessage} instance.
6647
* @param payload a non-null payload
6748
* @param isLast if the message is the last of a series of partial messages
6849
*/
69-
public BinaryMessage(byte[] payload, boolean isLast) {
70-
this(payload, 0, (payload == null ? 0 : payload.length), isLast);
71-
}
72-
73-
/**
74-
* Create a new {@link BinaryMessage} instance by wrapping an existing byte array.
75-
* @param payload a non-null payload, NOTE: this value is not copied so care must be
76-
* taken not to modify the array.
77-
* @param isLast if the message is the last of a series of partial messages
78-
*/
79-
public BinaryMessage(byte[] payload, int offset, int len) {
80-
this(payload, offset, len, true);
50+
public BinaryMessage(byte[] payload) {
51+
this(payload, 0, (payload == null ? 0 : payload.length));
8152
}
8253

8354
/**
@@ -88,20 +59,11 @@ public BinaryMessage(byte[] payload, int offset, int len) {
8859
* @param len the length of the array considered for the payload
8960
* @param isLast if the message is the last of a series of partial messages
9061
*/
91-
public BinaryMessage(byte[] payload, int offset, int len, boolean isLast) {
62+
public BinaryMessage(byte[] payload, int offset, int len) {
9263
super(payload != null ? ByteBuffer.wrap(payload, offset, len) : null);
9364
if(offset == 0 && len == payload.length) {
9465
this.bytes = payload;
9566
}
96-
this.last = isLast;
97-
}
98-
99-
/**
100-
* Returns if this is the last part in a series of partial messages. If this is
101-
* not a partial message this method will return {@code true}.
102-
*/
103-
public boolean isLast() {
104-
return this.last;
10567
}
10668

10769
/**

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,4 @@ public interface WebSocketHandler {
7272
*/
7373
void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception;
7474

75-
/**
76-
* Whether this WebSocketHandler wishes to receive messages broken up in parts.
77-
*/
78-
boolean isStreaming();
79-
8075
}

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,12 @@ public void onMessage(String message) {
7575
handleTextMessage(session, message);
7676
}
7777
});
78-
79-
if (!this.handler.isStreaming()) {
80-
session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {
81-
@Override
82-
public void onMessage(ByteBuffer message) {
83-
handleBinaryMessage(session, message, true);
84-
}
85-
});
86-
}
87-
else {
88-
session.addMessageHandler(new MessageHandler.Partial<ByteBuffer>() {
89-
@Override
90-
public void onMessage(ByteBuffer messagePart, boolean isLast) {
91-
handleBinaryMessage(session, messagePart, isLast);
92-
}
93-
});
94-
}
95-
78+
session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {
79+
@Override
80+
public void onMessage(ByteBuffer message) {
81+
handleBinaryMessage(session, message);
82+
}
83+
});
9684
}
9785

9886
private void handleTextMessage(javax.websocket.Session session, String payload) {
@@ -105,8 +93,8 @@ private void handleTextMessage(javax.websocket.Session session, String payload)
10593
}
10694
}
10795

108-
private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload, boolean isLast) {
109-
BinaryMessage binaryMessage = new BinaryMessage(payload, isLast);
96+
private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload) {
97+
BinaryMessage binaryMessage = new BinaryMessage(payload);
11098
try {
11199
this.handler.handleMessage(this.wsSession, binaryMessage);
112100
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,4 @@ public void handleTransportError(WebSocketSession session, Throwable exception)
6868
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
6969
}
7070

71-
@Override
72-
public boolean isStreaming() {
73-
return false;
74-
}
75-
7671
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,9 @@ public class PerConnectionWebSocketHandler implements WebSocketHandler, BeanFact
5757
private final Map<WebSocketSession, WebSocketHandler> handlers =
5858
new ConcurrentHashMap<WebSocketSession, WebSocketHandler>();
5959

60-
private final boolean streaming;
61-
6260

6361
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType) {
64-
this(handlerType, false);
65-
}
66-
67-
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean isStreaming) {
6862
this.provider = new BeanCreatingHandlerProvider<WebSocketHandler>(handlerType);
69-
this.streaming = isStreaming;
70-
}
71-
72-
73-
@Override
74-
public boolean isStreaming() {
75-
return this.streaming;
7663
}
7764

7865
@Override

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus closeSta
6262
this.delegate.afterConnectionClosed(session, closeStatus);
6363
}
6464

65-
@Override
66-
public boolean isStreaming() {
67-
return this.delegate.isStreaming();
68-
}
69-
7065
@Override
7166
public String toString() {
7267
return getClass().getSimpleName() + " [delegate=" + this.delegate + "]";

0 commit comments

Comments
 (0)