Skip to content

Commit e192f60

Browse files
author
Micha Kiener
committed
SPR-6419, manager implementation
1 parent 21e9bfd commit e192f60

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

org.springframework.context/src/main/java/org/springframework/conversation/JoinMode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public enum JoinMode {
7474

7575
/**
7676
* This mode is the same as {@link #ROOT} or {@link #NEW}, but it will not
77-
* terminate the current one but rather switch it in order to still be
78-
* available but the newly created one will become the current conversation.
79-
* Using this mode assumes the manual ending and removing of the switched
80-
* conversation as it is not terminated automatically, unless there is a
81-
* timeout.
77+
* implicitly ended as there might be more than one active, switched
78+
* conversations. If there is a current, non-switched conversation, it is
79+
* implicitly ended, however, if a switched one is the current one and a new
80+
* one is created, it is not ended, so ending a switched conversation must
81+
* either be cone manually or by specifying a timeout.
8282
*/
8383
SWITCHED;
8484

org.springframework.context/src/main/java/org/springframework/conversation/manager/ConversationManagerImpl.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,27 +201,31 @@ public void finalEndConversation(Conversation conversation, ConversationEndingTy
201201
* org.springframework.conversation.JoinMode)
202202
*/
203203
public Conversation beginConversation(boolean temporary, JoinMode joinMode) {
204-
// create a new conversation and initialize it
205-
MutableConversation newConversation = createNewConversation();
204+
ConversationResolver resolver = getConversationResolver();
205+
ConversationStore store = getConversationStore();
206+
MutableConversation currentConversation = silentlyCastConversation(getCurrentConversation());
207+
MutableConversation newConversation = null;
206208

207-
// set the default timeout according the setup of this manager
208-
newConversation.setTimeout(getDefaultConversationTimeout());
209+
if (currentConversation == null || !joinMode.mustBeJoined()) {
210+
// create a new conversation and initialize it
211+
newConversation = createNewConversation();
209212

210-
// set the temporary flag of the newly created conversation and also
211-
// assign it a newly created, unique id
212-
newConversation.setTemporary(temporary);
213-
newConversation.setId(createNewConversationId());
213+
// set the default timeout according the setup of this manager
214+
newConversation.setTimeout(getDefaultConversationTimeout());
214215

215-
ConversationResolver resolver = getConversationResolver();
216-
ConversationStore store = getConversationStore();
217-
store.registerConversation(newConversation);
216+
// set the temporary flag of the newly created conversation and also
217+
// assign it a newly created, unique id
218+
newConversation.setTemporary(temporary);
219+
newConversation.setId(createNewConversationId());
218220

219-
MutableConversation currentConversation = silentlyCastConversation(getCurrentConversation());
221+
store.registerConversation(newConversation);
222+
}
220223

221224
// check, if there is a current conversation
222225
if (currentConversation != null) {
223226
if (joinMode.mustBeJoined()) {
224227
currentConversation.joinConversation();
228+
return currentConversation;
225229
}
226230

227231
if (joinMode.mustBeSwitched()) {
@@ -248,8 +252,8 @@ public Conversation beginConversation(boolean temporary, JoinMode joinMode) {
248252
}
249253
}
250254

251-
// make the newly created conversation the current one, invoke listeners
252-
// and return it
255+
// make the newly created conversation the current one, invoke
256+
// listeners and return it
253257
resolver.setCurrentConversationId(newConversation.getId());
254258
newConversation.activated(joinMode.mustBeSwitched() ? ConversationActivationType.SWITCHED
255259
: ConversationActivationType.NEW, currentConversation);

0 commit comments

Comments
 (0)