1 package org.opendaylight.controller.clustersession;
3 import java.beans.PropertyChangeSupport;
4 import java.io.Serializable;
5 import java.security.Principal;
6 import java.util.ArrayList;
7 import java.util.concurrent.ConcurrentHashMap;
9 import org.apache.catalina.Manager;
10 import org.apache.catalina.SessionListener;
11 import org.apache.catalina.session.StandardSession;
12 import org.opendaylight.controller.clustersession.service.ClusterSessionService;
14 public class ClusterSession extends StandardSession implements Serializable {
16 private static final long serialVersionUID = 1L;
18 private transient ClusterSessionService sessionService;
20 public ClusterSession(Manager manager, ClusterSessionService sessionService) {
22 this.sessionService = sessionService;
25 public void setSessionService(ClusterSessionService sessionService){
26 this.sessionService = sessionService;
30 public void setAuthType(String authType) {
31 super.setAuthType(authType);
32 sessionService.updateSession(this);
36 public void setCreationTime(long time) {
37 super.setCreationTime(time);
38 sessionService.updateSession(this);
42 public void setMaxInactiveInterval(int interval) {
43 super.setMaxInactiveInterval(interval);
44 sessionService.updateSession(this);
48 public void setNew(boolean isNew) {
50 sessionService.updateSession(this);
54 public void setPrincipal(Principal principal) {
55 super.setPrincipal(principal);
56 sessionService.updateSession(this);
60 public void setValid(boolean isValid) {
61 super.setValid(isValid);
62 sessionService.updateSession(this);
66 public void access() {
68 sessionService.updateSession(this);
72 public void endAccess() {
74 sessionService.updateSession(this);
78 public void removeAttribute(String name, boolean notify) {
79 super.removeAttribute(name, notify);
80 sessionService.updateSession(this);
84 public void setAttribute(String name, Object value, boolean notify) {
85 super.setAttribute(name, value, notify);
86 sessionService.updateSession(this);
90 public void recycle() {
92 sessionService.updateSession(this);
96 public void removeNote(String name) {
97 super.removeNote(name);
98 sessionService.updateSession(this);
102 public void addSessionListener(SessionListener listener) {
103 super.addSessionListener(listener);
104 sessionService.updateSession(this);
108 public void removeSessionListener(SessionListener listener) {
109 super.removeSessionListener(listener);
110 sessionService.updateSession(this);
114 public void setNote(String name, Object value) {
115 super.setNote(name, value);
116 sessionService.updateSession(this);
120 * Certain fields inside Standard session are not serialized, We need to process them here
122 public void afterDeserialization(){
123 if (listeners == null){
124 listeners = new ArrayList<SessionListener>();
127 notes = new ConcurrentHashMap<String, Object>();
130 support = new PropertyChangeSupport(this);
135 public String toString() {
136 StringBuilder sb = new StringBuilder();
137 sb.append("ClusterSession[");
139 sb.append(", isNew : ");
141 sb.append(", isValid : ");
144 return sb.toString();
148 * These methods are added for deserialization purpose
151 public void setAuthTypeInternal(String authType){
152 this.authType = authType;
155 public void setPrincipalInternal(Principal principal){
156 this.principal = principal;
159 public void setNoteInternal(String name, Object value) {
160 notes.put(name, value);