Skip to content

Commit 8aac395

Browse files
author
Micha Kiener
committed
SPR-6419, manager implementation
1 parent 38415e9 commit 8aac395

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,22 @@ public boolean mustBeRoot() {
115115
}
116116

117117
/**
118+
* Returns <code>true</code>, if the given, current conversation must be
119+
* ended as a new one having this join mode was created. This is the case,
120+
* if the current one is not a switched one and if the join mode is either
121+
* new or switched.
122+
*
123+
* @param currentConversation the current conversation to check whether it
124+
* should be ended implicitly according to this join mode
118125
* @return <code>true</code>, if an already existing conversation must be
119126
* ended before creating a new one
120127
*/
121-
public boolean mustEndCurrent() {
122-
return (this == NEW);
128+
public boolean mustEndCurrent(Conversation currentConversation) {
129+
if (currentConversation != null && currentConversation.isSwitched()) {
130+
return false;
131+
}
132+
133+
return (this == NEW || this == SWITCHED);
123134
}
124135

125136
/**

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,38 +216,39 @@ public Conversation beginConversation(boolean temporary, JoinMode joinMode) {
216216
// set the temporary flag of the newly created conversation and also
217217
// assign it a newly created, unique id
218218
newConversation.setTemporary(temporary);
219+
newConversation.setSwitched(joinMode == JoinMode.SWITCHED);
219220
newConversation.setId(createNewConversationId());
220221

221222
store.registerConversation(newConversation);
222223
}
223224

224225
// check, if there is a current conversation
225226
if (currentConversation != null) {
227+
// check, if nesting is not allowed and throw an exception if so
228+
if (joinMode.mustBeRoot()) {
229+
throw new IllegalStateException(
230+
"Beginning a new conversation while one is still in progress and nesting is not allowed is not possible.");
231+
}
232+
226233
if (joinMode.mustBeJoined()) {
227234
currentConversation.joinConversation();
228235
return currentConversation;
229236
}
230237

231-
if (joinMode.mustBeSwitched()) {
238+
if (joinMode.mustBeSwitched() && currentConversation.isSwitched()) {
232239
currentConversation.deactivated(ConversationDeactivationType.NEW_SWITCHED, newConversation);
233240
}
234241

235242
// check, if the current one must be ended before creating a new one
236-
if (joinMode.mustEndCurrent()) {
243+
if (joinMode.mustEndCurrent(currentConversation)) {
237244
endConversation(currentConversation, ConversationEndingType.TRANSCRIBED);
238245
}
239246

240-
// check, if nesting is not allowed and throw an exception if so
241-
if (joinMode.mustBeRoot()) {
242-
throw new IllegalStateException(
243-
"Beginning a new conversation while one is still in progress and nesting is not allowed is not possible.");
244-
}
245-
246247
// nest the new conversation to the current one, if available and
247248
// set the current one as the parent of the new one
248249
if (joinMode.mustBeNested()) {
249250
newConversation.setParentConversation(currentConversation, joinMode.mustBeIsolated());
250-
newConversation.deactivated(joinMode.mustBeIsolated() ? ConversationDeactivationType.NEW_ISOLATED
251+
currentConversation.deactivated(joinMode.mustBeIsolated() ? ConversationDeactivationType.NEW_ISOLATED
251252
: ConversationDeactivationType.NEW_NESTED, newConversation);
252253
}
253254
}

0 commit comments

Comments
 (0)