KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > clustering > Tier


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;
19
20 import java.util.Map JavaDoc;
21
22 import javax.management.ObjectName JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /**
28  * Tier abstracts code common to different Tier impls
29  * into the same abstract base.
30  *
31  *
32  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
33  */

34 public abstract class
35   Tier
36   extends NamedMBeanImpl
37 {
38   protected Log _log=LogFactory.getLog(Tier.class);
39   protected Data _data;
40   protected Map JavaDoc _tiers;
41   protected Object JavaDoc _tier;
42
43
44   /**
45    * Makes an ObjectName for a Tier MBean with the given parameters.
46    *
47    * @param clusterName a <code>String</code> value
48    * @param nodeName a <code>String</code> value
49    * @param tierName a <code>String</code> value
50    * @return an <code>ObjectName</code> value
51    * @exception Exception if an error occurs
52    */

53   public static ObjectName JavaDoc
54     makeObjectName(String JavaDoc clusterName, String JavaDoc nodeName, String JavaDoc tierName)
55     throws Exception JavaDoc
56   {
57     return new ObjectName JavaDoc("geronimo.clustering:role=Tier,name="+tierName+",node="+nodeName+",cluster="+clusterName);
58   }
59
60   //----------------------------------------
61
// Tier
62
//----------------------------------------
63

64   protected Node _node;
65   public Node getNode(){return _node;}
66
67   public ObjectName JavaDoc getNodeObjectName(){return _node==null?null:_node.getObjectName();}
68
69   public String JavaDoc getClusterName(){return _objectName.getKeyProperty("cluster");}
70   public String JavaDoc getNodeName(){return _objectName.getKeyProperty("node");}
71
72   protected abstract Object JavaDoc alloc();
73   public abstract Object JavaDoc registerData(String JavaDoc uid, Object JavaDoc data);
74   public abstract Object JavaDoc deregisterData(String JavaDoc uid);
75
76   //----------------------------------------
77
// GeronimoMBeanTarget
78
//----------------------------------------
79

80   public boolean
81     canStart()
82   {
83     if (!super.canStart()) return false;
84
85     if (_objectName.getKeyProperty("cluster")==null)
86     {
87       _log.warn("Tier MBean name must contain a 'cluster' property");
88       return false;
89     }
90
91     if (_objectName.getKeyProperty("node")==null)
92     {
93       _log.warn("Tier MBean name must contain a 'node' property");
94       return false;
95     }
96
97     try
98     {
99       _node=(Node)_server.getAttribute(Node.makeObjectName(getClusterName(), getNodeName()), "Reference");
100       _log.debug("Node: "+_node);
101     }
102     catch (Exception JavaDoc e)
103     {
104       _log.error("could not find Node", e);
105       return false;
106     }
107
108     return true;
109   }
110
111   public synchronized void
112     doStart()
113   {
114     _log.info("starting");
115
116     // register our session map with it's Data object
117
Data data=_node.getData();
118     _tiers=data.getTiers(); // immutable, so doesn't need synchronisation
119
_tier=null;
120     synchronized (_tiers)
121     {
122       _tier=_tiers.get(getName());
123       if (_tier==null)
124       {
125     _tier=alloc();
126     _tiers.put(getName(), _tier);
127       }
128       // tier storage now initialised...
129
}
130     _log.info("Node Data:"+data);
131   }
132   /*
133   public void
134     setMBeanContext(GeronimoMBeanContext context)
135   {
136     super.setMBeanContext(context);
137     _log=LogFactory.getLog(getClass().getName()+"#"+getClusterName()+"/"+getNodeName()+"/"+getName());
138   }
139   */

140     /*
141   public static GeronimoMBeanInfo
142     getGeronimoMBeanInfo()
143   {
144     GeronimoMBeanInfo mbeanInfo=MBeanImpl.getGeronimoMBeanInfo();
145     //set target class in concrete subclass
146     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("ClusterName", true, false, "Name of this Tier's Node's Cluster"));
147     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("NodeName", true, false, "Name of this Tier's Node"));
148     mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("NodeObjectName", true, false, "ObjectName of this Tier's Node"));
149     return mbeanInfo;
150   }
151   */

152 }
153
Popular Tags