KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > mdb > RemoteProducerFactory


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.mdb;
23
24 import java.util.Hashtable JavaDoc;
25 import javax.jms.ConnectionFactory JavaDoc;
26 import javax.jms.Destination JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.NamingException JavaDoc;
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 /**
40  * comment
41  *
42  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
43  */

44 public class RemoteProducerFactory extends ProducerFactory
45 {
46    protected ConnectionFactory JavaDoc factory;
47
48    public RemoteProducerFactory(ConsumerContainer container, Class JavaDoc producer, MessageProperties props, Destination JavaDoc dest, InitialContext JavaDoc ctx, Hashtable JavaDoc initialContextProperties)
49    {
50       super(container, producer, props, dest, ctx, initialContextProperties);
51       try
52       {
53          String JavaDoc factoryName = pImpl.connectionFactory();
54          if (factoryName.equals("")) factoryName = "ConnectionFactory";
55          factory = (ConnectionFactory JavaDoc) ctx.lookup(factoryName);
56       }
57       catch (Exception JavaDoc e)
58       {
59          throw new RuntimeException JavaDoc(e);
60       }
61    }
62
63    public void setContainer(Container container)
64    {
65    }
66
67    public Object JavaDoc createProxy()
68    {
69       Class JavaDoc[] 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 JavaDoc
81    {
82       super.start();
83       Class JavaDoc[] interfaces = {ProxyFactory.class};
84       Object JavaDoc 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 JavaDoc e)
89       {
90          NamingException JavaDoc namingException = new NamingException JavaDoc("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 JavaDoc
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