KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > tomcat > tc6 > session > JBossCacheClusteredSession


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22
23 package org.jboss.web.tomcat.tc6.session;
24
25 /**
26  * Common superclass of ClusteredSession types that use JBossCache
27  * as their distributed cache.
28  *
29  * @author Brian Stansberry
30  *
31  * @version $Revision: 56542 $
32  */

33 public abstract class JBossCacheClusteredSession extends ClusteredSession
34 {
35    /**
36     * Our proxy to the cache.
37     */

38    protected transient JBossCacheService proxy_;
39    
40    /**
41     * Create a new JBossCacheClusteredSession.
42     *
43     * @param manager
44     * @param useJK
45     */

46    public JBossCacheClusteredSession(JBossCacheManager manager)
47    {
48       super(manager, manager.getUseJK());
49       establishProxy();
50    }
51
52    /**
53     * Initialize fields marked as transient after loading this session
54     * from the distributed store
55     *
56     * @param manager the manager for this session
57     */

58    public void initAfterLoad(AbstractJBossManager manager)
59    {
60       // Our manager and proxy may have been lost if we were recycled,
61
// so reestablish them
62
setManager(manager);
63       establishProxy();
64
65       // Since attribute map may be transient, we may need to populate it
66
// from the underlying store.
67
populateAttributes();
68       
69       // Notify all attributes of type HttpSessionActivationListener (SRV 7.7.2)
70
this.activate();
71       
72       // We are no longer outdated vis a vis distributed cache
73
clearOutdated();
74    }
75    
76    /**
77     * Gets a reference to the JBossCacheService.
78     */

79    protected void establishProxy()
80    {
81       if (proxy_ == null)
82       {
83          proxy_ = ((JBossCacheManager) manager).getCacheService();
84
85          // still null???
86
if (proxy_ == null)
87          {
88             throw new RuntimeException JavaDoc("JBossCacheClusteredSession: Cache service is null.");
89          }
90       }
91    }
92    
93    protected abstract void populateAttributes();
94
95    /**
96     * Override the superclass to additionally reset this class' fields.
97     * <p>
98     * <strong>NOTE:</strong> It is not anticipated that this method will be
99     * called on a ClusteredSession, but we are overriding the method to be
100     * thorough.
101     * </p>
102     */

103    public void recycle()
104    {
105       super.recycle();
106       
107       proxy_ = null;
108    }
109
110    /**
111     * Increment our version and place ourself in the cache.
112     */

113    public synchronized void processSessionRepl()
114    {
115       // Replicate the session.
116
if (log.isTraceEnabled())
117       {
118          log.trace("processSessionRepl(): session is dirty. Will increment " +
119                    "version from: " + getVersion() + " and replicate.");
120       }
121       this.incrementVersion();
122       proxy_.putSession(realId, this);
123       
124       sessionAttributesDirty = false;
125       sessionMetadataDirty = false;
126       
127       updateLastReplicated();
128    }
129
130    /**
131     * Overrides the superclass impl by doing nothing if <code>localCall</code>
132     * is <code>false</code>. The JBossCacheManager will already be aware of
133     * a remote invalidation and will handle removal itself.
134     */

135    protected void removeFromManager(boolean localCall, boolean localOnly)
136    {
137       if (localCall)
138       {
139          super.removeFromManager(localCall, localOnly);
140       }
141    }
142    
143    
144    protected Object JavaDoc removeAttributeInternal(String JavaDoc name, boolean localCall, boolean localOnly)
145    {
146       return removeJBossInternalAttribute(name, localCall, localOnly);
147    }
148
149    protected Object JavaDoc removeJBossInternalAttribute(String JavaDoc name)
150    {
151       throw new UnsupportedOperationException JavaDoc("removeJBossInternalAttribute(String) " +
152             "is not supported by JBossCacheClusteredSession; use " +
153             "removeJBossInternalAttribute(String, boolean, boolean");
154    }
155
156    protected abstract Object JavaDoc removeJBossInternalAttribute(String JavaDoc name,
157                                                           boolean localCall,
158                                                           boolean localOnly);
159
160 }
161
Popular Tags