Skip to content

Commit d4e28cd

Browse files
author
Marcel Overdijk
committed
Added a no operation session manager
1 parent c6f8be5 commit d4e28cd

2 files changed

Lines changed: 106 additions & 2 deletions

File tree

rivescript-core/src/main/java/com/rivescript/session/ConcurrentHashMapSessionManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import static com.rivescript.session.ThawAction.THAW;
3333

3434
/**
35-
* Implements the default in-memory session store for RiveScript, based on a {@link ConcurrentHashMap}.
35+
* Implements the default in-memory {@link SessionManager} for RiveScript, based on a {@link ConcurrentHashMap}.
3636
*
3737
* @author Noah Petherbridge
3838
* @author Marcel Overdijk
@@ -184,7 +184,7 @@ private UserData cloneUser(UserData data) {
184184
* <p>
185185
* This mostly just means the topic is set to "random".
186186
*
187-
* @return
187+
* @return the user data
188188
*/
189189
private UserData defaultSession() {
190190
UserData userData = new UserData();
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2016 the original author or authors.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package com.rivescript.session;
24+
25+
26+
import java.util.Collections;
27+
import java.util.Map;
28+
29+
/**
30+
* A no operation {@link SessionManager} suitable for disabling session storage.
31+
*
32+
* @author Noah Petherbridge
33+
* @author Marcel Overdijk
34+
*/
35+
public class NoOpSessionManager implements SessionManager {
36+
37+
@Override
38+
public UserData init(String username) {
39+
return noOpSession();
40+
}
41+
42+
@Override
43+
public void set(String username, String name, String value) {
44+
}
45+
46+
@Override
47+
public void set(String username, Map<String, String> vars) {
48+
}
49+
50+
@Override
51+
public void addHistory(String username, String input, String reply) {
52+
}
53+
54+
@Override
55+
public void setLastMatch(String username, String trigger) {
56+
}
57+
58+
@Override
59+
public String get(String username, String name) {
60+
return null;
61+
}
62+
63+
@Override
64+
public UserData get(String username) {
65+
return null;
66+
}
67+
68+
@Override
69+
public Map<String, UserData> getAll() {
70+
return Collections.emptyMap();
71+
}
72+
73+
@Override
74+
public String getLastMatch(String username) {
75+
return null;
76+
}
77+
78+
@Override
79+
public History getHistory(String username) {
80+
return new History();
81+
}
82+
83+
@Override
84+
public void clear(String username) {
85+
}
86+
87+
@Override
88+
public void clearAll() {
89+
}
90+
91+
@Override
92+
public void freeze(String username) {
93+
}
94+
95+
@Override
96+
public void thaw(String username, ThawAction action) {
97+
}
98+
99+
private UserData noOpSession() {
100+
UserData userData = new UserData();
101+
userData.setLastMatch("");
102+
return userData;
103+
}
104+
}

0 commit comments

Comments
 (0)