001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.tomcat.cluster;
017:
018: import java.util.Map;
019:
020: import org.apache.catalina.Valve;
021: import org.apache.catalina.ha.CatalinaCluster;
022: import org.apache.catalina.ha.ClusterDeployer;
023: import org.apache.catalina.ha.ClusterListener;
024: import org.apache.catalina.tribes.Channel;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.geronimo.gbean.GBeanInfo;
028: import org.apache.geronimo.gbean.GBeanInfoBuilder;
029: import org.apache.geronimo.gbean.GBeanLifecycle;
030: import org.apache.geronimo.tomcat.BaseGBean;
031: import org.apache.geronimo.tomcat.ObjectRetriever;
032: import org.apache.geronimo.tomcat.ValveGBean;
033:
034: /**
035: * @version $Rev: 511136 $ $Date: 2007-02-23 14:12:09 -0800 (Fri, 23 Feb 2007) $
036: */
037: public class CatalinaClusterGBean extends BaseGBean implements
038: GBeanLifecycle, ObjectRetriever {
039:
040: private static final Log log = LogFactory
041: .getLog(CatalinaClusterGBean.class);
042:
043: public static final String J2EE_TYPE = "Cluster";
044:
045: private final CatalinaCluster cluster;
046:
047: public CatalinaClusterGBean() {
048: cluster = null;
049: }
050:
051: public CatalinaClusterGBean(String className, Map initParams,
052: ClusterListenerGBean clusterListenerChain,
053: ValveGBean tomcatValveChain, ClusterDeployerGBean deployer,
054: ChannelGBean channel) throws Exception {
055:
056: super (); // TODO: make it an attribute
057:
058: //Validate
059: if (className == null) {
060: throw new IllegalArgumentException(
061: "Must have a 'className' attribute.");
062: }
063:
064: //Create the CatalinaCluster object
065: cluster = (CatalinaCluster) Class.forName(className)
066: .newInstance();
067:
068: //Set the parameters
069: setParameters(cluster, initParams);
070:
071: //Add the cluster listeners list
072: if (clusterListenerChain != null) {
073: ClusterListenerGBean clusterListenerGBean = clusterListenerChain;
074: while (clusterListenerGBean != null) {
075: cluster
076: .addClusterListener((ClusterListener) clusterListenerGBean
077: .getInternalObject());
078: clusterListenerGBean = clusterListenerGBean
079: .getNextValve();
080: }
081: }
082:
083: //Add the valve list
084: if (tomcatValveChain != null) {
085: ValveGBean valveGBean = tomcatValveChain;
086: while (valveGBean != null) {
087: cluster
088: .addValve((Valve) valveGBean
089: .getInternalObject());
090: valveGBean = valveGBean.getNextValve();
091: }
092: }
093:
094: //Add deployer
095: if (deployer != null) {
096: cluster.setClusterDeployer((ClusterDeployer) deployer
097: .getInternalObject());
098: }
099:
100: //Add channel
101: if (channel != null) {
102: cluster.setChannel((Channel) channel.getInternalObject());
103: }
104: }
105:
106: public Object getInternalObject() {
107: return cluster;
108: }
109:
110: public void doFail() {
111: log.warn("Failed");
112: }
113:
114: public void doStart() throws Exception {
115: log.debug("Started cluster gbean.");
116: }
117:
118: public void doStop() throws Exception {
119: log.debug("Stopped cluster gbean.");
120: }
121:
122: public static final GBeanInfo GBEAN_INFO;
123:
124: static {
125: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
126: "CatalinaCluster", CatalinaClusterGBean.class,
127: J2EE_TYPE);
128: infoFactory.addAttribute("className", String.class, true);
129: infoFactory.addAttribute("initParams", Map.class, true);
130: infoFactory.addReference("ClusterListenerChain",
131: ClusterListenerGBean.class,
132: ClusterListenerGBean.J2EE_TYPE);
133: infoFactory.addReference("TomcatValveChain", ValveGBean.class,
134: ValveGBean.J2EE_TYPE);
135: infoFactory.addReference("ClusterDeployer",
136: ClusterDeployerGBean.class,
137: ClusterDeployerGBean.J2EE_TYPE);
138: infoFactory.addReference("Channel", ChannelGBean.class,
139: ChannelGBean.J2EE_TYPE);
140: infoFactory.addOperation("getInternalObject", "Object");
141: infoFactory.setConstructor(new String[] { "className",
142: "initParams", "ClusterListenerChain",
143: "TomcatValveChain", "ClusterDeployer", "Channel" });
144: GBEAN_INFO = infoFactory.getBeanInfo();
145: }
146:
147: public static GBeanInfo getGBeanInfo() {
148: return GBEAN_INFO;
149: }
150: }
|