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.ChannelSender;
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 SenderGBean extends BaseGBean implements GBeanLifecycle,
30: ObjectRetriever {
31:
32: private static final Log log = LogFactory.getLog(SenderGBean.class);
33:
34: public static final String J2EE_TYPE = "Sender";
35:
36: private final ChannelSender sender;
37:
38: public SenderGBean() {
39: sender = null;
40: }
41:
42: public SenderGBean(String className, Map initParams)
43: throws Exception {
44:
45: super (); // TODO: make it an attribute
46:
47: // Validate
48: if (className == null) {
49: throw new IllegalArgumentException(
50: "Must have a 'className' attribute.");
51: }
52:
53: // Create the CatalinaCluster object
54: sender = (ChannelSender) Class.forName(className).newInstance();
55:
56: // Set the parameters
57: setParameters(sender, initParams);
58:
59: }
60:
61: public Object getInternalObject() {
62: return sender;
63: }
64:
65: public void doFail() {
66: log.warn("Failed");
67: }
68:
69: public void doStart() throws Exception {
70: log.debug("Started Sender service gbean.");
71: }
72:
73: public void doStop() throws Exception {
74: log.debug("Stopped Sender gbean.");
75: }
76:
77: public static final GBeanInfo GBEAN_INFO;
78:
79: static {
80: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
81: "Sender", SenderGBean.class, J2EE_TYPE);
82: infoFactory.addAttribute("className", String.class, true);
83: infoFactory.addAttribute("initParams", Map.class, true);
84: infoFactory.addOperation("getInternalObject", "Object");
85: infoFactory.setConstructor(new String[] { "className",
86: "initParams" });
87: GBEAN_INFO = infoFactory.getBeanInfo();
88: }
89:
90: public static GBeanInfo getGBeanInfo() {
91: return GBEAN_INFO;
92: }
93: }
|