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.cluster.ClusterReceiver;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27 import org.apache.geronimo.tomcat.BaseGBean;
28 import org.apache.geronimo.tomcat.ObjectRetriever;
29
30 public class ReceiverGBean extends BaseGBean implements
31 GBeanLifecycle, ObjectRetriever {
32
33 private static final Log log = LogFactory
34 .getLog(ReceiverGBean.class);
35
36 public static final String J2EE_TYPE = "Receiver";
37
38 private final ClusterReceiver receiver;
39
40 public ReceiverGBean() {
41 receiver = null;
42 }
43
44 public ReceiverGBean(String className, Map initParams) throws Exception {
45
46 super();
47
48
49 if (className == null) {
50 throw new IllegalArgumentException(
51 "Must have a 'className' attribute.");
52 }
53
54
55 receiver = (ClusterReceiver) Class.forName(className).newInstance();
56
57
58 setParameters(receiver, initParams);
59
60 }
61
62 public Object getInternalObject() {
63 return receiver;
64 }
65
66 public void doFail() {
67 log.warn("Failed");
68 }
69
70 public void doStart() throws Exception {
71 log.debug("Started Receiver service gbean.");
72 }
73
74 public void doStop() throws Exception {
75 log.debug("Stopped Receiver gbean.");
76 }
77
78 public static final GBeanInfo GBEAN_INFO;
79
80 static {
81 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Receiver", ReceiverGBean.class, J2EE_TYPE);
82 infoFactory.addAttribute("className", String.class, true);
83 infoFactory.addAttribute("initParams", Map.class, true);
84 infoFactory.addOperation("getInternalObject");
85 infoFactory.setConstructor(new String[] { "className", "initParams" });
86 GBEAN_INFO = infoFactory.getBeanInfo();
87 }
88
89 public static GBeanInfo getGBeanInfo() {
90 return GBEAN_INFO;
91 }
92 }