1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.http.protocol;
22
23 import org.waarp.http.protocol.servlet.HttpAuthent;
24
25 import java.util.concurrent.ConcurrentHashMap;
26
27
28
29
30 public class HttpSessions {
31 private static final HttpSessions httpSessions = new HttpSessions();
32
33 private final ConcurrentHashMap<String, HttpResumableSession> sessions =
34 new ConcurrentHashMap<String, HttpResumableSession>();
35
36 private HttpSessions() {
37
38 }
39
40
41
42
43 public static HttpSessions getInstance() {
44 return httpSessions;
45 }
46
47
48
49
50
51
52
53
54
55
56
57
58 public synchronized HttpResumableSession getOrCreateResumableSession(
59 final HttpResumableInfo resumableInfo, final String rulename,
60 final String comment, final HttpAuthent authent) {
61 HttpResumableSession session = sessions.get(resumableInfo.getIdentifier());
62 if (session == null) {
63 session =
64 new HttpResumableSession(resumableInfo, rulename, comment, authent);
65 sessions.put(resumableInfo.getIdentifier(), session);
66 }
67 return session;
68 }
69
70
71
72
73
74
75
76
77 protected final boolean contains(final HttpResumableInfo resumableInfo) {
78 return sessions.containsKey(resumableInfo.getIdentifier());
79 }
80
81
82
83
84
85
86
87
88 public final boolean removeSession(final HttpResumableInfo resumableInfo) {
89 return sessions.remove(resumableInfo.getIdentifier()) != null;
90 }
91
92
93
94
95
96
97
98
99 public final boolean removeSession(
100 final HttpResumableSession resumableSession) {
101 return sessions.remove(
102 resumableSession.getHttpResumableInfo().getIdentifier()) != null;
103 }
104 }