1 /**
2 *
3 * Copyright 2003-2005 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.geronimo.tomcat.cluster;
18
19 import java.util.Map;
20
21 import org.apache.catalina.Valve;
22 import org.apache.catalina.cluster.CatalinaCluster;
23 import org.apache.catalina.cluster.ClusterDeployer;
24 import org.apache.catalina.cluster.ClusterReceiver;
25 import org.apache.catalina.cluster.ClusterSender;
26 import org.apache.catalina.cluster.MembershipService;
27 import org.apache.catalina.cluster.MessageListener;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.geronimo.gbean.GBeanInfo;
31 import org.apache.geronimo.gbean.GBeanInfoBuilder;
32 import org.apache.geronimo.gbean.GBeanLifecycle;
33 import org.apache.geronimo.tomcat.BaseGBean;
34 import org.apache.geronimo.tomcat.ObjectRetriever;
35 import org.apache.geronimo.tomcat.ValveGBean;
36
37 /**
38 * @version $Rev: 356897 $ $Date: 2005-12-14 14:45:55 -0800 (Wed, 14 Dec 2005) $
39 */
40 public class CatalinaClusterGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
41
42 private static final Log log = LogFactory.getLog(CatalinaClusterGBean.class);
43
44 public static final String J2EE_TYPE = "Cluster";
45
46 private final CatalinaCluster cluster;
47
48 public CatalinaClusterGBean(){
49 cluster=null;
50 }
51
52 public CatalinaClusterGBean(String className,
53 Map initParams,
54 MembershipServiceGBean membership,
55 ReceiverGBean receiver,
56 SenderGBean sender,
57 MessageListenerGBean messageListenerChain,
58 ValveGBean tomcatValveChain,
59 ClusterDeployerGBean deployer) throws Exception {
60
61 super();
62
63
64 if (className == null){
65 throw new IllegalArgumentException("Must have a 'className' attribute.");
66 }
67
68
69 cluster = (CatalinaCluster)Class.forName(className).newInstance();
70
71
72 setParameters(cluster, initParams);
73
74
75 if (membership != null){
76 cluster.setMembershipService((MembershipService)membership.getInternalObject());
77 }
78
79
80 if (receiver != null){
81 cluster.setClusterReceiver((ClusterReceiver)receiver.getInternalObject());
82 }
83
84
85 if (sender != null){
86 cluster.setClusterSender((ClusterSender)sender.getInternalObject());
87 }
88
89
90 if (messageListenerChain != null){
91 MessageListenerGBean messageListenerGBean = messageListenerChain;
92 while(messageListenerGBean != null){
93 cluster.addClusterListener((MessageListener)messageListenerGBean.getInternalObject());
94 messageListenerGBean = messageListenerGBean.getNextValve();
95 }
96 }
97
98
99 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
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 }