Browse Source

Remove synchronized block around WebSocketSession.send

Since we now wrap the WebSocketSession with a concurrent decorator, the
synchronized keyword around message sending needed to be removed.

Issue: SPR-11586
pull/495/head
Rossen Stoyanchev 12 years ago
parent
commit
299be08268
  1. 5
      spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java
  2. 6
      spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java
  3. 2
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java

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

@ -118,6 +118,11 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat @@ -118,6 +118,11 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat
}
private void checkSessionLimits() throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Another send already in progress, session id '" + getId() + "'" +
", in-progress send time " + getInProgressSendTime() + " (ms), " +
", buffer size " + this.bufferSize + " bytes");
}
if (getInProgressSendTime() > this.sendTimeLimit) {
logError("A message could not be sent due to a timeout");
getDelegate().close();

6
spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java

@ -198,11 +198,9 @@ public class StompSubProtocolHandler implements SubProtocolHandler { @@ -198,11 +198,9 @@ public class StompSubProtocolHandler implements SubProtocolHandler {
try {
message = MessageBuilder.withPayload(message.getPayload()).setHeaders(headers).build();
byte[] bytes = this.stompEncoder.encode((Message<byte[]>) message);
TextMessage textMessage = new TextMessage(bytes);
synchronized(session) {
session.sendMessage(new TextMessage(bytes));
}
session.sendMessage(textMessage);
}
catch (Throwable ex) {
sendErrorMessage(session, ex);

2
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java

@ -174,7 +174,7 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen @@ -174,7 +174,7 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
@Override
protected void disconnect(CloseStatus status) throws IOException {
if (this.webSocketSession != null) {
if (isActive()) {
this.webSocketSession.close(status);
}
}

Loading…
Cancel
Save