summaryrefslogtreecommitdiff
path: root/gnu/CORBA/Functional_ORB.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/CORBA/Functional_ORB.java')
-rw-r--r--gnu/CORBA/Functional_ORB.java671
1 files changed, 327 insertions, 344 deletions
diff --git a/gnu/CORBA/Functional_ORB.java b/gnu/CORBA/Functional_ORB.java
index c8d6a4c93..bf6497953 100644
--- a/gnu/CORBA/Functional_ORB.java
+++ b/gnu/CORBA/Functional_ORB.java
@@ -1,4 +1,4 @@
-/* FunctionalORB.java --
+/* Functional_ORB.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -58,6 +58,7 @@ import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CORBA.Request;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.UNKNOWN;
+import org.omg.CORBA.WrongTransaction;
import org.omg.CORBA.portable.Delegate;
import org.omg.CORBA.portable.InvokeHandler;
import org.omg.CORBA.portable.ObjectImpl;
@@ -88,28 +89,25 @@ import java.util.TreeMap;
/**
* The ORB implementation, capable to handle remote invocations on the
- * registered object. This class implements all features, required till
- * the jdk 1.3 inclusive, but does not support the POA that appears since
- * 1.4. The POA is supported by {@link gnu.CORBA.Poa.ORB_1_4}.
+ * registered object. This class implements all features, required till the jdk
+ * 1.3 inclusive, but does not support the POA that appears since 1.4. The POA
+ * is supported by {@link gnu.CORBA.Poa.ORB_1_4}.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
-public class Functional_ORB
- extends Restricted_ORB
+public class Functional_ORB extends Restricted_ORB
{
/**
- * A server, responsible for listening on requests on some
- * local port. The ORB may listen on multiple ports and process
- * the requests in separate threads. Normally the server takes
- * one port per object being served.
+ * A server, responsible for listening on requests on some local port. The ORB
+ * may listen on multiple ports and process the requests in separate threads.
+ * Normally the server takes one port per object being served.
*/
- class portServer
- extends Thread
+ class portServer extends Thread
{
/**
* The number of the currently running parallel threads.
*/
- private int running_threads;
+ int running_threads;
/**
* The port on that this portServer is listening for requests.
@@ -122,8 +120,7 @@ public class Functional_ORB
ServerSocket service;
/**
- * True if the serving node must shutdown due
- * call of the close_now().
+ * True if the serving node must shutdown due call of the close_now().
*/
boolean terminated;
@@ -136,9 +133,8 @@ public class Functional_ORB
}
/**
- * Enter the serving loop (get request/process it).
- * All portServer normally terminate thy threads when
- * the Functional_ORB.running is set to false.
+ * Enter the serving loop (get request/process it). All portServer normally
+ * terminate thy threads when the Functional_ORB.running is set to false.
*/
public void run()
{
@@ -184,10 +180,10 @@ public class Functional_ORB
/**
* Perform a single serving step.
+ *
* @throws java.lang.Exception
*/
- void tick()
- throws Exception
+ void tick() throws Exception
{
serve(this, service);
}
@@ -219,12 +215,11 @@ public class Functional_ORB
}
/**
- * A server, responsible for listening on requests on some
- * local port and serving multiple requests (probably to the
- * different objects) on the same thread.
+ * A server, responsible for listening on requests on some local port and
+ * serving multiple requests (probably to the different objects) on the same
+ * thread.
*/
- class sharedPortServer
- extends portServer
+ class sharedPortServer extends portServer
{
/**
* Create a new portServer, serving on specific port.
@@ -236,10 +231,10 @@ public class Functional_ORB
/**
* Perform a single serving step.
+ *
* @throws java.lang.Exception
*/
- void tick()
- throws Exception
+ void tick() throws Exception
{
Socket request = service.accept();
serveStep(request, false);
@@ -247,14 +242,14 @@ public class Functional_ORB
}
/**
- * The default value where the first instance of this ORB will start
- * looking for a free port.
+ * The default value where the first instance of this ORB will start looking
+ * for a free port.
*/
public static int DEFAULT_INITIAL_PORT = 1126;
/**
- * The property of port, on that this ORB is listening for requests from clients.
- * This class supports one port per ORB only.
+ * The property of port, on that this ORB is listening for requests from
+ * clients. This class supports one port per ORB only.
*/
public static final String LISTEN_ON = "gnu.classpath.CORBA.ListenOn";
@@ -264,12 +259,14 @@ public class Functional_ORB
public static final String REFERENCE = "org.omg.CORBA.ORBInitRef";
/**
- * The property, defining the port on that the default name service is running.
+ * The property, defining the port on that the default name service is
+ * running.
*/
public static final String NS_PORT = "org.omg.CORBA.ORBInitialPort";
/**
- * The property, defining the host on that the default name service is running.
+ * The property, defining the host on that the default name service is
+ * running.
*/
public static final String NS_HOST = "org.omg.CORBA.ORBInitialHost";
@@ -279,24 +276,25 @@ public class Functional_ORB
public static final String NAME_SERVICE = "NameService";
/**
- * The if the client has once opened a socket, it should start sending
- * the message header in a given time. Otherwise the server will close the
- * socket. This prevents server hang when the client opens the socket,
- * but does not send any message, usually due crash on the client side.
+ * The if the client has once opened a socket, it should start sending the
+ * message header in a given time. Otherwise the server will close the socket.
+ * This prevents server hang when the client opens the socket, but does not
+ * send any message, usually due crash on the client side.
*/
public static String START_READING_MESSAGE =
"gnu.classpath.CORBA.TOUT_START_READING_MESSAGE";
/**
- * If the client has started to send the request message, the socket time
- * out changes to the specified value.
+ * If the client has started to send the request message, the socket time out
+ * changes to the specified value.
*/
- public static String WHILE_READING = "gnu.classpath.CORBA.TOUT_WHILE_READING";
+ public static String WHILE_READING =
+ "gnu.classpath.CORBA.TOUT_WHILE_READING";
/**
- * If the message body is received, the time out changes to the
- * specifice value. This must be longer, as includes time, required to
- * process the received task. We make it 40 minutes.
+ * If the message body is received, the time out changes to the specifice
+ * value. This must be longer, as includes time, required to process the
+ * received task. We make it 40 minutes.
*/
public static String AFTER_RECEIVING =
"gnu.classpath.CORBA.TOUT_AFTER_RECEIVING";
@@ -307,53 +305,52 @@ public class Functional_ORB
public final String LOCAL_HOST;
/**
- * The if the client has once opened a socket, it should start sending
- * the message header in a given time. Otherwise the server will close the
- * socket. This prevents server hang when the client opens the socket,
- * but does not send any message, usually due crash on the client side.
+ * The if the client has once opened a socket, it should start sending the
+ * message header in a given time. Otherwise the server will close the socket.
+ * This prevents server hang when the client opens the socket, but does not
+ * send any message, usually due crash on the client side.
*/
private int TOUT_START_READING_MESSAGE = 20 * 1000;
// (Here and below, we use * to make the meaning of the constant clearler).
/**
- * If the client has started to send the request message, the socket time
- * out changes to the specified value.
+ * If the client has started to send the request message, the socket time out
+ * changes to the specified value.
*/
private int TOUT_WHILE_READING = 2 * 60 * 1000;
/**
- * If the message body is received, the time out changes to the
- * specifice value. This must be longer, as includes time, required to
- * process the received task. We make it 40 minutes.
+ * If the message body is received, the time out changes to the specifice
+ * value. This must be longer, as includes time, required to process the
+ * received task. We make it 40 minutes.
*/
private int TOUT_AFTER_RECEIVING = 40 * 60 * 1000;
/**
- * Some clients tend to submit multiple requests over the
- * same socket. The server waits for the next request on
- * the same socket for the duration, specified
- * below. In additions, the request of this implementation also
- * waits for the same duration before closing the socket.
- * The default time is seven seconds.
+ * Some clients tend to submit multiple requests over the same socket. The
+ * server waits for the next request on the same socket for the duration,
+ * specified below. In additions, the request of this implementation also
+ * waits for the same duration before closing the socket. The default time is
+ * seven seconds.
*/
public static int TANDEM_REQUESTS = 7000;
/**
* The map of the already conncted objects.
*/
- protected final Connected_objects connected_objects = new Connected_objects();
+ protected final Connected_objects connected_objects =
+ new Connected_objects();
/**
- * The maximal CORBA version, supported by this ORB. The default value
- * 0 means that the ORB will not check the request version while trying
- * to respond.
+ * The maximal CORBA version, supported by this ORB. The default value 0 means
+ * that the ORB will not check the request version while trying to respond.
*/
protected Version max_version;
/**
- * Setting this value to false causes the ORB to shutdown after the
- * latest serving operation is complete.
+ * Setting this value to false causes the ORB to shutdown after the latest
+ * serving operation is complete.
*/
protected boolean running;
@@ -373,12 +370,12 @@ public class Functional_ORB
private String ns_host;
/**
- * Probably free port, under that the ORB will try listening for
- * remote requests first. When the new object is connected, this
- * port is used first, then it is incremented by 1, etc. If the given
- * port is not available, up to 20 subsequent values are tried and then
- * the parameterless server socket contructor is called. The constant is
- * shared between multiple instances of this ORB.
+ * Probably free port, under that the ORB will try listening for remote
+ * requests first. When the new object is connected, this port is used first,
+ * then it is incremented by 1, etc. If the given port is not available, up to
+ * 20 subsequent values are tried and then the parameterless server socket
+ * contructor is called. The constant is shared between multiple instances of
+ * this ORB.
*/
private static int Port = DEFAULT_INITIAL_PORT;
@@ -404,10 +401,9 @@ public class Functional_ORB
protected Hashtable identities = new Hashtable();
/**
- * The maximal allowed number of the currently running parallel
- * threads per object. For security reasons, this is made private and
- * unchangeable. After exceeding this limit, the NO_RESOURCES
- * is thrown back to the client.
+ * The maximal allowed number of the currently running parallel threads per
+ * object. For security reasons, this is made private and unchangeable. After
+ * exceeding this limit, the NO_RESOURCES is thrown back to the client.
*/
private int MAX_RUNNING_THREADS = 256;
@@ -431,20 +427,19 @@ public class Functional_ORB
}
/**
- * If the max version is assigned, the orb replies with the error
- * message if the request version is above the supported 1.2 version.
- * This behavior is recommended by OMG, but not all implementations
- * respond that error message by re-sending the request, encoded in the older
- * version.
- */
+ * If the max version is assigned, the orb replies with the error message if
+ * the request version is above the supported 1.2 version. This behavior is
+ * recommended by OMG, but not all implementations respond that error message
+ * by re-sending the request, encoded in the older version.
+ */
public void setMaxVersion(Version max_supported)
{
max_version = max_supported;
}
/**
- * Get the maximal supported GIOP version or null if the version is
- * not checked.
+ * Get the maximal supported GIOP version or null if the version is not
+ * checked.
*/
public Version getMaxVersion()
{
@@ -452,17 +447,15 @@ public class Functional_ORB
}
/**
- * Get the currently free port, starting from the initially set port
- * and going up max 20 steps, then trying to bind into any free
- * address.
+ * Get the currently free port, starting from the initially set port and going
+ * up max 20 steps, then trying to bind into any free address.
*
* @return the currently available free port.
*
- * @throws NO_RESOURCES if the server socked cannot be opened on the
- * local host.
+ * @throws NO_RESOURCES if the server socked cannot be opened on the local
+ * host.
*/
- public int getFreePort()
- throws BAD_OPERATION
+ public int getFreePort() throws BAD_OPERATION
{
ServerSocket s;
int a_port;
@@ -519,12 +512,11 @@ public class Functional_ORB
}
/**
- * Set the port, on that the server is listening for the client requests.
- * If only one object is connected to the orb, the server will be
- * try listening on this port first. It the port is busy, or if more
- * objects are connected, the subsequent object will receive a larger
- * port values, skipping unavailable ports, if required. The change
- * applies globally.
+ * Set the port, on that the server is listening for the client requests. If
+ * only one object is connected to the orb, the server will be try listening
+ * on this port first. It the port is busy, or if more objects are connected,
+ * the subsequent object will receive a larger port values, skipping
+ * unavailable ports, if required. The change applies globally.
*
* @param a_Port a port, on that the server is listening for requests.
*/
@@ -534,14 +526,13 @@ public class Functional_ORB
}
/**
- * Connect the given CORBA object to this ORB. After the object is
- * connected, it starts receiving remote invocations via this ORB.
+ * Connect the given CORBA object to this ORB. After the object is connected,
+ * it starts receiving remote invocations via this ORB.
*
- * The ORB tries to connect the object to the port, that has been
- * previously set by {@link setPort(int)}. On failure, it tries
- * 20 subsequent larger values and then calls the parameterless
- * server socked constructor to get any free local port.
- * If this fails, the {@link NO_RESOURCES} is thrown.
+ * The ORB tries to connect the object to the port, that has been previously
+ * set by {@link setPort(int)}. On failure, it tries 20 subsequent larger
+ * values and then calls the parameterless server socked constructor to get
+ * any free local port. If this fails, the {@link NO_RESOURCES} is thrown.
*
* @param object the object, must implement the {@link InvokeHandler})
* interface.
@@ -561,19 +552,18 @@ public class Functional_ORB
}
/**
- * Connect the given CORBA object to this ORB, explicitly specifying
- * the object key.
+ * Connect the given CORBA object to this ORB, explicitly specifying the
+ * object key.
*
- * The ORB tries to connect the object to the port, that has been
- * previously set by {@link setPort(int)}. On failure, it tries
- * 20 subsequent larger values and then calls the parameterless
- * server socked constructor to get any free local port.
- * If this fails, the {@link NO_RESOURCES} is thrown.
+ * The ORB tries to connect the object to the port, that has been previously
+ * set by {@link setPort(int)}. On failure, it tries 20 subsequent larger
+ * values and then calls the parameterless server socked constructor to get
+ * any free local port. If this fails, the {@link NO_RESOURCES} is thrown.
*
* @param object the object, must implement the {@link InvokeHandler})
* interface.
- * @param key the object key, usually used to identify the object from
- * remote side.
+ * @param key the object key, usually used to identify the object from remote
+ * side.
*
* @throws BAD_PARAM if the object does not implement the
* {@link InvokeHandler}).
@@ -591,31 +581,30 @@ public class Functional_ORB
}
/**
- * Connect the given CORBA object to this ORB, explicitly specifying
- * the object key and the identity of the thread (and port), where the
- * object must be served. The identity is normally the POA.
+ * Connect the given CORBA object to this ORB, explicitly specifying the
+ * object key and the identity of the thread (and port), where the object must
+ * be served. The identity is normally the POA.
*
- * The new port server will be started only if there is no one
- * already running for the same identity. Otherwise, the task of
- * the existing port server will be widened, including duty to serve
- * the given object. All objects, connected to a single identity by
- * this method, will process they requests subsequently in the same
- * thread. The method is used when the expected number of the
- * objects is too large to have a single port and thread per object.
- * This method is used by POAs, having a single thread policy.
+ * The new port server will be started only if there is no one already running
+ * for the same identity. Otherwise, the task of the existing port server will
+ * be widened, including duty to serve the given object. All objects,
+ * connected to a single identity by this method, will process they requests
+ * subsequently in the same thread. The method is used when the expected
+ * number of the objects is too large to have a single port and thread per
+ * object. This method is used by POAs, having a single thread policy.
*
* @param object the object, must implement the {@link InvokeHandler})
* interface.
- * @param key the object key, usually used to identify the object from
- * remote side.
+ * @param key the object key, usually used to identify the object from remote
+ * side.
* @param port the port, where the object must be connected.
*
* @throws BAD_PARAM if the object does not implement the
* {@link InvokeHandler}).
*/
public void connect_1_thread(org.omg.CORBA.Object object, byte[] key,
- java.lang.Object identity
- )
+ java.lang.Object identity
+ )
{
sharedPortServer shared = (sharedPortServer) identities.get(identity);
if (shared == null)
@@ -653,23 +642,22 @@ public class Functional_ORB
*/
public void destroy()
{
- super.destroy();
-
portServer p;
for (int i = 0; i < portServers.size(); i++)
{
p = (portServer) portServers.get(i);
p.close_now();
}
+ super.destroy();
}
/**
- * Disconnect the given CORBA object from this ORB. The object will be
- * no longer receiving the remote invocations. In response to the
- * remote invocation on this object, the ORB will send the
- * exception {@link OBJECT_NOT_EXIST}. The object, however, is not
- * destroyed and can receive the local invocations.
-
+ * Disconnect the given CORBA object from this ORB. The object will be no
+ * longer receiving the remote invocations. In response to the remote
+ * invocation on this object, the ORB will send the exception
+ * {@link OBJECT_NOT_EXIST}. The object, however, is not destroyed and can
+ * receive the local invocations.
+ *
* @param object the object to disconnect.
*/
public void disconnect(org.omg.CORBA.Object object)
@@ -692,8 +680,6 @@ public class Functional_ORB
// object implementation.
if (rmKey == null)
rmKey = connected_objects.getKey(object);
-
- // Disconnect the object on any success.
if (rmKey != null)
{
// Find and stop the corresponding portServer.
@@ -714,10 +700,10 @@ public class Functional_ORB
}
/**
- * Notifies ORB that the shared service indentity (usually POA)
- * is destroyed. The matching shared port server is terminated
- * and the identity table entry is deleted. If this identity
- * is not known for this ORB, the method returns without action.
+ * Notifies ORB that the shared service indentity (usually POA) is destroyed.
+ * The matching shared port server is terminated and the identity table entry
+ * is deleted. If this identity is not known for this ORB, the method returns
+ * without action.
*
* @param identity the identity that has been destroyed.
*/
@@ -728,24 +714,24 @@ public class Functional_ORB
sharedPortServer ise = (sharedPortServer) identities.get(identity);
if (ise != null)
- synchronized (connected_objects)
- {
- ise.close_now();
- identities.remove(identity);
+ {
+ synchronized (connected_objects)
+ {
+ ise.close_now();
+ identities.remove(identity);
- Connected_objects.cObject obj;
- Map.Entry m;
- Iterator iter = connected_objects.entrySet().iterator();
- while (iter.hasNext())
- {
- m = (Map.Entry) iter.next();
- obj = (Connected_objects.cObject) m.getValue();
- if (obj.identity == identity)
- {
+ Connected_objects.cObject obj;
+ Map.Entry m;
+ Iterator iter = connected_objects.entrySet().iterator();
+ while (iter.hasNext())
+ {
+ m = (Map.Entry) iter.next();
+ obj = (Connected_objects.cObject) m.getValue();
+ if (obj.identity == identity)
iter.remove();
- }
- }
- }
+ }
+ }
+ }
}
/**
@@ -753,8 +739,8 @@ public class Functional_ORB
*
* @param ior the ior of the potentially local object.
*
- * @return the local object, represented by the given IOR,
- * or null if this is not a local connected object.
+ * @return the local object, represented by the given IOR, or null if this is
+ * not a local connected object.
*/
public org.omg.CORBA.Object find_local_object(IOR ior)
{
@@ -783,26 +769,26 @@ public class Functional_ORB
Iterator iter = initial_references.keySet().iterator();
while (iter.hasNext())
- refs [ p++ ] = (String) iter.next();
-
+ {
+ refs [ p++ ] = (String) iter.next();
+ }
return refs;
}
/**
- * Get the IOR reference string for the given object.
- * The string embeds information about the object
- * repository Id, its access key and the server internet
- * address and port. With this information, the object
- * can be found by another ORB, possibly located on remote
- * computer.
+ * Get the IOR reference string for the given object. The string embeds
+ * information about the object repository Id, its access key and the server
+ * internet address and port. With this information, the object can be found
+ * by another ORB, possibly located on remote computer.
*
* @param the CORBA object
* @return the object IOR representation.
*
- * @throws BAD_PARAM if the object has not been previously
- * connected to this ORB.
- * @throws BAD_OPERATION in the unlikely case if the local host
- * address cannot be resolved.
+ * @throws BAD_PARAM if the object has not been previously connected to this
+ * ORB.
+ *
+ * @throws BAD_OPERATION in the unlikely case if the local host address cannot
+ * be resolved.
*
* @see string_to_object(String)
*/
@@ -821,8 +807,8 @@ public class Functional_ORB
if (rec == null)
throw new BAD_PARAM("The object " + forObject +
- " has not been previously connected to this ORB"
- );
+ " has not been previously connected to this ORB"
+ );
IOR ior = createIOR(rec);
@@ -830,17 +816,28 @@ public class Functional_ORB
}
/**
- * Find and return the easily accessible CORBA object, addressed
- * by name.
+ * Get the local IOR for the given object, null if the object is not local.
+ */
+ public IOR getLocalIor(org.omg.CORBA.Object forObject)
+ {
+ Connected_objects.cObject rec = connected_objects.getKey(forObject);
+ if (rec == null)
+ return null;
+ else
+ return createIOR(rec);
+ }
+
+ /**
+ * Find and return the easily accessible CORBA object, addressed by name.
*
* @param name the object name.
* @return the object
*
- * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name
- * is not associated with the known object.
+ * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name is not
+ * associated with the known object.
*/
public org.omg.CORBA.Object resolve_initial_references(String name)
- throws InvalidName
+ throws InvalidName
{
org.omg.CORBA.Object object = null;
try
@@ -866,9 +863,8 @@ public class Functional_ORB
}
/**
- * Start the ORBs main working cycle
- * (receive invocation - invoke on the local object - send response -
- * wait for another invocation).
+ * Start the ORBs main working cycle (receive invocation - invoke on the local
+ * object - send response - wait for another invocation).
*
* The method only returns after calling {@link #shutdown(boolean)}.
*/
@@ -894,9 +890,7 @@ public class Functional_ORB
portServers.add(subserver);
}
else
- {
- subserver = (portServer) identities.get(obj.identity);
- }
+ subserver = (portServer) identities.get(obj.identity);
if (!subserver.isAlive())
{
@@ -917,8 +911,8 @@ public class Functional_ORB
/**
* Shutdown the ORB server.
*
- * @param wait_for_completion if true, the current thread is
- * suspended until the shutdown process is complete.
+ * @param wait_for_completion if true, the current thread is suspended until
+ * the shutdown process is complete.
*/
public void shutdown(boolean wait_for_completion)
{
@@ -936,10 +930,10 @@ public class Functional_ORB
}
/**
- * Find and return the CORBA object, addressed by the given
- * IOR string representation. The object can (an usually is)
- * located on a remote computer, possibly running a different
- * (not necessary java) CORBA implementation.
+ * Find and return the CORBA object, addressed by the given IOR string
+ * representation. The object can (an usually is) located on a remote
+ * computer, possibly running a different (not necessary java) CORBA
+ * implementation.
*
* @param ior the object IOR representation string.
*
@@ -956,9 +950,7 @@ public class Functional_ORB
try
{
if (impl._get_delegate() == null)
- {
- impl._set_delegate(new IOR_Delegate(this, ior));
- }
+ impl._set_delegate(new IOR_Delegate(this, ior));
}
catch (BAD_OPERATION ex)
{
@@ -974,15 +966,13 @@ public class Functional_ORB
}
/**
- * Get the default naming service for the case when there no
- * NameService entries.
+ * Get the default naming service for the case when there no NameService
+ * entries.
*/
protected org.omg.CORBA.Object getDefaultNameService()
{
if (initial_references.containsKey(NAME_SERVICE))
- {
- return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE);
- }
+ return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE);
IOR ior = new IOR();
ior.Id = NamingContextExtHelper.id();
@@ -997,8 +987,8 @@ public class Functional_ORB
}
/**
- * Find and return the object, that must be previously connected
- * to this ORB. Return null if no such object is available.
+ * Find and return the object, that must be previously connected to this ORB.
+ * Return null if no such object is available.
*
* @param key the object key.
*
@@ -1017,8 +1007,7 @@ public class Functional_ORB
* @param app the current applet.
*
* @param props application specific properties, passed as the second
- * parameter in {@link #init(Applet, Properties)}.
- * Can be <code>null</code>.
+ * parameter in {@link #init(Applet, Properties)}. Can be <code>null</code>.
*/
protected void set_parameters(Applet app, Properties props)
{
@@ -1031,27 +1020,23 @@ public class Functional_ORB
{
if (para [ i ] [ 0 ].equals(LISTEN_ON))
Port = Integer.parseInt(para [ i ] [ 1 ]);
-
if (para [ i ] [ 0 ].equals(REFERENCE))
{
- StringTokenizer st = new StringTokenizer(para [ i ] [ 1 ], "=");
+ StringTokenizer st =
+ new StringTokenizer(para [ i ] [ 1 ], "=");
initial_references.put(st.nextToken(),
- string_to_object(st.nextToken())
- );
+ string_to_object(st.nextToken())
+ );
}
if (para [ i ] [ 0 ].equals(NS_HOST))
ns_host = para [ i ] [ 1 ];
-
if (para [ i ] [ 0 ].equals(START_READING_MESSAGE))
TOUT_START_READING_MESSAGE = Integer.parseInt(para [ i ] [ 1 ]);
-
if (para [ i ] [ 0 ].equals(WHILE_READING))
TOUT_WHILE_READING = Integer.parseInt(para [ i ] [ 1 ]);
-
if (para [ i ] [ 0 ].equals(AFTER_RECEIVING))
TOUT_AFTER_RECEIVING = Integer.parseInt(para [ i ] [ 1 ]);
-
try
{
if (para [ i ] [ 0 ].equals(NS_PORT))
@@ -1061,9 +1046,9 @@ public class Functional_ORB
{
BAD_PARAM bad =
new BAD_PARAM("Invalid " + NS_PORT +
- "property, unable to parse '" +
- props.getProperty(NS_PORT) + "'"
- );
+ "property, unable to parse '" +
+ props.getProperty(NS_PORT) + "'"
+ );
bad.initCause(ex);
throw bad;
}
@@ -1075,52 +1060,54 @@ public class Functional_ORB
* Set the ORB parameters. This method is normally called from
* {@link #init(String[], Properties)}.
*
- * @param para the parameters, that were passed as the parameters
- * to the <code>main(String[] args)</code> method of the current standalone
+ * @param para the parameters, that were passed as the parameters to the
+ * <code>main(String[] args)</code> method of the current standalone
* application.
*
- * @param props application specific properties that were passed
- * as a second parameter in {@link init(String[], Properties)}).
- * Can be <code>null</code>.
+ * @param props application specific properties that were passed as a second
+ * parameter in {@link init(String[], Properties)}). Can be <code>null</code>.
*/
protected void set_parameters(String[] para, Properties props)
{
if (para.length > 1)
- for (int i = 0; i < para.length - 1; i++)
- {
- if (para [ i ].endsWith("ListenOn"))
- Port = Integer.parseInt(para [ i + 1 ]);
-
- if (para [ i ].endsWith("ORBInitRef"))
- {
- StringTokenizer st = new StringTokenizer(para [ i + 1 ], "=");
- initial_references.put(st.nextToken(),
- string_to_object(st.nextToken())
- );
- }
-
- if (para [ i ].endsWith("ORBInitialHost"))
- ns_host = para [ i + 1 ];
+ {
+ for (int i = 0; i < para.length - 1; i++)
+ {
+ if (para [ i ].endsWith("ListenOn"))
+ Port = Integer.parseInt(para [ i + 1 ]);
+ if (para [ i ].endsWith("ORBInitRef"))
+ {
+ StringTokenizer st = new StringTokenizer(para [ i + 1 ], "=");
+ initial_references.put(st.nextToken(),
+ string_to_object(st.nextToken())
+ );
+ }
- try
- {
- if (para [ i ].endsWith("ORBInitialPort"))
- ns_port = Integer.parseInt(para [ i + 1 ]);
- }
- catch (NumberFormatException ex)
- {
- throw new BAD_PARAM("Invalid " + para [ i ] +
- "parameter, unable to parse '" +
- props.getProperty(para [ i + 1 ]) + "'"
- );
- }
- }
+ if (para [ i ].endsWith("ORBInitialHost"))
+ ns_host = para [ i + 1 ];
+ try
+ {
+ if (para [ i ].endsWith("ORBInitialPort"))
+ ns_port = Integer.parseInt(para [ i + 1 ]);
+ }
+ catch (NumberFormatException ex)
+ {
+ throw new BAD_PARAM("Invalid " + para [ i ] +
+ "parameter, unable to parse '" +
+ props.getProperty(para [ i + 1 ]) + "'"
+ );
+ }
+ }
+ }
useProperties(props);
}
- private IOR createIOR(Connected_objects.cObject ref)
- throws BAD_OPERATION
+ /**
+ * Create IOR for the given object references.
+ */
+ protected IOR createIOR(Connected_objects.cObject ref)
+ throws BAD_OPERATION
{
IOR ior = new IOR();
ior.key = ref.key;
@@ -1134,7 +1121,6 @@ public class Functional_ORB
}
if (ior.Id == null)
ior.Id = ref.object.getClass().getName();
-
try
{
ior.Internet.host = InetAddress.getLocalHost().getHostAddress();
@@ -1156,13 +1142,12 @@ public class Functional_ORB
* {@link InvokeHandler}).
*/
private void prepareObject(org.omg.CORBA.Object object, IOR ior)
- throws BAD_PARAM
+ throws BAD_PARAM
{
/*
- if (!(object instanceof InvokeHandler))
- throw new BAD_PARAM(object.getClass().getName() +
- " does not implement InvokeHandler. "
- );
+ * if (!(object instanceof InvokeHandler)) throw new
+ * BAD_PARAM(object.getClass().getName() + " does not implement
+ * InvokeHandler. " );
*/
// If no delegate is set, set the default delegate.
@@ -1172,9 +1157,7 @@ public class Functional_ORB
try
{
if (impl._get_delegate() == null)
- {
- impl._set_delegate(new Simple_delegate(this, ior));
- }
+ impl._set_delegate(new Simple_delegate(this, ior));
}
catch (BAD_OPERATION ex)
{
@@ -1190,20 +1173,17 @@ public class Functional_ORB
* @param net_out the stream to write response into
* @param msh_request the request message header
* @param rh_request the request header
- * @param handler the invocation handler that has been used to
- * invoke the operation
- * @param sysEx the system exception, thrown during the invocation,
- * null if none.
+ * @param handler the invocation handler that has been used to invoke the
+ * operation
+ * @param sysEx the system exception, thrown during the invocation, null if
+ * none.
*
* @throws IOException
*/
private void respond_to_client(OutputStream net_out,
- MessageHeader msh_request,
- RequestHeader rh_request,
- bufferedResponseHandler handler,
- SystemException sysEx
- )
- throws IOException
+ MessageHeader msh_request, RequestHeader rh_request,
+ bufferedResponseHandler handler, SystemException sysEx
+ ) throws IOException
{
// Set the reply header properties.
ReplyHeader reply = handler.reply_header;
@@ -1214,17 +1194,23 @@ public class Functional_ORB
reply.reply_status = ReplyHeader.USER_EXCEPTION;
else
reply.reply_status = ReplyHeader.NO_EXCEPTION;
-
reply.request_id = rh_request.request_id;
- cdrBufOutput out = new cdrBufOutput(50 + handler.getBuffer().buffer.size());
+ cdrBufOutput out =
+ new cdrBufOutput(50 + handler.getBuffer().buffer.size());
out.setOrb(this);
out.setOffset(msh_request.getHeaderSize());
reply.write(out);
- // Write the reply data from the handler.
+ if (msh_request.version.since_inclusive(1, 2))
+ {
+ out.align(8);
+
+ // Write the reply data from the handler. The handler data already
+ // include the necessary heading zeroes for alignment.
+ }
handler.getBuffer().buffer.writeTo(out);
MessageHeader msh_reply = new MessageHeader();
@@ -1240,13 +1226,11 @@ public class Functional_ORB
}
/**
- * Forward request to another target, as indicated by the passed
- * exception.
+ * Forward request to another target, as indicated by the passed exception.
*/
- private void forward_request(OutputStream net_out, MessageHeader msh_request,
- RequestHeader rh_request, gnuForwardRequest info
- )
- throws IOException
+ private void forward_request(OutputStream net_out,
+ MessageHeader msh_request, RequestHeader rh_request, gnuForwardRequest info
+ ) throws IOException
{
MessageHeader msh_forward = new MessageHeader();
msh_forward.version = msh_request.version;
@@ -1265,7 +1249,6 @@ public class Functional_ORB
if (msh_forward.version.since_inclusive(1, 2))
out.align(8);
-
out.write_Object(info.forward_reference);
msh_forward.message_size = out.buffer.size();
@@ -1279,17 +1262,17 @@ public class Functional_ORB
/**
* Contains a single servicing task.
*
- * Normally, each task matches a single remote invocation.
- * However under frequent tandem submissions the same
- * task may span over several invocations.
+ * Normally, each task matches a single remote invocation. However under
+ * frequent tandem submissions the same task may span over several
+ * invocations.
*
* @param serverSocket the ORB server socket.
*
* @throws MARSHAL
* @throws IOException
*/
- private void serve(final portServer p, ServerSocket serverSocket)
- throws MARSHAL, IOException
+ void serve(final portServer p, ServerSocket serverSocket)
+ throws MARSHAL, IOException
{
final Socket service;
service = serverSocket.accept();
@@ -1327,15 +1310,15 @@ public class Functional_ORB
/**
* A single servicing step, when the client socket is alrady open.
*
- * Normally, each task matches a single remote invocation.
- * However under frequent tandem submissions the same
- * task may span over several invocations.
+ * Normally, each task matches a single remote invocation. However under
+ * frequent tandem submissions the same task may span over several
+ * invocations.
*
* @param service the opened client socket.
- * @param no_resources if true, the "NO RESOURCES" exception
- * is thrown to the client.
+ * @param no_resources if true, the "NO RESOURCES" exception is thrown to the
+ * client.
*/
- private void serveStep(Socket service, boolean no_resources)
+ void serveStep(Socket service, boolean no_resources)
{
try
{
@@ -1358,15 +1341,17 @@ public class Functional_ORB
}
if (max_version != null)
- if (!msh_request.version.until_inclusive(max_version.major,
- max_version.minor
- )
- )
- {
- OutputStream out = service.getOutputStream();
- new ErrorMessage(max_version).write(out);
- return;
- }
+ {
+ if (!msh_request.version.until_inclusive(max_version.major,
+ max_version.minor
+ )
+ )
+ {
+ OutputStream out = service.getOutputStream();
+ new ErrorMessage(max_version).write(out);
+ return;
+ }
+ }
byte[] r = new byte[ msh_request.message_size ];
@@ -1400,9 +1385,12 @@ public class Functional_ORB
// in 1.2 and higher, align the current position at
// 8 octet boundary.
if (msh_request.version.since_inclusive(1, 2))
- cin.align(8);
+ {
+ cin.align(8);
+
+ // find the target object.
+ }
- // find the target object.
InvokeHandler target =
(InvokeHandler) find_connected_object(rh_request.object_key);
@@ -1413,7 +1401,9 @@ public class Functional_ORB
// TODO log errors about not existing objects and methods.
bufferedResponseHandler handler =
- new bufferedResponseHandler(this, msh_request, rh_reply);
+ new bufferedResponseHandler(this, msh_request, rh_reply,
+ rh_request
+ );
SystemException sysEx = null;
@@ -1449,7 +1439,9 @@ public class Functional_ORB
{
except.printStackTrace();
sysEx =
- new UNKNOWN("Unknown", 2, CompletionStatus.COMPLETED_MAYBE);
+ new UNKNOWN("Unknown", 2,
+ CompletionStatus.COMPLETED_MAYBE
+ );
org.omg.CORBA.portable.OutputStream ech =
handler.createExceptionReply();
@@ -1462,13 +1454,13 @@ public class Functional_ORB
{
OutputStream sou = service.getOutputStream();
respond_to_client(sou, msh_request, rh_request, handler,
- sysEx
- );
+ sysEx
+ );
}
}
else if (msh_request.message_type == MessageHeader.CLOSE_CONNECTION ||
- msh_request.message_type == MessageHeader.MESSAGE_ERROR
- )
+ msh_request.message_type == MessageHeader.MESSAGE_ERROR
+ )
{
CloseMessage.close(service.getOutputStream());
service.close();
@@ -1478,11 +1470,10 @@ public class Functional_ORB
// TODO log error: "Not a request message."
if (service != null && !service.isClosed())
- {
- // Wait for the subsequent invocations on the
- // same socket for the TANDEM_REQUEST duration.
- service.setSoTimeout(TANDEM_REQUESTS);
- }
+
+ // Wait for the subsequent invocations on the
+ // same socket for the TANDEM_REQUEST duration.
+ service.setSoTimeout(TANDEM_REQUESTS);
else
return;
}
@@ -1506,23 +1497,18 @@ public class Functional_ORB
{
if (props.containsKey(LISTEN_ON))
Port = Integer.parseInt(props.getProperty(LISTEN_ON));
-
if (props.containsKey(NS_HOST))
ns_host = props.getProperty(NS_HOST);
-
try
{
if (props.containsKey(NS_PORT))
ns_port = Integer.parseInt(props.getProperty(NS_PORT));
-
if (props.containsKey(START_READING_MESSAGE))
TOUT_START_READING_MESSAGE =
Integer.parseInt(props.getProperty(START_READING_MESSAGE));
-
if (props.containsKey(WHILE_READING))
TOUT_WHILE_READING =
Integer.parseInt(props.getProperty(WHILE_READING));
-
if (props.containsKey(AFTER_RECEIVING))
TOUT_AFTER_RECEIVING =
Integer.parseInt(props.getProperty(AFTER_RECEIVING));
@@ -1530,9 +1516,9 @@ public class Functional_ORB
catch (NumberFormatException ex)
{
throw new BAD_PARAM("Invalid " + NS_PORT +
- "property, unable to parse '" +
- props.getProperty(NS_PORT) + "'"
- );
+ "property, unable to parse '" + props.getProperty(NS_PORT) +
+ "'"
+ );
}
Enumeration en = props.elements();
@@ -1541,33 +1527,31 @@ public class Functional_ORB
String item = (String) en.nextElement();
if (item.equals(REFERENCE))
initial_references.put(item,
- string_to_object(props.getProperty(item))
- );
+ string_to_object(props.getProperty(item))
+ );
}
}
}
/**
- * Get the next instance with a response being received. If all currently
- * sent responses not yet processed, this method pauses till at least one of
- * them is complete. If there are no requests currently sent, the method
- * pauses till some request is submitted and the response is received.
- * This strategy is identical to the one accepted by Suns 1.4 ORB
- * implementation.
+ * Get the next instance with a response being received. If all currently sent
+ * responses not yet processed, this method pauses till at least one of them
+ * is complete. If there are no requests currently sent, the method pauses
+ * till some request is submitted and the response is received. This strategy
+ * is identical to the one accepted by Suns 1.4 ORB implementation.
*
- * The returned response is removed from the list of the currently
- * submitted responses and is never returned again.
+ * The returned response is removed from the list of the currently submitted
+ * responses and is never returned again.
*
* @return the previously sent request that now contains the received
* response.
*
* @throws WrongTransaction If the method was called from the transaction
- * scope different than the one, used to send the request. The exception
- * can be raised only if the request is implicitly associated with some
- * particular transaction.
+ * scope different than the one, used to send the request. The exception can
+ * be raised only if the request is implicitly associated with some particular
+ * transaction.
*/
- public Request get_next_response()
- throws org.omg.CORBA.WrongTransaction
+ public Request get_next_response() throws org.omg.CORBA.WrongTransaction
{
return asynchron.get_next_response();
}
@@ -1576,8 +1560,8 @@ public class Functional_ORB
* Find if any of the requests that have been previously sent with
* {@link #send_multiple_requests_deferred}, have a response yet.
*
- * @return true if there is at least one response to the previously
- * sent request, false otherwise.
+ * @return true if there is at least one response to the previously sent
+ * request, false otherwise.
*/
public boolean poll_next_response()
{
@@ -1585,12 +1569,12 @@ public class Functional_ORB
}
/**
- * Send multiple prepared requests expecting to get a reply. All requests
- * are send in parallel, each in its own separate thread. When the
- * reply arrives, it is stored in the agreed fields of the corresponing
- * request data structure. If this method is called repeatedly,
- * the new requests are added to the set of the currently sent requests,
- * but the old set is not discarded.
+ * Send multiple prepared requests expecting to get a reply. All requests are
+ * send in parallel, each in its own separate thread. When the reply arrives,
+ * it is stored in the agreed fields of the corresponing request data
+ * structure. If this method is called repeatedly, the new requests are added
+ * to the set of the currently sent requests, but the old set is not
+ * discarded.
*
* @param requests the prepared array of requests.
*
@@ -1605,8 +1589,8 @@ public class Functional_ORB
/**
* Send multiple prepared requests one way, do not caring about the answer.
- * The messages, containing requests, will be marked, indicating that
- * the sender is not expecting to get a reply.
+ * The messages, containing requests, will be marked, indicating that the
+ * sender is not expecting to get a reply.
*
* @param requests the prepared array of requests.
*
@@ -1620,8 +1604,7 @@ public class Functional_ORB
/**
* Set the flag, forcing all server threads to terminate.
*/
- protected void finalize()
- throws java.lang.Throwable
+ protected void finalize() throws java.lang.Throwable
{
running = false;
super.finalize();