dc93700c0d1e338c0045334936be6166e0fc2c37
[controller.git] / opendaylight / samples / clustersession / src / main / java / org / opendaylight / controller / clustersession / ClusterSession.java
1 package org.opendaylight.controller.clustersession;
2
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;
8
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;
13
14 public class ClusterSession extends StandardSession implements Serializable {
15
16   private static final long serialVersionUID = 1L;
17
18   private transient ClusterSessionService sessionService;
19
20   public ClusterSession(Manager manager, ClusterSessionService sessionService) {
21     super(manager);
22     this.sessionService = sessionService;
23   }
24
25   public void setSessionService(ClusterSessionService sessionService){
26     this.sessionService = sessionService;
27   }
28
29   @Override
30   public void setAuthType(String authType) {
31     super.setAuthType(authType);
32     sessionService.updateSession(this);
33   }
34
35   @Override
36   public void setCreationTime(long time) {
37     super.setCreationTime(time);
38     sessionService.updateSession(this);
39   }
40
41   @Override
42   public void setMaxInactiveInterval(int interval) {
43     super.setMaxInactiveInterval(interval);
44     sessionService.updateSession(this);
45   }
46
47   @Override
48   public void setNew(boolean isNew) {
49     super.setNew(isNew);
50     sessionService.updateSession(this);
51   }
52
53   @Override
54   public void setPrincipal(Principal principal) {
55     super.setPrincipal(principal);
56     sessionService.updateSession(this);
57   }
58
59   @Override
60   public void setValid(boolean isValid) {
61     super.setValid(isValid);
62     sessionService.updateSession(this);
63   }
64
65   @Override
66   public void access() {
67     super.access();
68     sessionService.updateSession(this);
69   }
70
71   @Override
72   public void endAccess() {
73     super.endAccess();
74     sessionService.updateSession(this);
75   }
76
77   @Override
78   public void removeAttribute(String name, boolean notify) {
79     super.removeAttribute(name, notify);
80     sessionService.updateSession(this);
81   }
82
83   @Override
84   public void setAttribute(String name, Object value, boolean notify) {
85     super.setAttribute(name, value, notify);
86     sessionService.updateSession(this);
87   }
88
89   @Override
90   public void recycle() {
91     super.recycle();
92     sessionService.updateSession(this);
93   }
94
95   @Override
96   public void removeNote(String name) {
97     super.removeNote(name);
98     sessionService.updateSession(this);
99   }
100
101   @Override
102   public void addSessionListener(SessionListener listener) {
103     super.addSessionListener(listener);
104     sessionService.updateSession(this);
105   }
106
107   @Override
108   public void removeSessionListener(SessionListener listener) {
109     super.removeSessionListener(listener);
110     sessionService.updateSession(this);
111   }
112
113   @Override
114   public void setNote(String name, Object value) {
115     super.setNote(name, value);
116     sessionService.updateSession(this);
117   }
118
119   /*
120    * Certain fields inside Standard session are not serialized, We need to process them here
121    */
122    public void afterDeserialization(){
123     if (listeners == null){
124       listeners = new ArrayList<SessionListener>();
125     }
126     if (notes == null){
127       notes = new ConcurrentHashMap<String, Object>();
128     }
129     if(support == null){
130       support = new PropertyChangeSupport(this);
131     }
132    }
133
134    @Override
135    public String toString() {
136      StringBuilder sb = new StringBuilder();
137      sb.append("ClusterSession[");
138      sb.append(id);
139      sb.append(", isNew : ");
140      sb.append(isNew);
141      sb.append(", isValid : ");
142      sb.append(isValid);
143      sb.append("]");
144      return sb.toString();
145    }
146
147    /*
148     * These methods are added for deserialization purpose
149     */
150
151    public void setAuthTypeInternal(String authType){
152      this.authType = authType;
153    }
154
155    public void setPrincipalInternal(Principal principal){
156      this.principal = principal;
157    }
158
159    public void setNoteInternal(String name, Object value) {
160      notes.put(name, value);
161    }
162 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.