001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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.tribes.ChannelReceiver; 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 ReceiverGBean extends BaseGBean implements 031 GBeanLifecycle, ObjectRetriever { 032 033 private static final Log log = LogFactory.getLog(ReceiverGBean.class); 034 035 public static final String J2EE_TYPE = "Receiver"; 036 037 private final ChannelReceiver receiver; 038 039 public ReceiverGBean() { 040 receiver = null; 041 } 042 043 public ReceiverGBean(String className, Map initParams) throws Exception { 044 045 super(); // TODO: make it an attribute 046 047 // Validate 048 if (className == null) { 049 throw new IllegalArgumentException("Must have a 'className' attribute."); 050 } 051 052 // Create the CatalinaCluster object 053 receiver = (ChannelReceiver) Class.forName(className).newInstance(); 054 055 // Set the parameters 056 setParameters(receiver, initParams); 057 058 } 059 060 public Object getInternalObject() { 061 return receiver; 062 } 063 064 public void doFail() { 065 log.warn("Failed"); 066 } 067 068 public void doStart() throws Exception { 069 log.debug("Started Receiver service gbean."); 070 } 071 072 public void doStop() throws Exception { 073 log.debug("Stopped Receiver gbean."); 074 } 075 076 public static final GBeanInfo GBEAN_INFO; 077 078 static { 079 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Receiver", ReceiverGBean.class, J2EE_TYPE); 080 infoFactory.addAttribute("className", String.class, true); 081 infoFactory.addAttribute("initParams", Map.class, true); 082 infoFactory.addOperation("getInternalObject", "Object"); 083 infoFactory.setConstructor(new String[] { "className", "initParams" }); 084 GBEAN_INFO = infoFactory.getBeanInfo(); 085 } 086 087 public static GBeanInfo getGBeanInfo() { 088 return GBEAN_INFO; 089 } 090 }