Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
747863d5
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
747863d5
编写于
12月 02, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Documented units for send-time limit and buffer-size limit
Issue: SPR-13753
上级
3fec802b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
28 deletion
+50
-28
spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java
...b/socket/handler/ConcurrentWebSocketSessionDecorator.java
+9
-3
spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java
...ork/web/socket/messaging/SubProtocolWebSocketHandler.java
+41
-25
未找到文件。
spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java
浏览文件 @
747863d5
...
...
@@ -35,9 +35,9 @@ import org.springframework.web.socket.WebSocketSession;
* only one thread can send messages at a time.
*
* <p>If a send is slow, subsequent attempts to send more messages from a different
* thread will fail to acquire the flush
Lock and the messages will be buffered instead --
*
at that time the specified buffer size limit and send time limit will be checked
* and the session closed if the limits are exceeded.
* thread will fail to acquire the flush
lock and the messages will be buffered
*
instead: At that time, the specified buffer-size limit and send-time limit will
*
be checked
and the session closed if the limits are exceeded.
*
* @author Rossen Stoyanchev
* @since 4.0.3
...
...
@@ -69,6 +69,12 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat
private
final
Lock
closeLock
=
new
ReentrantLock
();
/**
* Create a new {@code ConcurrentWebSocketSessionDecorator}.
* @param delegate the {@code WebSocketSession} to delegate to
* @param sendTimeLimit the send-time limit (milliseconds)
* @param bufferSizeLimit the buffer-size limit (number of bytes)
*/
public
ConcurrentWebSocketSessionDecorator
(
WebSocketSession
delegate
,
int
sendTimeLimit
,
int
bufferSizeLimit
)
{
super
(
delegate
);
this
.
sendTimeLimit
=
sendTimeLimit
;
...
...
spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java
浏览文件 @
747863d5
...
...
@@ -52,22 +52,20 @@ import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSe
/**
* An implementation of {@link WebSocketHandler} that delegates incoming WebSocket
* messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to
* which the sub-protocol handler can send messages from WebSocket clients to
* the application.
* <p>
* Also an implementation of {@link MessageHandler} that finds the WebSocket
* session associated with the {@link Message} and passes it, along with the message,
* to the sub-protocol handler to send messages from the application back to the
* client.
* messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to which
* the sub-protocol handler can send messages from WebSocket clients to the application.
*
* <p>Also an implementation of {@link MessageHandler} that finds the WebSocket session
* associated with the {@link Message} and passes it, along with the message, to the
* sub-protocol handler to send messages from the application back to the client.
*
* @author Rossen Stoyanchev
* @author Andy Wilkinson
* @author Artem Bilan
* @since 4.0
*/
public
class
SubProtocolWebSocketHandler
implements
WebSocketHandler
,
SubProtocolCapable
,
MessageHandler
,
SmartLifecycle
{
public
class
SubProtocolWebSocketHandler
implements
WebSocketHandler
,
SubProtocolCapable
,
MessageHandler
,
SmartLifecycle
{
/**
* Sessions connected to this handler use a sub-protocol. Hence we expect to
...
...
@@ -109,9 +107,14 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
private
volatile
boolean
running
=
false
;
/**
* Create a new {@code SubProtocolWebSocketHandler} for the given inbound and outbound channels.
* @param clientInboundChannel the inbound {@code MessageChannel}
* @param clientOutboundChannel the outbound {@code MessageChannel}
*/
public
SubProtocolWebSocketHandler
(
MessageChannel
clientInboundChannel
,
SubscribableChannel
clientOutboundChannel
)
{
Assert
.
notNull
(
clientInboundChannel
,
"
ClientInbound
Channel must not be null"
);
Assert
.
notNull
(
clientOutboundChannel
,
"
ClientOutbound
Channel must not be null"
);
Assert
.
notNull
(
clientInboundChannel
,
"
Inbound Message
Channel must not be null"
);
Assert
.
notNull
(
clientOutboundChannel
,
"
Outbound Message
Channel must not be null"
);
this
.
clientInboundChannel
=
clientInboundChannel
;
this
.
clientOutboundChannel
=
clientOutboundChannel
;
}
...
...
@@ -125,7 +128,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
public
void
setProtocolHandlers
(
List
<
SubProtocolHandler
>
protocolHandlers
)
{
this
.
protocolHandlerLookup
.
clear
();
this
.
protocolHandlers
.
clear
();
for
(
SubProtocolHandler
handler:
protocolHandlers
)
{
for
(
SubProtocolHandler
handler
:
protocolHandlers
)
{
addProtocolHandler
(
handler
);
}
}
...
...
@@ -134,7 +137,6 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
return
new
ArrayList
<
SubProtocolHandler
>(
this
.
protocolHandlers
);
}
/**
* Register a sub-protocol handler.
*/
...
...
@@ -174,7 +176,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
}
/**
*
@return the default sub-protocol handler to use
*
Return the default sub-protocol handler to use.
*/
public
SubProtocolHandler
getDefaultProtocolHandler
()
{
return
this
.
defaultProtocolHandler
;
...
...
@@ -187,23 +189,44 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
return
new
ArrayList
<
String
>(
this
.
protocolHandlerLookup
.
keySet
());
}
/**
* Specify the send-time limit (milliseconds).
* @see ConcurrentWebSocketSessionDecorator
*/
public
void
setSendTimeLimit
(
int
sendTimeLimit
)
{
this
.
sendTimeLimit
=
sendTimeLimit
;
}
/**
* Return the send-time limit (milliseconds).
*/
public
int
getSendTimeLimit
()
{
return
this
.
sendTimeLimit
;
}
/**
* Specify the buffer-size limit (number of bytes).
* @see ConcurrentWebSocketSessionDecorator
*/
public
void
setSendBufferSizeLimit
(
int
sendBufferSizeLimit
)
{
this
.
sendBufferSizeLimit
=
sendBufferSizeLimit
;
}
/**
* Return the buffer-size limit (number of bytes).
*/
public
int
getSendBufferSizeLimit
()
{
return
sendBufferSizeLimit
;
return
this
.
sendBufferSizeLimit
;
}
/**
* Return a String describing internal state and counters.
*/
public
String
getStatsInfo
()
{
return
this
.
stats
.
toString
();
}
@Override
public
boolean
isAutoStartup
()
{
return
true
;
...
...
@@ -221,14 +244,6 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
}
}
/**
* Return a String describing internal state and counters.
*/
public
String
getStatsInfo
()
{
return
this
.
stats
.
toString
();
}
@Override
public
final
void
start
()
{
Assert
.
isTrue
(
this
.
defaultProtocolHandler
!=
null
||
!
this
.
protocolHandlers
.
isEmpty
(),
"No handlers"
);
...
...
@@ -262,6 +277,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
}
}
@Override
public
void
afterConnectionEstablished
(
WebSocketSession
session
)
throws
Exception
{
// WebSocketHandlerDecorator could close the session
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录