1 22 package org.jboss.ejb3.mdb; 23 24 import org.jboss.annotation.ejb.AcknowledgementMode; 25 import org.jboss.annotation.ejb.DefaultActivationSpecs; 26 import org.jboss.annotation.ejb.ResourceAdapter; 27 import org.jboss.aop.AspectManager; 28 import org.jboss.aop.MethodInfo; 29 import org.jboss.aop.advice.Interceptor; 30 import org.jboss.aop.util.MethodHashing; 31 import org.jboss.deployment.DeploymentException; 32 import org.jboss.ejb3.*; 33 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory; 34 import org.jboss.ejb3.interceptor.InterceptorInfoRepository; 35 import org.jboss.ejb3.timerservice.TimedObjectInvoker; 36 import org.jboss.ejb3.timerservice.TimerServiceFactory; 37 import org.jboss.jms.ConnectionFactoryHelper; 38 import org.jboss.jms.jndi.JMSProviderAdapter; 39 import org.jboss.logging.Logger; 40 import org.jboss.metadata.ActivationConfigPropertyMetaData; 41 42 import javax.ejb.*; 43 import javax.ejb.Timer ; 44 import javax.jms.*; 45 import javax.jms.Queue ; 46 import javax.management.MBeanServer ; 47 import javax.management.MalformedObjectNameException ; 48 import javax.management.ObjectName ; 49 import javax.naming.Context ; 50 import javax.naming.NamingException ; 51 import java.lang.reflect.Field ; 52 import java.lang.reflect.Method ; 53 import java.util.*; 54 55 61 public class MDB extends MessagingContainer 62 { 63 private static final Logger log = Logger.getLogger(MDB.class); 64 65 protected Class messagingType = null; 66 71 protected final static String DEFAULT_DESTINATION_TYPE = "javax.jms.Topic"; 72 73 public MDB(String ejbName, AspectManager manager, ClassLoader cl, String beanClassName, Hashtable ctxProperties, 74 InterceptorInfoRepository interceptorRepository, Ejb3Deployment deployment) 75 { 76 super(ejbName, manager, cl, beanClassName, ctxProperties, interceptorRepository, deployment); 77 } 78 79 public Class getMessagingType() 80 { 81 if (messagingType == null) 82 { 83 MessageDriven annotation = (MessageDriven) resolveAnnotation(MessageDriven.class); 84 messagingType = annotation.messageListenerInterface(); 85 if (messagingType.getName().equals(Object .class.getName())) 86 { 87 ArrayList<Class > list = ProxyFactoryHelper.getBusinessInterfaces(clazz); 88 if (list.size() > 1 || list.size() == 0) throw new RuntimeException ("unable to determine messagingType interface for MDB"); 89 messagingType = list.get(0); 90 } 91 } 92 93 return messagingType; 94 } 95 96 public MethodInfo getMethodInfo(Method method) 97 { 98 long hash = MethodHashing.calculateHash(method); 99 MethodInfo info = (MethodInfo) methodInterceptors.get(hash); 100 return info; 101 } 102 103 public Map getActivationConfigProperties() 104 { 105 HashMap result = new HashMap(); 106 MessageDriven mdAnnotation = (MessageDriven) resolveAnnotation(MessageDriven.class); 107 for (ActivationConfigProperty property : mdAnnotation.activationConfig()) 108 { 109 addActivationSpecProperty(result, property); 110 } 111 112 DefaultActivationSpecs defaultSpecsAnnotation = (DefaultActivationSpecs)resolveAnnotation(DefaultActivationSpecs.class); 113 if (defaultSpecsAnnotation != null) 114 { 115 for (ActivationConfigProperty property : defaultSpecsAnnotation.value()) 116 { 117 addActivationSpecProperty(result, property); 118 } 119 } 120 121 return result; 122 } 123 124 public void start() throws Exception 125 { 126 super.start(); 127 } 128 129 public ObjectName getJmxName() 130 { 131 ObjectName jmxName = null; 132 String jndiName = ProxyFactoryHelper.getLocalJndiName(this); 133 String name = org.jboss.ejb.Container.BASE_EJB_CONTAINER_NAME + ",jndiName=" + jndiName; 135 try 136 { 137 jmxName = org.jboss.mx.util.ObjectNameConverter.convert(name); 138 } 139 catch (MalformedObjectNameException e) 140 { 141 e.printStackTrace(); 142 throw new RuntimeException ("Failed to create ObjectName, msg=" + e.getMessage()); 143 } 144 145 return jmxName; 146 } 147 148 protected void populateActivationSpec() 149 { 150 DefaultActivationSpecs defaultSpecs = (DefaultActivationSpecs) resolveAnnotation(DefaultActivationSpecs.class); 151 if (defaultSpecs != null) 152 { 153 activationSpec.merge(defaultSpecs.value()); 154 } 155 156 MessageDriven md = (MessageDriven) resolveAnnotation(MessageDriven.class); 157 158 activationSpec.merge(md.activationConfig()); 159 } 160 } 161 | Popular Tags |