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.MembershipService;
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 MembershipServiceGBean extends BaseGBean implements
30: GBeanLifecycle, ObjectRetriever {
31:
32: private static final Log log = LogFactory
33: .getLog(MembershipServiceGBean.class);
34:
35: public static final String J2EE_TYPE = "MembershipService";
36:
37: private final MembershipService membership;
38:
39: public MembershipServiceGBean() {
40: membership = null;
41: }
42:
43: public MembershipServiceGBean(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: membership = (MembershipService) Class.forName(className)
56: .newInstance();
57:
58: // Set the parameters
59: setParameters(membership, initParams);
60:
61: }
62:
63: public Object getInternalObject() {
64: return membership;
65: }
66:
67: public void doFail() {
68: log.warn("Failed");
69: }
70:
71: public void doStart() throws Exception {
72: log.debug("Started membership service gbean.");
73: }
74:
75: public void doStop() throws Exception {
76: log.debug("Stopped MembershipService gbean.");
77: }
78:
79: public static final GBeanInfo GBEAN_INFO;
80:
81: static {
82: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
83: "MembershipService", MembershipServiceGBean.class,
84: J2EE_TYPE);
85: infoFactory.addAttribute("className", String.class, true);
86: infoFactory.addAttribute("initParams", Map.class, true);
87: infoFactory.addOperation("getInternalObject", "Object");
88: infoFactory.setConstructor(new String[] { "className",
89: "initParams" });
90: GBEAN_INFO = infoFactory.getBeanInfo();
91: }
92:
93: public static GBeanInfo getGBeanInfo() {
94: return GBEAN_INFO;
95: }
96: }
|