KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > clustering > web > HttpSessionManager


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.clustering.web;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.management.ObjectName JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.geronimo.clustering.MBeanImpl;
28 import org.apache.geronimo.clustering.Tier;
29
30 /**
31  * An HttpSessionManager for <distributable/> webapps, which
32  * backs onto the generic Geronimo clustering framework.
33  *
34  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
35  */

36 public class
37   HttpSessionManager
38   extends MBeanImpl
39 {
40   protected Log _log=LogFactory.getLog(HttpSessionManager.class);
41   //----------------------------------------
42
// HttpSessionManager
43
//----------------------------------------
44

45   protected Map JavaDoc _sessions=new HashMap JavaDoc();
46
47   public int getSize(){return _sessions.size();}
48
49   protected Tier _tier;
50   public Tier getTier(){return _tier;}
51
52   public ObjectName JavaDoc getTierObjectName() {return _tier==null?null:_tier.getObjectName();}
53
54   protected String JavaDoc _clusterName;
55   public String JavaDoc getClusterName(){return _clusterName;}
56   public void setClusterName(String JavaDoc clusterName){_clusterName=clusterName;}
57
58   protected String JavaDoc _nodeName;
59   public String JavaDoc getNodeName(){return _nodeName;}
60   public void setNodeName(String JavaDoc nodeName){_nodeName=nodeName;}
61
62   protected String JavaDoc _tierName="web";
63   public String JavaDoc getTierName(){return _tierName;}
64   public void setTierName(String JavaDoc tierName){_tierName=tierName;}
65
66   protected String JavaDoc _contextPath;
67   public String JavaDoc getContextPath(){return _contextPath;}
68   public void setContextPath(String JavaDoc contextPath){_contextPath=contextPath;}
69
70   protected String JavaDoc _uid;
71   public String JavaDoc getUID(){return _uid;}
72
73   //----------------------------------------
74
// GeronimoMBeanTarget
75
//----------------------------------------
76

77   public boolean
78     canStart()
79   {
80     if (!super.canStart()) return false;
81
82     try
83     {
84       // find our tier
85
_tier=(Tier)_server.getAttribute(Tier.makeObjectName(getClusterName(), getNodeName(), getTierName()), "Reference");
86       _log.debug("Tier: "+_tier);
87     }
88     catch (Exception JavaDoc e)
89     {
90       _log.error("could not find Tier", e);
91       return false;
92     }
93
94     return true;
95   }
96
97   public void
98     doStart()
99   {
100     _uid=_contextPath; // TODO - what does Greg say ?
101
_log=LogFactory.getLog(getClass().getName()+"#"+getUID());
102     _log.info("starting");
103     _tier.registerData(getUID(),_sessions);
104     _log.info("sessions registered: "+getUID());
105
106       // test stuff
107
_sessions.put("aaa", new Object JavaDoc());
108     _sessions.put("bbb", new Object JavaDoc());
109     _sessions.put("ccc", new Object JavaDoc());
110   }
111
112   public void
113     doStop()
114   {
115     _log.info("stopping");
116
117     _tier.deregisterData(getUID());
118     // TODO - leave cluster
119
}
120   /*
121   public static GeronimoMBeanInfo
122     getGeronimoMBeanInfo()
123   {
124     GeronimoMBeanInfo mbeanInfo=MBeanImpl.getGeronimoMBeanInfo();
125     mbeanInfo.setTargetClass(HttpSessionManager.class);
126     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Size", true, false, "number of extant HttpSessions within this webapp"));
127     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("UID", true, false, "unique identity for this webapp within this vm"));
128     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("TierObjectName", true, false, "ObjectName of Tier to which this webapp is attached"));
129
130     // TODO - these should probably become RO...
131     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("ClusterName", true, true, "name of Cluster upon which this webapp is deployed"));
132     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("NodeName", true, true, "name of Cluster Node upon which this webapp is deployed"));
133     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("TierName", true, true, "name of Tier to which this webapp is attached"));
134     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("ContextPath", true, true, "context path at which this webapp is deployed"));
135
136     return mbeanInfo;
137   }
138   */

139 }
140
Popular Tags