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.ClusterListener;
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 ClusterListenerGBean extends BaseGBean implements
030: GBeanLifecycle, ObjectRetriever {
031:
032: private static final Log log = LogFactory
033: .getLog(ClusterListenerGBean.class);
034:
035: public static final String J2EE_TYPE = "ClusterListener";
036:
037: private final ClusterListener listener;
038: private final ClusterListenerGBean nextListener;
039: private final String className;
040:
041: public ClusterListenerGBean() {
042: listener = null;
043: nextListener = null;
044: className = null;
045: }
046:
047: public ClusterListenerGBean(String className, Map initParams,
048: ClusterListenerGBean nextListener) throws Exception {
049:
050: //Validate
051: if (className == null) {
052: throw new IllegalArgumentException(
053: "className cannot be null.");
054: }
055:
056: if (nextListener != null) {
057: if (!(nextListener.getInternalObject() instanceof ClusterListener)) {
058: throw new IllegalArgumentException(
059: "nextListener is not of type ClusterListener.");
060: }
061:
062: this .nextListener = nextListener;
063: } else {
064: this .nextListener = null;
065: }
066:
067: this .className = className;
068:
069: //Create the listener object
070: listener = (ClusterListener) Class.forName(className)
071: .newInstance();
072:
073: //Set the parameters
074: setParameters(listener, initParams);
075:
076: }
077:
078: public void doStart() throws Exception {
079: log.debug(className + " started.");
080: }
081:
082: public void doStop() throws Exception {
083: log.debug(className + " stopped.");
084: }
085:
086: public void doFail() {
087: log.warn(className + " failed.");
088: }
089:
090: public Object getInternalObject() {
091: return listener;
092: }
093:
094: public ClusterListenerGBean getNextValve() {
095: return nextListener;
096: }
097:
098: public static final GBeanInfo GBEAN_INFO;
099:
100: static {
101: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
102: "ClusterListener", ClusterListenerGBean.class,
103: J2EE_TYPE);
104: infoFactory.addAttribute("className", String.class, true);
105: infoFactory.addAttribute("initParams", Map.class, true);
106: infoFactory.addReference("NextListener",
107: ClusterListenerGBean.class, J2EE_TYPE);
108: infoFactory.addOperation("getInternalObject", "Object");
109: infoFactory
110: .addOperation("getNextValve", "ClusterListenerGBean");
111: infoFactory.setConstructor(new String[] { "className",
112: "initParams", "NextListener" });
113: GBEAN_INFO = infoFactory.getBeanInfo();
114: }
115:
116: public static GBeanInfo getGBeanInfo() {
117: return GBEAN_INFO;
118: }
119:
120: }
|