Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
5e2b340a
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 搜索 >>
提交
5e2b340a
编写于
12月 30, 2009
作者:
M
Micha Kiener
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-6421, conversation store
上级
0dbdf683
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
157 addition
and
1 deletion
+157
-1
org.springframework.context/src/main/java/org/springframework/conversation/manager/AbstractConversationStore.java
...ework/conversation/manager/AbstractConversationStore.java
+155
-0
org.springframework.context/src/main/java/org/springframework/conversation/manager/ConversationStore.java
...ringframework/conversation/manager/ConversationStore.java
+2
-1
未找到文件。
org.springframework.context/src/main/java/org/springframework/conversation/manager/AbstractConversationStore.java
0 → 100644
浏览文件 @
5e2b340a
/*
* Copyright 2002-2008 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.conversation.manager
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.conversation.Conversation
;
/**
* An abstract base implementation for the {@link ConversationStore} interface
* used by the {@link ConversationManager} to register conversation objects
* within. This implementation supports the basic mechanism and exposes two
* methods to be implemented by concrete stores to provide the conversation map
* and optionally a fallback map used, if the default one is not reachable. This
* could be the case, if the default one is session scoped and the conversation
* management is used from within a non web thread so the fallback map could be
* a thread attached map using a {@link ThreadLocal} for instance.
*
* @author Micha Kiener
* @since 3.1
*/
public
abstract
class
AbstractConversationStore
implements
ConversationStore
{
/**
* Flag indicating whether to use the fallback conversation map, if the
* default one is not reachable, see {@link #getConversationMapSafe()} for
* more information. Default is <code>true</code>.
*/
private
boolean
useFallbackMap
;
/**
* Default constructor, turning the fallback map on by default.
*/
public
AbstractConversationStore
()
{
useFallbackMap
=
true
;
}
/**
* @see org.springframework.conversation.manager.ConversationStore#getConversation(java.lang.String)
*/
public
Conversation
getConversation
(
String
id
)
{
Map
<
String
,
Conversation
>
map
=
getConversationMapSafe
();
return
map
.
get
(
id
);
}
/**
* @see org.springframework.conversation.manager.ConversationStore#getConversations()
*/
public
List
<
Conversation
>
getConversations
()
{
Map
<
String
,
Conversation
>
map
=
getConversationMapSafe
();
return
new
ArrayList
<
Conversation
>(
map
.
values
());
}
/**
* @see org.springframework.conversation.manager.ConversationStore#registerConversation(org.springframework.conversation.Conversation)
*/
public
void
registerConversation
(
Conversation
conversation
)
{
Map
<
String
,
Conversation
>
map
=
getConversationMapSafe
();
map
.
put
(
conversation
.
getId
(),
conversation
);
}
/**
* @see org.springframework.conversation.manager.ConversationStore#removeConversation(java.lang.String)
*/
public
Conversation
removeConversation
(
String
id
)
{
Map
<
String
,
Conversation
>
map
=
getConversationMapSafe
();
return
map
.
remove
(
id
);
}
/**
* @see org.springframework.conversation.manager.ConversationStore#size()
*/
public
int
size
()
{
return
getConversationMapSafe
().
size
();
}
/**
* Internal method returning the conversation map in a safe way as the
* method {@link #getConversationMap()} could actually raise an exception,
* if the method is injected and the map is currently not available (for
* instance if the map is in session scope and this method is invoked from a
* non web thread). If the fallback mechanism is turned on (as done by
* default), in this case the fallback map as being returned by
* {@link #getConversationMapFallback()} is returned in order to use the
* conversation management in a non web thread as well (for instance for
* asynchronous tasks or batch stuff).
*
* @return the conversation map to be used currently
*/
protected
Map
<
String
,
Conversation
>
getConversationMapSafe
()
{
try
{
return
getConversationMap
();
}
catch
(
Exception
e
)
{
// if the map is not reachable and fallback is on, return the
// fallback map
if
(
isUseFallbackMap
())
{
return
getConversationMapFallback
();
}
}
throw
new
IllegalAccessError
(
"The conversation map to store conversations in is currently not available."
);
}
/**
* Returns the map used to store the conversations in using their id as the
* key. This method can either be injected by providing a map implementation
* in session or window scope or might be implemented.
*
* @return the map for storing the conversations
*/
public
abstract
Map
<
String
,
Conversation
>
getConversationMap
();
/**
* Returns the conversation map used if the default one returned by
* {@link #getConversationMap()} is not available. This could be the case,
* if the default one is session based and the conversation management is
* used from within a non web thread. This method must always be able to
* provide a map, if the conversation management should be available in any
* situation.
*
* @return the fallback conversation map
*/
public
abstract
Map
<
String
,
Conversation
>
getConversationMapFallback
();
/**
* @param useFallbackMap <code>true</code>, if the fallback map should be
* used in the case the default one is not reachable, <code>false</code> to
* raise an exception in that case
*/
public
void
setUseFallbackMap
(
boolean
useFallbackMap
)
{
this
.
useFallbackMap
=
useFallbackMap
;
}
/**
* @return the <code>true</code>, if the fallback map should be used in the
* case the default one is not reachable
*/
public
boolean
isUseFallbackMap
()
{
return
useFallbackMap
;
}
}
org.springframework.context/src/main/java/org/springframework/conversation/manager/ConversationStore.java
浏览文件 @
5e2b340a
...
...
@@ -76,7 +76,8 @@ public interface ConversationStore {
/**
* Returns a list of available conversations in the current store which have
* been registered using the {@link #registerConversation(Conversation)}
* method.
* method. The list being returned is not backed by the store so it can be
* modified safely from outside.
*
* @return the list of available conversations or an empty list, never
* <code>null</code>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录