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 */
017 package org.apache.geronimo.tomcat.cluster;
018
019 import java.util.Map;
020
021 import org.apache.catalina.ha.ClusterDeployer;
022 import org.apache.commons.logging.Log;
023 import org.apache.commons.logging.LogFactory;
024 import org.apache.geronimo.gbean.GBeanInfo;
025 import org.apache.geronimo.gbean.GBeanInfoBuilder;
026 import org.apache.geronimo.gbean.GBeanLifecycle;
027 import org.apache.geronimo.tomcat.BaseGBean;
028 import org.apache.geronimo.tomcat.ObjectRetriever;
029
030 public class ClusterDeployerGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
031
032 private static final Log log = LogFactory
033 .getLog(ClusterDeployerGBean.class);
034
035 public static final String J2EE_TYPE = "ClusterDeployer";
036
037 protected final ClusterDeployer deployer;
038
039 public ClusterDeployerGBean() {
040 deployer = null;
041 }
042
043 protected ClusterDeployerGBean(String className) throws Exception{
044 super();
045 deployer = (ClusterDeployer)Class.forName(className).newInstance();
046 }
047
048 public ClusterDeployerGBean(String className, Map initParams) throws Exception {
049
050 super(); // TODO: make it an attribute
051
052 // Validate
053 if (className == null) {
054 throw new IllegalArgumentException(
055 "Must have a 'className' attribute.");
056 }
057
058 // Create the CatalinaCluster object
059 deployer = (ClusterDeployer) Class.forName(className).newInstance();
060
061 // Set the parameters
062 setParameters(deployer, initParams);
063
064 }
065
066 public Object getInternalObject() {
067 return deployer;
068 }
069
070 public void doFail() {
071 log.warn("Failed: "+ deployer.getClass().getName());
072 }
073
074 public void doStart() throws Exception {
075 log.debug("Started "+ deployer.getClass().getName() +" gbean.");
076 }
077
078 public void doStop() throws Exception {
079 log.debug("Stopped " + deployer.getClass().getName() + " gbean.");
080 }
081
082 public static final GBeanInfo GBEAN_INFO;
083
084 static {
085 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("ClusterDeployer", ClusterDeployerGBean.class, J2EE_TYPE);
086 infoFactory.addAttribute("className", String.class, true);
087 infoFactory.addAttribute("initParams", Map.class, true);
088 infoFactory.addOperation("getInternalObject", "Object");
089 infoFactory.setConstructor(new String[] { "className", "initParams" });
090 GBEAN_INFO = infoFactory.getBeanInfo();
091 }
092
093 public static GBeanInfo getGBeanInfo() {
094 return GBEAN_INFO;
095 }
096 }