1 /* CollocatedOrbs.java -- Handles collocations
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import gnu.CORBA.Poa.gnuServantObject;
43 import java.net.InetAddress;
44 import java.net.UnknownHostException;
45 import java.util.ArrayList;
48 * This class provides support for the direct method invocations without
49 * involving the network in the case when both ORBs run on the same java
50 * virtual machine. Special attention is only needed when call is made
51 * between two independent ORBs, instantiated via ORB.init. The call to the
52 * object, obtained via IOR reference from the ORB where it was locally
53 * connected is always local anyway.
55 * For security reasons it may be sensible to keep this class and all support
58 * @author Audrius Meskauskas
63 * This field is used in automated Classpath specific testing to disable
66 static boolean DIRECT_CALLS_ALLOWED = true;
69 * Containts the references of the all running GNU Classpath ORBs in the
70 * local virtual machine. GNU Classpath ORBs register themselves here when
71 * created and unregister when either ORB.destroy is called or in the
74 private static ArrayList orbs = new ArrayList();
77 * The address of the local host.
79 static String localHost;
85 localHost = InetAddress.getLocalHost().getHostAddress();
87 catch (UnknownHostException ex)
89 throw new InternalError("Local host is not accessible:" + ex);
94 * Register the new ORB
96 * @param orb the orb to register
98 static void registerOrb(OrbFunctional orb)
100 if (DIRECT_CALLS_ALLOWED)
103 assert ! orbs.contains(orb);
109 * Unregister the ORB. The ORB will no longer be reacheable locally but may
110 * be reacheable via network as if it would be remote.
112 * @param orb the orb to unregister
114 static void unregisterOrb(OrbFunctional orb)
116 if (DIRECT_CALLS_ALLOWED)
119 assert orbs.contains(orb);
125 * Search the possibly local object. If the IOR is not local or none of the
126 * found ORBs of this virtual machine knows about it, null is returned.
128 * @param ior the IOR to search
129 * @return the found local CORBA object or null in not found.
131 static org.omg.CORBA.Object searchLocalObject(IOR ior)
133 if (! DIRECT_CALLS_ALLOWED && ! ior.Internet.host.equals(localHost))
139 org.omg.CORBA.Object object;
140 for (int i = 0; i < orbs.size(); i++)
142 orb = (OrbFunctional) orbs.get(i);
143 object = orb.find_connected_object(ior.key, ior.Internet.port);
146 if (object instanceof SafeForDirectCalls)
150 else if (object instanceof gnuServantObject)