001 /** 002 * 003 * Copyright 2003-2005 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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.Valve; 022 import org.apache.catalina.cluster.CatalinaCluster; 023 import org.apache.catalina.cluster.ClusterDeployer; 024 import org.apache.catalina.cluster.ClusterReceiver; 025 import org.apache.catalina.cluster.ClusterSender; 026 import org.apache.catalina.cluster.MembershipService; 027 import org.apache.catalina.cluster.MessageListener; 028 import org.apache.commons.logging.Log; 029 import org.apache.commons.logging.LogFactory; 030 import org.apache.geronimo.gbean.GBeanInfo; 031 import org.apache.geronimo.gbean.GBeanInfoBuilder; 032 import org.apache.geronimo.gbean.GBeanLifecycle; 033 import org.apache.geronimo.tomcat.BaseGBean; 034 import org.apache.geronimo.tomcat.ObjectRetriever; 035 import org.apache.geronimo.tomcat.ValveGBean; 036 037 /** 038 * @version $Rev: 356897 $ $Date: 2005-12-14 14:45:55 -0800 (Wed, 14 Dec 2005) $ 039 */ 040 public class CatalinaClusterGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever { 041 042 private static final Log log = LogFactory.getLog(CatalinaClusterGBean.class); 043 044 public static final String J2EE_TYPE = "Cluster"; 045 046 private final CatalinaCluster cluster; 047 048 public CatalinaClusterGBean(){ 049 cluster=null; 050 } 051 052 public CatalinaClusterGBean(String className, 053 Map initParams, 054 MembershipServiceGBean membership, 055 ReceiverGBean receiver, 056 SenderGBean sender, 057 MessageListenerGBean messageListenerChain, 058 ValveGBean tomcatValveChain, 059 ClusterDeployerGBean deployer) throws Exception { 060 061 super(); // TODO: make it an attribute 062 063 //Validate 064 if (className == null){ 065 throw new IllegalArgumentException("Must have a 'className' attribute."); 066 } 067 068 //Create the CatalinaCluster object 069 cluster = (CatalinaCluster)Class.forName(className).newInstance(); 070 071 //Set the parameters 072 setParameters(cluster, initParams); 073 074 //Add the MembershipService 075 if (membership != null){ 076 cluster.setMembershipService((MembershipService)membership.getInternalObject()); 077 } 078 079 //Add Receiver 080 if (receiver != null){ 081 cluster.setClusterReceiver((ClusterReceiver)receiver.getInternalObject()); 082 } 083 084 //Add Sender 085 if (sender != null){ 086 cluster.setClusterSender((ClusterSender)sender.getInternalObject()); 087 } 088 089 //Add the message listeners list 090 if (messageListenerChain != null){ 091 MessageListenerGBean messageListenerGBean = messageListenerChain; 092 while(messageListenerGBean != null){ 093 cluster.addClusterListener((MessageListener)messageListenerGBean.getInternalObject()); 094 messageListenerGBean = messageListenerGBean.getNextValve(); 095 } 096 } 097 098 //Add the valve list 099 if (tomcatValveChain != null){ 100 ValveGBean valveGBean = tomcatValveChain; 101 while(valveGBean != null){ 102 cluster.addValve((Valve)valveGBean.getInternalObject()); 103 valveGBean = valveGBean.getNextValve(); 104 } 105 } 106 107 //Add deployer 108 if (deployer != null){ 109 cluster.setClusterDeployer((ClusterDeployer)deployer.getInternalObject()); 110 } 111 } 112 113 public Object getInternalObject() { 114 return cluster; 115 } 116 117 public void doFail() { 118 log.warn("Failed"); 119 } 120 121 public void doStart() throws Exception { 122 log.debug("Started cluster gbean."); 123 } 124 125 public void doStop() throws Exception { 126 log.debug("Stopped cluster gbean."); 127 } 128 129 public static final GBeanInfo GBEAN_INFO; 130 131 static { 132 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("CatalinaCluster", CatalinaClusterGBean.class, J2EE_TYPE); 133 infoFactory.addAttribute("className", String.class, true); 134 infoFactory.addAttribute("initParams", Map.class, true); 135 infoFactory.addReference("Membership", MembershipServiceGBean.class, MembershipServiceGBean.J2EE_TYPE); 136 infoFactory.addReference("Receiver", ReceiverGBean.class, ReceiverGBean.J2EE_TYPE); 137 infoFactory.addReference("Sender", SenderGBean.class, SenderGBean.J2EE_TYPE); 138 infoFactory.addReference("MessageListenerChain", MessageListenerGBean.class, MessageListenerGBean.J2EE_TYPE); 139 infoFactory.addReference("TomcatValveChain", ValveGBean.class, ValveGBean.J2EE_TYPE); 140 infoFactory.addReference("ClusterDeployer", ClusterDeployerGBean.class, ClusterDeployerGBean.J2EE_TYPE); 141 infoFactory.addOperation("getInternalObject"); 142 infoFactory.setConstructor(new String[] { 143 "className", 144 "initParams", 145 "Membership", 146 "Receiver", 147 "Sender", 148 "MessageListenerChain", 149 "TomcatValveChain", 150 "ClusterDeployer" }); 151 GBEAN_INFO = infoFactory.getBeanInfo(); 152 } 153 154 public static GBeanInfo getGBeanInfo() { 155 return GBEAN_INFO; 156 } 157 }