1 22 package org.jboss.ejb3.mdb; 23 24 import java.util.Hashtable ; 25 import javax.jms.ConnectionFactory ; 26 import javax.jms.Destination ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 30 import org.jboss.annotation.ejb.MessageProperties; 31 import org.jboss.aop.Dispatcher; 32 import org.jboss.aop.advice.Interceptor; 33 import org.jboss.aspects.remoting.Remoting; 34 import org.jboss.ejb3.Container; 35 import org.jboss.ejb3.ProxyFactory; 36 import org.jboss.ejb3.remoting.RemoteProxyFactory; 37 import org.jboss.naming.Util; 38 39 44 public class RemoteProducerFactory extends ProducerFactory 45 { 46 protected ConnectionFactory factory; 47 48 public RemoteProducerFactory(ConsumerContainer container, Class producer, MessageProperties props, Destination dest, InitialContext ctx, Hashtable initialContextProperties) 49 { 50 super(container, producer, props, dest, ctx, initialContextProperties); 51 try 52 { 53 String factoryName = pImpl.connectionFactory(); 54 if (factoryName.equals("")) factoryName = "ConnectionFactory"; 55 factory = (ConnectionFactory ) ctx.lookup(factoryName); 56 } 57 catch (Exception e) 58 { 59 throw new RuntimeException (e); 60 } 61 } 62 63 public void setContainer(Container container) 64 { 65 } 66 67 public Object createProxy() 68 { 69 Class [] interfaces = {producer, ProducerObject.class}; 70 71 ProducerManagerImpl mImpl = null; 72 73 mImpl = new ProducerManagerImpl(pImpl, dest, factory, props.delivery(), props.timeToLive(), props.priority(), methodMap, initialContextProperties); 74 75 Interceptor[] interceptors = {mImpl}; 76 ProducerProxy ih = new ProducerProxy(mImpl, interceptors); 77 return java.lang.reflect.Proxy.newProxyInstance(producer.getClassLoader(), interfaces, ih); 78 } 79 80 public void start() throws Exception 81 { 82 super.start(); 83 Class [] interfaces = {ProxyFactory.class}; 84 Object factoryProxy = Remoting.createPojiProxy(jndiName + PROXY_FACTORY_NAME, interfaces, RemoteProxyFactory.DEFAULT_CLIENT_BINDING); 85 try 86 { 87 Util.rebind(ctx, jndiName + PROXY_FACTORY_NAME, factoryProxy); 88 } catch (NamingException e) 89 { 90 NamingException namingException = new NamingException ("Could not bind remote producer factory into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME); 91 namingException.setRootCause(e); 92 throw namingException; 93 } 94 Dispatcher.singleton.registerTarget(jndiName + PROXY_FACTORY_NAME, this); 95 } 96 97 public void stop() throws Exception 98 { 99 super.stop(); 100 Util.unbind(ctx, jndiName + PROXY_FACTORY_NAME); 101 Dispatcher.singleton.unregisterTarget(jndiName + PROXY_FACTORY_NAME); 102 } 103 } 104 | Popular Tags |