01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.tomcat.cluster;
17:
18: import java.util.Map;
19:
20: import org.apache.catalina.tribes.ChannelReceiver;
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.apache.geronimo.gbean.GBeanInfo;
24: import org.apache.geronimo.gbean.GBeanInfoBuilder;
25: import org.apache.geronimo.gbean.GBeanLifecycle;
26: import org.apache.geronimo.tomcat.BaseGBean;
27: import org.apache.geronimo.tomcat.ObjectRetriever;
28:
29: public class ReceiverGBean extends BaseGBean implements GBeanLifecycle,
30: ObjectRetriever {
31:
32: private static final Log log = LogFactory
33: .getLog(ReceiverGBean.class);
34:
35: public static final String J2EE_TYPE = "Receiver";
36:
37: private final ChannelReceiver receiver;
38:
39: public ReceiverGBean() {
40: receiver = null;
41: }
42:
43: public ReceiverGBean(String className, Map initParams)
44: throws Exception {
45:
46: super (); // TODO: make it an attribute
47:
48: // Validate
49: if (className == null) {
50: throw new IllegalArgumentException(
51: "Must have a 'className' attribute.");
52: }
53:
54: // Create the CatalinaCluster object
55: receiver = (ChannelReceiver) Class.forName(className)
56: .newInstance();
57:
58: // Set the parameters
59: setParameters(receiver, initParams);
60:
61: }
62:
63: public Object getInternalObject() {
64: return receiver;
65: }
66:
67: public void doFail() {
68: log.warn("Failed");
69: }
70:
71: public void doStart() throws Exception {
72: log.debug("Started Receiver service gbean.");
73: }
74:
75: public void doStop() throws Exception {
76: log.debug("Stopped Receiver gbean.");
77: }
78:
79: public static final GBeanInfo GBEAN_INFO;
80:
81: static {
82: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
83: "Receiver", ReceiverGBean.class, J2EE_TYPE);
84: infoFactory.addAttribute("className", String.class, true);
85: infoFactory.addAttribute("initParams", Map.class, true);
86: infoFactory.addOperation("getInternalObject", "Object");
87: infoFactory.setConstructor(new String[] { "className",
88: "initParams" });
89: GBEAN_INFO = infoFactory.getBeanInfo();
90: }
91:
92: public static GBeanInfo getGBeanInfo() {
93: return GBEAN_INFO;
94: }
95: }
|