如何在超过 ConcurrentWebSocketSessionDecorator bufferSizeLimit 时刷新缓冲区?
How to flush buffer when ConcurrentWebSocketSessionDecorator bufferSizeLimit exceeded?
我在我的项目中使用Spring Websocket,我发现ConcurrentWebSocketSessionDecorator在超过bufferSizeLimit时停止了,但是没有办法恢复它。
我是这样使用的:
try {
if (concurrentWebSocketSessionDecorator.isOpen()) {
concurrentWebSocketSessionDecorator.sendMessage(message);
}
} catch (SessionLimitExceededException se) {
logger.warn("sendMessage exceed limit: ", se);
// TODO flush buffer
} catch (IOException ie) {
logger.error("sendMessage failed: ", ie);
}
看了concurrentWebSocketSessionDecorator的代码,方法checkSessionLimits set limitExceeded=true 并在超出缓冲区大小时抛出 SessionLimitExceededException,但我找不到任何设置 limitExceeded=false[=25= 的方法].如何刷新缓冲区并重置 limitExceeded?
public void sendMessage(WebSocketMessage<?> message) throws IOException {
if (shouldNotSend()) {
return;
}
this.buffer.add(message);
this.bufferSize.addAndGet(message.getPayloadLength());
do {
if (!tryFlushMessageBuffer()) {
if (logger.isTraceEnabled()) {
String text = String.format("Another send already in progress: " +
"session id '%s':, \"in-progress\" send time %d (ms), buffer size %d bytes",
getId(), getTimeSinceSendStarted(), getBufferSize());
logger.trace(text);
}
checkSessionLimits();
break;
}
}
while (!this.buffer.isEmpty() && !shouldNotSend());
}
它在已经 运行 tryFlushMessageBuffer()
:
中自行刷新
private boolean tryFlushMessageBuffer() throws IOException {
if (this.flushLock.tryLock()) {
try {
while (true) {
WebSocketMessage<?> message = this.buffer.poll();
if (message == null || shouldNotSend()) {
break;
}
this.bufferSize.addAndGet(message.getPayloadLength() * -1);
this.sendStartTime = System.currentTimeMillis();
getDelegate().sendMessage(message);
this.sendStartTime = 0;
}
}
finally {
this.sendStartTime = 0;
this.flushLock.unlock();
}
return true;
}
return false;
}
我明白你关于 limitExceeded
标志的观点:我们只是不去那个 tryFlushMessageBuffer()
因为我们已经存在于 shouldNotSend()
之后。那是因为你是对的 limitExceeded
永远不会被重置。
听起来真的很像一个错误。请就此事提出 JIRA:https://jira.spring.io/projects/SPR
我在我的项目中使用Spring Websocket,我发现ConcurrentWebSocketSessionDecorator在超过bufferSizeLimit时停止了,但是没有办法恢复它。
我是这样使用的:
try {
if (concurrentWebSocketSessionDecorator.isOpen()) {
concurrentWebSocketSessionDecorator.sendMessage(message);
}
} catch (SessionLimitExceededException se) {
logger.warn("sendMessage exceed limit: ", se);
// TODO flush buffer
} catch (IOException ie) {
logger.error("sendMessage failed: ", ie);
}
看了concurrentWebSocketSessionDecorator的代码,方法checkSessionLimits set limitExceeded=true 并在超出缓冲区大小时抛出 SessionLimitExceededException,但我找不到任何设置 limitExceeded=false[=25= 的方法].如何刷新缓冲区并重置 limitExceeded?
public void sendMessage(WebSocketMessage<?> message) throws IOException {
if (shouldNotSend()) {
return;
}
this.buffer.add(message);
this.bufferSize.addAndGet(message.getPayloadLength());
do {
if (!tryFlushMessageBuffer()) {
if (logger.isTraceEnabled()) {
String text = String.format("Another send already in progress: " +
"session id '%s':, \"in-progress\" send time %d (ms), buffer size %d bytes",
getId(), getTimeSinceSendStarted(), getBufferSize());
logger.trace(text);
}
checkSessionLimits();
break;
}
}
while (!this.buffer.isEmpty() && !shouldNotSend());
}
它在已经 运行 tryFlushMessageBuffer()
:
private boolean tryFlushMessageBuffer() throws IOException {
if (this.flushLock.tryLock()) {
try {
while (true) {
WebSocketMessage<?> message = this.buffer.poll();
if (message == null || shouldNotSend()) {
break;
}
this.bufferSize.addAndGet(message.getPayloadLength() * -1);
this.sendStartTime = System.currentTimeMillis();
getDelegate().sendMessage(message);
this.sendStartTime = 0;
}
}
finally {
this.sendStartTime = 0;
this.flushLock.unlock();
}
return true;
}
return false;
}
我明白你关于 limitExceeded
标志的观点:我们只是不去那个 tryFlushMessageBuffer()
因为我们已经存在于 shouldNotSend()
之后。那是因为你是对的 limitExceeded
永远不会被重置。
听起来真的很像一个错误。请就此事提出 JIRA:https://jira.spring.io/projects/SPR