001 /** 002 * 003 * Copyright 2003-2005 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.tomcat.cluster; 018 019 import java.util.Map; 020 021 import org.apache.catalina.cluster.ClusterSender; 022 import org.apache.commons.logging.Log; 023 import org.apache.commons.logging.LogFactory; 024 import org.apache.geronimo.gbean.GBeanInfo; 025 import org.apache.geronimo.gbean.GBeanInfoBuilder; 026 import org.apache.geronimo.gbean.GBeanLifecycle; 027 import org.apache.geronimo.tomcat.BaseGBean; 028 import org.apache.geronimo.tomcat.ObjectRetriever; 029 030 public class SenderGBean extends BaseGBean implements 031 GBeanLifecycle, ObjectRetriever { 032 033 private static final Log log = LogFactory 034 .getLog(SenderGBean.class); 035 036 public static final String J2EE_TYPE = "Sender"; 037 038 private final ClusterSender sender; 039 040 public SenderGBean(){ 041 sender = null; 042 } 043 044 public SenderGBean(String className, Map initParams) throws Exception { 045 046 super(); // TODO: make it an attribute 047 048 // Validate 049 if (className == null) { 050 throw new IllegalArgumentException( 051 "Must have a 'className' attribute."); 052 } 053 054 // Create the CatalinaCluster object 055 sender = (ClusterSender) Class.forName(className).newInstance(); 056 057 // Set the parameters 058 setParameters(sender, initParams); 059 060 } 061 062 public Object getInternalObject() { 063 return sender; 064 } 065 066 public void doFail() { 067 log.warn("Failed"); 068 } 069 070 public void doStart() throws Exception { 071 log.debug("Started Sender service gbean."); 072 } 073 074 public void doStop() throws Exception { 075 log.debug("Stopped Sender gbean."); 076 } 077 078 public static final GBeanInfo GBEAN_INFO; 079 080 static { 081 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Sender", SenderGBean.class, J2EE_TYPE); 082 infoFactory.addAttribute("className", String.class, true); 083 infoFactory.addAttribute("initParams", Map.class, true); 084 infoFactory.addOperation("getInternalObject"); 085 infoFactory.setConstructor(new String[] { "className", "initParams" }); 086 GBEAN_INFO = infoFactory.getBeanInfo(); 087 } 088 089 public static GBeanInfo getGBeanInfo() { 090 return GBEAN_INFO; 091 } 092 }