KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > AbstractInvoker


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9 package org.jboss.remoting;
10
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13 import org.jboss.logging.Logger;
14 import org.jboss.remoting.loading.ClassByteClassLoader;
15 import org.jboss.remoting.marshal.MarshallLoaderFactory;
16
17 /**
18  * AbstractInvoker is an abstract handler part that contains common methods between both
19  * client and server.
20  *
21  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
22  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
23  * @version $Revision: 1.4 $
24  */

25 public abstract class AbstractInvoker implements Invoker
26 {
27    protected final Logger log = Logger.getLogger(getClass());
28    protected ClassByteClassLoader classbyteloader;
29    protected InvokerLocator locator;
30    protected Map JavaDoc localServerLocators = new HashMap JavaDoc();
31
32    public AbstractInvoker(InvokerLocator locator)
33    {
34       this.classbyteloader = new ClassByteClassLoader(this.getClass().getClassLoader());
35       this.locator = locator;
36
37       try
38       {
39          InvokerLocator loaderLocator = MarshallLoaderFactory.convertLocator(locator);
40          if(loaderLocator != null)
41          {
42             classbyteloader.setClientInvoker(new Client(loaderLocator));
43          }
44       }
45       catch(Exception JavaDoc e)
46       {
47          log.error("Could not create remote class loading for invoker.", e);
48       }
49    }
50
51    /**
52     * return the locator this Invoker represents
53     *
54     * @return
55     */

56    public InvokerLocator getLocator()
57    {
58       return locator;
59    }
60
61    /**
62     * Sets the callback server locator for the specified callback listener id
63     *
64     * @param locator
65     */

66    public void addClientLocator(String JavaDoc listenerId, InvokerLocator locator)
67    {
68       Object JavaDoc obj = localServerLocators.put(listenerId, locator);
69       if(obj != null)
70       {
71          throw new RuntimeException JavaDoc("InvokerLocator already exists for listener id " + listenerId + ". " +
72                                     "Remove this listener before adding again.");
73       }
74    }
75
76    /**
77     * Gets the client locator. This locator will be used by the server side
78     * to make callbacks to the handler for this locator.
79     *
80     * @return
81     */

82    public InvokerLocator getClientLocator(String JavaDoc listenerId)
83    {
84       return (InvokerLocator) localServerLocators.get(listenerId);
85    }
86
87    /**
88     * set the classloader to use internally
89     *
90     * @param classloader
91     */

92    public synchronized void setClassLoader(ClassLoader JavaDoc classloader)
93    {
94       this.classbyteloader = new ClassByteClassLoader(classloader);
95    }
96
97    public synchronized ClassLoader JavaDoc getClassLoader()
98    {
99       return classbyteloader;
100    }
101
102 }
103
Popular Tags