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