001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.mdb;
023:
024: import org.jboss.annotation.ejb.AcknowledgementMode;
025: import org.jboss.annotation.ejb.DefaultActivationSpecs;
026: import org.jboss.annotation.ejb.ResourceAdapter;
027: import org.jboss.aop.AspectManager;
028: import org.jboss.aop.MethodInfo;
029: import org.jboss.aop.advice.Interceptor;
030: import org.jboss.aop.util.MethodHashing;
031: import org.jboss.deployment.DeploymentException;
032: import org.jboss.ejb3.*;
033: import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
034: import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
035: import org.jboss.ejb3.timerservice.TimedObjectInvoker;
036: import org.jboss.ejb3.timerservice.TimerServiceFactory;
037: import org.jboss.jms.ConnectionFactoryHelper;
038: import org.jboss.jms.jndi.JMSProviderAdapter;
039: import org.jboss.logging.Logger;
040: import org.jboss.metadata.ActivationConfigPropertyMetaData;
041:
042: import javax.ejb.*;
043: import javax.ejb.Timer;
044: import javax.jms.*;
045: import javax.jms.Queue;
046: import javax.management.MBeanServer;
047: import javax.management.MalformedObjectNameException;
048: import javax.management.ObjectName;
049: import javax.naming.Context;
050: import javax.naming.NamingException;
051: import java.lang.reflect.Field;
052: import java.lang.reflect.Method;
053: import java.util.*;
054:
055: /**
056: * Comment
057: *
058: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
059: * @version $Revision: 61201 $
060: */
061: public class MDB extends MessagingContainer {
062: private static final Logger log = Logger.getLogger(MDB.class);
063:
064: protected Class messagingType = null;
065: /**
066: * Default destination type. Used when no message-driven-destination is given
067: * in ejb-jar, and a lookup of destinationJNDI from jboss.xml is not
068: * successfull. Default value: javax.jms.Topic.
069: */
070: protected final static String DEFAULT_DESTINATION_TYPE = "javax.jms.Topic";
071:
072: public MDB(String ejbName, AspectManager manager, ClassLoader cl,
073: String beanClassName, Hashtable ctxProperties,
074: InterceptorInfoRepository interceptorRepository,
075: Ejb3Deployment deployment) {
076: super (ejbName, manager, cl, beanClassName, ctxProperties,
077: interceptorRepository, deployment);
078: }
079:
080: public Class getMessagingType() {
081: if (messagingType == null) {
082: MessageDriven annotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
083: messagingType = annotation.messageListenerInterface();
084: if (messagingType.getName().equals(Object.class.getName())) {
085: ArrayList<Class> list = ProxyFactoryHelper
086: .getBusinessInterfaces(clazz);
087: if (list.size() > 1 || list.size() == 0)
088: throw new RuntimeException(
089: "unable to determine messagingType interface for MDB");
090: messagingType = list.get(0);
091: }
092: }
093:
094: return messagingType;
095: }
096:
097: public MethodInfo getMethodInfo(Method method) {
098: long hash = MethodHashing.calculateHash(method);
099: MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
100: return info;
101: }
102:
103: public Map getActivationConfigProperties() {
104: HashMap result = new HashMap();
105: MessageDriven mdAnnotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
106: for (ActivationConfigProperty property : mdAnnotation
107: .activationConfig()) {
108: addActivationSpecProperty(result, property);
109: }
110:
111: DefaultActivationSpecs defaultSpecsAnnotation = (DefaultActivationSpecs) resolveAnnotation(DefaultActivationSpecs.class);
112: if (defaultSpecsAnnotation != null) {
113: for (ActivationConfigProperty property : defaultSpecsAnnotation
114: .value()) {
115: addActivationSpecProperty(result, property);
116: }
117: }
118:
119: return result;
120: }
121:
122: public void start() throws Exception {
123: super .start();
124: }
125:
126: public ObjectName getJmxName() {
127: ObjectName jmxName = null;
128: String jndiName = ProxyFactoryHelper.getLocalJndiName(this );
129: // The name must be escaped since the jndiName may be arbitrary
130: String name = org.jboss.ejb.Container.BASE_EJB_CONTAINER_NAME
131: + ",jndiName=" + jndiName;
132: try {
133: jmxName = org.jboss.mx.util.ObjectNameConverter
134: .convert(name);
135: } catch (MalformedObjectNameException e) {
136: e.printStackTrace();
137: throw new RuntimeException(
138: "Failed to create ObjectName, msg="
139: + e.getMessage());
140: }
141:
142: return jmxName;
143: }
144:
145: protected void populateActivationSpec() {
146: DefaultActivationSpecs defaultSpecs = (DefaultActivationSpecs) resolveAnnotation(DefaultActivationSpecs.class);
147: if (defaultSpecs != null) {
148: activationSpec.merge(defaultSpecs.value());
149: }
150:
151: MessageDriven md = (MessageDriven) resolveAnnotation(MessageDriven.class);
152:
153: activationSpec.merge(md.activationConfig());
154: }
155:
156: public int getMinPoolSize() {
157: String minSession = activationSpec.get("minSession");
158: if (minSession != null)
159: return Integer.parseInt(minSession);
160: else
161: return 1;
162: }
163:
164: public int getMaxPoolSize() {
165: String maxSession = activationSpec.get("maxSession");
166: if (maxSession != null)
167: return Integer.parseInt(maxSession);
168: else
169: return 15;
170: }
171:
172: public int getMaxMessages() {
173: String maxMessages = activationSpec.get("maxMessages");
174: if (maxMessages != null)
175: return Integer.parseInt(maxMessages);
176: else
177: return 1;
178: }
179:
180: public int getKeepAliveMillis() {
181: String keepAlive = activationSpec.get("keepAlive");
182: if (keepAlive != null)
183: return Integer.parseInt(keepAlive);
184: else
185: return 60000;
186: }
187: }
|