Debian Codegraph @

jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionDataStore.java

raw
1 //
2 // ========================================================================
3 // Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.nosql;
20
21 import java.util.HashSet;
22 import java.util.Set;
23
24 import org.eclipse.jetty.server.session.AbstractSessionDataStore;
25 import org.eclipse.jetty.server.session.SessionData;
26
27 /**
28 * NoSqlSessionDataStore
29 */
30 public abstract class NoSqlSessionDataStore extends AbstractSessionDataStore
31 {
32
33 public class NoSqlSessionData extends SessionData
34 {
35 private Object _version;
36 private Set<String> _dirtyAttributes = new HashSet<>();
37
38 public NoSqlSessionData(String id, String cpath, String vhost, long created, long accessed, long lastAccessed, long maxInactiveMs)
39 {
40 super(id, cpath, vhost, created, accessed, lastAccessed, maxInactiveMs);
41 setVersion(new Long(0));
42 }
43
44 public void setVersion(Object v)
45 {
46 _version = v;
47 }
48
49 public Object getVersion()
50 {
51 return _version;
52 }
53
54 @Override
55 public void setDirty(String name)
56 {
57 super.setDirty(name);
58 _dirtyAttributes.add(name);
59 }
60
61 public Set<String> takeDirtyAttributes()
62 {
63 Set<String> copy = new HashSet<>(_dirtyAttributes);
64 _dirtyAttributes.clear();
65 return copy;
66 }
67
68 public Set<String> getAllAttributeNames()
69 {
70 return new HashSet<String>(_attributes.keySet());
71 }
72 }
73
74 @Override
75 public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
76 {
77 return new NoSqlSessionData(id, _context.getCanonicalContextPath(), _context.getVhost(), created, accessed, lastAccessed, maxInactiveMs);
78 }
79 }