Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
f25ccac1
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,发现更多精彩内容 >>
提交
f25ccac1
编写于
7月 05, 2013
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish SessionSubscriptionRegistry types
上级
96cb7c06
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
150 addition
and
101 deletion
+150
-101
spring-websocket/src/main/java/org/springframework/web/messaging/SessionSubscriptionRegistry.java
...gframework/web/messaging/SessionSubscriptionRegistry.java
+2
-0
spring-websocket/src/main/java/org/springframework/web/messaging/service/SimpleBrokerWebMessageHandler.java
.../web/messaging/service/SimpleBrokerWebMessageHandler.java
+2
-2
spring-websocket/src/main/java/org/springframework/web/messaging/support/CachingSessionSubscriptionRegistry.java
...messaging/support/CachingSessionSubscriptionRegistry.java
+4
-3
spring-websocket/src/main/java/org/springframework/web/messaging/support/DefaultSessionSubscriptionRegistry.java
...messaging/support/DefaultSessionSubscriptionRegistry.java
+17
-0
spring-websocket/src/test/java/org/springframework/web/messaging/support/AbstractSessionSubscriptionRegistryTests.java
...ing/support/AbstractSessionSubscriptionRegistryTests.java
+116
-0
spring-websocket/src/test/java/org/springframework/web/messaging/support/CachingSessionSubscriptionRegistryTests.java
...ging/support/CachingSessionSubscriptionRegistryTests.java
+4
-40
spring-websocket/src/test/java/org/springframework/web/messaging/support/DefaultSessionSubscriptionRegistryTests.java
...ging/support/DefaultSessionSubscriptionRegistryTests.java
+5
-56
未找到文件。
spring-websocket/src/main/java/org/springframework/web/messaging/SessionSubscriptionRegistry.java
浏览文件 @
f25ccac1
...
...
@@ -33,4 +33,6 @@ public interface SessionSubscriptionRegistry {
Set
<
String
>
getSessionSubscriptions
(
String
sessionId
,
String
destination
);
Set
<
SessionSubscriptionRegistration
>
getRegistrationsByDestination
(
String
destination
);
}
spring-websocket/src/main/java/org/springframework/web/messaging/service/SimpleBrokerWebMessageHandler.java
浏览文件 @
f25ccac1
...
...
@@ -40,7 +40,7 @@ public class SimpleBrokerWebMessageHandler extends AbstractWebMessageHandler {
private
final
MessageChannel
clientChannel
;
private
Caching
SessionSubscriptionRegistry
subscriptionRegistry
=
private
SessionSubscriptionRegistry
subscriptionRegistry
=
new
CachingSessionSubscriptionRegistry
(
new
DefaultSessionSubscriptionRegistry
());
...
...
@@ -56,7 +56,7 @@ public class SimpleBrokerWebMessageHandler extends AbstractWebMessageHandler {
public
void
setSubscriptionRegistry
(
SessionSubscriptionRegistry
subscriptionRegistry
)
{
Assert
.
notNull
(
subscriptionRegistry
,
"subscriptionRegistry is required"
);
this
.
subscriptionRegistry
=
new
CachingSessionSubscriptionRegistry
(
subscriptionRegistry
)
;
this
.
subscriptionRegistry
=
subscriptionRegistry
;
}
@Override
...
...
spring-websocket/src/main/java/org/springframework/web/messaging/support/CachingSessionSubscriptionRegistry.java
浏览文件 @
f25ccac1
...
...
@@ -28,8 +28,7 @@ import org.springframework.web.messaging.SessionSubscriptionRegistry;
/**
* A decorator for a {@link SessionSubscriptionRegistry} that intercepts subscriptions
* being added and removed, and maintains a cache that tracks registrations for a
* given destination.
* being added and removed and maintains a lookup cache of registrations by destination.
*
* @author Rossen Stoyanchev
* @since 4.0
...
...
@@ -49,7 +48,8 @@ public class CachingSessionSubscriptionRegistry implements SessionSubscriptionRe
@Override
public
SessionSubscriptionRegistration
getRegistration
(
String
sessionId
)
{
return
new
CachingSessionSubscriptionRegistration
(
this
.
delegate
.
getRegistration
(
sessionId
));
SessionSubscriptionRegistration
reg
=
this
.
delegate
.
getRegistration
(
sessionId
);
return
(
reg
!=
null
)
?
new
CachingSessionSubscriptionRegistration
(
reg
)
:
null
;
}
@Override
...
...
@@ -71,6 +71,7 @@ public class CachingSessionSubscriptionRegistry implements SessionSubscriptionRe
return
this
.
delegate
.
getSessionSubscriptions
(
sessionId
,
destination
);
}
@Override
public
Set
<
SessionSubscriptionRegistration
>
getRegistrationsByDestination
(
String
destination
)
{
return
this
.
destinationCache
.
getRegistrations
(
destination
);
}
...
...
spring-websocket/src/main/java/org/springframework/web/messaging/support/DefaultSessionSubscriptionRegistry.java
浏览文件 @
f25ccac1
...
...
@@ -16,6 +16,7 @@
package
org.springframework.web.messaging.support
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -63,4 +64,20 @@ public class DefaultSessionSubscriptionRegistry implements SessionSubscriptionRe
return
(
registration
!=
null
)
?
registration
.
getSubscriptionsByDestination
(
destination
)
:
null
;
}
/**
* The default implementation performs a lookup by destination on each registration.
* For a more efficient algorithm consider decorating an instance of this class with
* {@link CachingSessionSubscriptionRegistry}.
*/
@Override
public
Set
<
SessionSubscriptionRegistration
>
getRegistrationsByDestination
(
String
destination
)
{
Set
<
SessionSubscriptionRegistration
>
result
=
new
HashSet
<
SessionSubscriptionRegistration
>();
for
(
SessionSubscriptionRegistration
r
:
this
.
registrations
.
values
())
{
if
(
r
.
getSubscriptionsByDestination
(
destination
)
!=
null
)
{
result
.
add
(
r
);
}
}
return
result
.
isEmpty
()
?
null
:
result
;
}
}
spring-websocket/src/test/java/org/springframework/web/messaging/support/AbstractSessionSubscriptionRegistryTests.java
0 → 100644
浏览文件 @
f25ccac1
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.messaging.support
;
import
java.util.Set
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.web.messaging.SessionSubscriptionRegistration
;
import
org.springframework.web.messaging.SessionSubscriptionRegistry
;
import
static
org
.
junit
.
Assert
.*;
/**
* A test fixture for {@link AbstractSessionSubscriptionRegistry}.
*
* @author Rossen Stoyanchev
*/
public
abstract
class
AbstractSessionSubscriptionRegistryTests
{
protected
SessionSubscriptionRegistry
registry
;
@Before
public
void
setup
()
{
this
.
registry
=
createSessionSubscriptionRegistry
();
}
protected
abstract
SessionSubscriptionRegistry
createSessionSubscriptionRegistry
();
@Test
public
void
getRegistration
()
{
String
sessionId
=
"sess1"
;
assertNull
(
this
.
registry
.
getRegistration
(
sessionId
));
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
assertNotNull
(
this
.
registry
.
getRegistration
(
sessionId
));
assertEquals
(
sessionId
,
this
.
registry
.
getRegistration
(
sessionId
).
getSessionId
());
}
@Test
public
void
getOrCreateRegistration
()
{
String
sessionId
=
"sess1"
;
assertNull
(
this
.
registry
.
getRegistration
(
sessionId
));
SessionSubscriptionRegistration
registration
=
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
assertEquals
(
registration
,
this
.
registry
.
getOrCreateRegistration
(
sessionId
));
}
@Test
public
void
removeRegistration
()
{
String
sessionId
=
"sess1"
;
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
assertNotNull
(
this
.
registry
.
getRegistration
(
sessionId
));
assertEquals
(
sessionId
,
this
.
registry
.
getRegistration
(
sessionId
).
getSessionId
());
this
.
registry
.
removeRegistration
(
sessionId
);
assertNull
(
this
.
registry
.
getRegistration
(
sessionId
));
}
@Test
public
void
getSessionSubscriptions
()
{
String
sessionId
=
"sess1"
;
SessionSubscriptionRegistration
registration
=
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
registration
.
addSubscription
(
"/foo"
,
"sub1"
);
registration
.
addSubscription
(
"/foo"
,
"sub2"
);
Set
<
String
>
subscriptions
=
this
.
registry
.
getSessionSubscriptions
(
sessionId
,
"/foo"
);
assertEquals
(
"Wrong number of subscriptions "
+
subscriptions
,
2
,
subscriptions
.
size
());
assertTrue
(
subscriptions
.
contains
(
"sub1"
));
assertTrue
(
subscriptions
.
contains
(
"sub2"
));
}
@Test
public
void
getRegistrationsByDestination
()
{
SessionSubscriptionRegistration
reg1
=
this
.
registry
.
getOrCreateRegistration
(
"sess1"
);
reg1
.
addSubscription
(
"/foo"
,
"sub1"
);
SessionSubscriptionRegistration
reg2
=
this
.
registry
.
getOrCreateRegistration
(
"sess2"
);
reg2
.
addSubscription
(
"/foo"
,
"sub1"
);
Set
<
SessionSubscriptionRegistration
>
actual
=
this
.
registry
.
getRegistrationsByDestination
(
"/foo"
);
assertEquals
(
2
,
actual
.
size
());
assertTrue
(
actual
.
contains
(
reg1
));
assertTrue
(
actual
.
contains
(
reg2
));
reg1
.
removeSubscription
(
"sub1"
);
actual
=
this
.
registry
.
getRegistrationsByDestination
(
"/foo"
);
assertEquals
(
"Invalid set of registrations "
+
actual
,
1
,
actual
.
size
());
assertTrue
(
actual
.
contains
(
reg2
));
reg2
.
removeSubscription
(
"sub1"
);
actual
=
this
.
registry
.
getRegistrationsByDestination
(
"/foo"
);
assertNull
(
"Unexpected registrations "
+
actual
,
actual
);
}
}
spring-websocket/src/test/java/org/springframework/web/messaging/support/CachingSessionSubscriptionRegistryTests.java
浏览文件 @
f25ccac1
...
...
@@ -16,56 +16,20 @@
package
org.springframework.web.messaging.support
;
import
java.util.Set
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.web.messaging.SessionSubscriptionRegistration
;
import
org.springframework.web.messaging.SessionSubscriptionRegistry
;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture for {@link CachingSessionSubscriptionRegistry}.
*
* @author Rossen Stoyanchev
*/
public
class
CachingSessionSubscriptionRegistryTests
{
private
CachingSessionSubscriptionRegistry
registry
;
@Before
public
void
setup
()
{
SessionSubscriptionRegistry
delegate
=
new
DefaultSessionSubscriptionRegistry
();
this
.
registry
=
new
CachingSessionSubscriptionRegistry
(
delegate
);
}
@Test
public
void
getRegistrationsByDestination
()
{
SessionSubscriptionRegistration
reg1
=
this
.
registry
.
getOrCreateRegistration
(
"sess1"
);
reg1
.
addSubscription
(
"/foo"
,
"sub1"
);
SessionSubscriptionRegistration
reg2
=
this
.
registry
.
getOrCreateRegistration
(
"sess2"
);
reg2
.
addSubscription
(
"/foo"
,
"sub1"
);
Set
<
SessionSubscriptionRegistration
>
actual
=
this
.
registry
.
getRegistrationsByDestination
(
"/foo"
);
assertEquals
(
2
,
actual
.
size
());
assertTrue
(
actual
.
contains
(
reg1
));
assertTrue
(
actual
.
contains
(
reg2
));
reg1
.
removeSubscription
(
"sub1"
);
actual
=
this
.
registry
.
getRegistrationsByDestination
(
"/foo"
);
assertEquals
(
"Invalid set of registrations "
+
actual
,
1
,
actual
.
size
());
assertTrue
(
actual
.
contains
(
reg2
));
public
class
CachingSessionSubscriptionRegistryTests
extends
AbstractSessionSubscriptionRegistryTests
{
reg2
.
removeSubscription
(
"sub1"
);
actual
=
this
.
registry
.
getRegistrationsByDestination
(
"/foo"
);
assertNull
(
"Unexpected registrations "
+
actual
,
actual
);
@Override
protected
SessionSubscriptionRegistry
createSessionSubscriptionRegistry
()
{
return
new
CachingSessionSubscriptionRegistry
(
new
DefaultSessionSubscriptionRegistry
());
}
}
spring-websocket/src/test/java/org/springframework/web/messaging/support/DefaultSessionSubscriptionRegistryTests.java
浏览文件 @
f25ccac1
...
...
@@ -16,13 +16,7 @@
package
org.springframework.web.messaging.support
;
import
java.util.Set
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.web.messaging.SessionSubscriptionRegistration
;
import
static
org
.
junit
.
Assert
.*;
import
org.springframework.web.messaging.SessionSubscriptionRegistry
;
/**
...
...
@@ -30,57 +24,12 @@ import static org.junit.Assert.*;
*
* @author Rossen Stoyanchev
*/
public
class
DefaultSessionSubscriptionRegistryTests
{
private
DefaultSessionSubscriptionRegistry
registry
;
@Before
public
void
setup
()
{
this
.
registry
=
new
DefaultSessionSubscriptionRegistry
();
}
@Test
public
void
getRegistration
()
{
String
sessionId
=
"sess1"
;
assertNull
(
this
.
registry
.
getRegistration
(
sessionId
));
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
assertNotNull
(
this
.
registry
.
getRegistration
(
sessionId
));
assertEquals
(
sessionId
,
this
.
registry
.
getRegistration
(
sessionId
).
getSessionId
());
}
@Test
public
void
getOrCreateRegistration
()
{
String
sessionId
=
"sess1"
;
assertNull
(
this
.
registry
.
getRegistration
(
sessionId
));
SessionSubscriptionRegistration
registration
=
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
assertSame
(
registration
,
this
.
registry
.
getOrCreateRegistration
(
sessionId
));
}
@Test
public
void
removeRegistration
()
{
String
sessionId
=
"sess1"
;
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
assertNotNull
(
this
.
registry
.
getRegistration
(
sessionId
));
assertEquals
(
sessionId
,
this
.
registry
.
getRegistration
(
sessionId
).
getSessionId
());
this
.
registry
.
removeRegistration
(
sessionId
);
assertNull
(
this
.
registry
.
getRegistration
(
sessionId
));
}
public
class
DefaultSessionSubscriptionRegistryTests
extends
AbstractSessionSubscriptionRegistryTests
{
@Test
public
void
getSessionSubscriptions
()
{
String
sessionId
=
"sess1"
;
SessionSubscriptionRegistration
registration
=
this
.
registry
.
getOrCreateRegistration
(
sessionId
);
registration
.
addSubscription
(
"/foo"
,
"sub1"
);
registration
.
addSubscription
(
"/foo"
,
"sub2"
);
Set
<
String
>
subscriptions
=
this
.
registry
.
getSessionSubscriptions
(
sessionId
,
"/foo"
);
assertEquals
(
"Wrong number of subscriptions "
+
subscriptions
,
2
,
subscriptions
.
size
());
assertTrue
(
subscriptions
.
contains
(
"sub1"
));
assertTrue
(
subscriptions
.
contains
(
"sub2"
));
@Override
protected
SessionSubscriptionRegistry
createSessionSubscriptionRegistry
()
{
return
new
DefaultSessionSubscriptionRegistry
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录