View Javadoc

1   /***
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Exoffice Technologies.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Exoffice Technologies. Exolab is a registered
23   *    trademark of Exoffice Technologies.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 2004-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: SharedORB.java,v 1.6 2005/05/27 14:04:01 tanderson Exp $
44   */
45  package org.exolab.jms.client.net;
46  
47  import java.util.Map;
48  
49  import java.rmi.NoSuchObjectException;
50  import java.rmi.RemoteException;
51  import java.rmi.StubNotFoundException;
52  import java.rmi.server.ExportException;
53  import java.rmi.server.ObjID;
54  
55  import org.exolab.jms.net.connector.CallerListener;
56  import org.exolab.jms.net.connector.Caller;
57  import org.exolab.jms.net.orb.ORB;
58  import org.exolab.jms.net.orb.ORBFactory;
59  import org.exolab.jms.net.proxy.Proxy;
60  import org.exolab.jms.net.registry.LocalRegistry;
61  import org.exolab.jms.net.registry.Registry;
62  
63  
64  /***
65   * Shared {@link ORB} instance.
66   *
67   * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
68   * @version $Revision: 1.6 $ $Date: 2005/05/27 14:04:01 $
69   */
70  public class SharedORB implements ORB {
71  
72      /***
73       * The ORB to delegate requests to.
74       */
75      private final ORB _orb;
76  
77      /***
78       * The singleton instance.
79       */
80      private static org.exolab.jms.net.orb.ORB _instance;
81  
82  
83      /***
84       * Construct a new <code>SharedORB</code>.
85       *
86       * @throws RemoteException for any error
87       */
88      private SharedORB() throws RemoteException {
89          _orb = ORBFactory.createORB();
90      }
91  
92      /***
93       * Add a route for exported objects.
94       *
95       * @param uri   the URI to route
96       * @param toURI the URI to route to
97       * @throws RemoteException for any error
98       */
99      public void addRoute(String uri, String toURI) throws RemoteException {
100         _orb.addRoute(uri, toURI);
101     }
102 
103     /***
104      * Returns a reference to the registry service.
105      *
106      * @return the registry service
107      * @throws RemoteException if the service cannot be exported
108      */
109     public LocalRegistry getRegistry() throws RemoteException {
110         return _orb.getRegistry();
111     }
112 
113     /***
114      * Returns a reference to a remote registry service.
115      *
116      * @param properties the connection properties. May be <code>null</code>.
117      * @return the registry service
118      * @throws RemoteException for any error
119      */
120     public Registry getRegistry(Map properties) throws RemoteException {
121         return _orb.getRegistry(properties);
122     }
123 
124     /***
125      * Export an object on the default URI.
126      *
127      * @param object the object to export
128      * @return a proxy which may be used to invoke methods on the object
129      * @throws ExportException       if the object cannot be exported
130      * @throws StubNotFoundException if the proxy class cannot be found
131      */
132     public Proxy exportObject(Object object)
133             throws ExportException, StubNotFoundException {
134         return _orb.exportObject(object);
135     }
136 
137     /***
138      * Export an object on a specific URI.
139      *
140      * @param object the object to export
141      * @param uri    the URI via which connections to the object are made. If
142      *               <code>null</code>, the default URI is used.
143      * @return a proxy which may be used to invoke methods on the object
144      * @throws ExportException       if the object cannot be exported
145      * @throws StubNotFoundException if the proxy class cannot be found
146      */
147     public Proxy exportObject(Object object, String uri)
148             throws ExportException, StubNotFoundException {
149         return _orb.exportObject(object, uri);
150     }
151 
152     /***
153      * Export an object with a well known identifier on the default URI.
154      *
155      * @param object the object to export
156      * @param objID  the well known object identifier
157      * @return a proxy which may be used to invoke methods on the object
158      * @throws ExportException       if the object cannot be exported
159      * @throws StubNotFoundException if the proxy class cannot be found
160      */
161     public Proxy exportObject(Object object, ObjID objID)
162             throws ExportException, StubNotFoundException {
163         return _orb.exportObject(object, objID);
164     }
165 
166     /***
167      * Export an object with a well known identifier on a specific URI.
168      *
169      * @param object the object to export
170      * @param objID  the well known object identifier
171      * @param uri    the URI via which connections to the object are made
172      * @return a proxy which may be used to invoke methods on the object
173      * @throws ExportException       if the object cannot be exported
174      * @throws StubNotFoundException if the proxy class cannot be found
175      */
176     public Proxy exportObject(Object object, ObjID objID, String uri)
177             throws ExportException, StubNotFoundException {
178         return _orb.exportObject(object, objID, uri);
179     }
180 
181     /***
182      * Export an object to the current remote caller. Only the remote caller may
183      * perform invocations.
184      *
185      * @param object the object to export
186      * @return a proxy which may be used to invoke methods on the object
187      * @throws ExportException       if the object cannot be exported
188      * @throws StubNotFoundException if the proxy class cannot be found
189      */
190     public Proxy exportObjectTo(Object object) throws ExportException,
191             StubNotFoundException {
192         return _orb.exportObjectTo(object);
193     }
194 
195     /***
196      * Export an object to a specific URI. Only callers from the target URI may
197      * perform invocations.
198      *
199      * @param object the object to export
200      * @param uri    the target URI from which connections to the object are
201      *               made.
202      * @return a proxy which may be used to invoke methods on the object
203      * @throws ExportException       if the object cannot be exported
204      * @throws StubNotFoundException if the proxy class cannot be found
205      */
206     public Proxy exportObjectTo(Object object, String uri)
207             throws ExportException, StubNotFoundException {
208         return _orb.exportObjectTo(object, uri);
209     }
210 
211     /***
212      * Export an object to a specific URI. Only callers from the target URI may
213      * perform invocations.
214      *
215      * @param object      the object to export
216      * @param uri         the target URI from which connections to the object
217      *                    are made.
218      * @param principal   the security principal. May be <code>null</code>
219      * @param credentials the security credentials. May be <code>null</code>
220      * @return a proxy which may be used to invoke methods on the object
221      * @throws ExportException       if the object cannot be exported
222      * @throws StubNotFoundException if the proxy class cannot be found
223      */
224     public Proxy exportObjectTo(Object object, String uri, String principal,
225                                 String credentials)
226             throws ExportException, StubNotFoundException {
227         return _orb.exportObjectTo(object, uri, principal, credentials);
228     }
229 
230     /***
231      * Unexport an object.
232      *
233      * @param object the object to export
234      * @throws NoSuchObjectException if the object isn't exported
235      */
236     public void unexportObject(Object object) throws NoSuchObjectException {
237         _orb.unexportObject(object);
238     }
239 
240     /***
241      * Returns the current caller.
242      *
243      * @return the current caller, or <code>null</code> if no call is in
244      *         progress
245      * @throws RemoteException for any error
246      */
247     public Caller getCaller() throws RemoteException {
248         return _orb.getCaller();
249     }
250 
251     /***
252      * Register a caller event listener.
253      *
254      * @param uri      the remote URI to listen on
255      * @param listener the listener to notify
256      * @throws RemoteException for any error
257      */
258     public void addCallerListener(String uri, CallerListener listener)
259             throws RemoteException {
260         _orb.addCallerListener(uri, listener);
261     }
262 
263     /***
264      * Deregister a caller event listener.
265      *
266      * @param uri      the remote URI the listener is listening for events on
267      * @param listener the listener to remove
268      * @throws RemoteException for any error
269      */
270     public void removeCallerListener(String uri, CallerListener listener)
271             throws RemoteException {
272         _orb.removeCallerListener(uri, listener);
273     }
274 
275     /***
276      * Shuts down the ORB.
277      *
278      * @throws RemoteException for any error
279      */
280     public void shutdown() throws RemoteException {
281         _orb.shutdown();
282     }
283 
284     /***
285      * Returns the singleton ORB instance.
286      *
287      * @return the singleton ORB instance
288      * @throws RemoteException for any error
289      */
290     public static synchronized ORB getInstance() throws RemoteException {
291         if (_instance == null) {
292             _instance = new SharedORB();
293         }
294         return _instance;
295     }
296 
297 }