1 |
/* FunctionalORB.java -- |
/* Functional_ORB.java -- |
2 |
Copyright (C) 2005 Free Software Foundation, Inc. |
Copyright (C) 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
45 |
import gnu.CORBA.GIOP.MessageHeader; |
import gnu.CORBA.GIOP.MessageHeader; |
46 |
import gnu.CORBA.GIOP.ReplyHeader; |
import gnu.CORBA.GIOP.ReplyHeader; |
47 |
import gnu.CORBA.GIOP.RequestHeader; |
import gnu.CORBA.GIOP.RequestHeader; |
48 |
|
import gnu.CORBA.NamingService.NameParser; |
49 |
import gnu.CORBA.NamingService.NamingServiceTransient; |
import gnu.CORBA.NamingService.NamingServiceTransient; |
50 |
import gnu.CORBA.Poa.gnuForwardRequest; |
import gnu.CORBA.Poa.gnuForwardRequest; |
51 |
|
|
52 |
import org.omg.CORBA.BAD_OPERATION; |
import org.omg.CORBA.BAD_OPERATION; |
53 |
import org.omg.CORBA.BAD_PARAM; |
import org.omg.CORBA.BAD_PARAM; |
54 |
import org.omg.CORBA.CompletionStatus; |
import org.omg.CORBA.CompletionStatus; |
55 |
|
import org.omg.CORBA.DATA_CONVERSION; |
56 |
import org.omg.CORBA.MARSHAL; |
import org.omg.CORBA.MARSHAL; |
57 |
import org.omg.CORBA.NO_RESOURCES; |
import org.omg.CORBA.NO_RESOURCES; |
58 |
import org.omg.CORBA.OBJECT_NOT_EXIST; |
import org.omg.CORBA.OBJECT_NOT_EXIST; |
59 |
|
import org.omg.CORBA.Object; |
60 |
import org.omg.CORBA.ORBPackage.InvalidName; |
import org.omg.CORBA.ORBPackage.InvalidName; |
61 |
import org.omg.CORBA.Request; |
import org.omg.CORBA.Request; |
62 |
import org.omg.CORBA.SystemException; |
import org.omg.CORBA.SystemException; |
63 |
import org.omg.CORBA.UNKNOWN; |
import org.omg.CORBA.UNKNOWN; |
64 |
|
import org.omg.CORBA.WrongTransaction; |
65 |
import org.omg.CORBA.portable.Delegate; |
import org.omg.CORBA.portable.Delegate; |
66 |
import org.omg.CORBA.portable.InvokeHandler; |
import org.omg.CORBA.portable.InvokeHandler; |
67 |
import org.omg.CORBA.portable.ObjectImpl; |
import org.omg.CORBA.portable.ObjectImpl; |
92 |
|
|
93 |
/** |
/** |
94 |
* The ORB implementation, capable to handle remote invocations on the |
* The ORB implementation, capable to handle remote invocations on the |
95 |
* registered object. This class implements all features, required till |
* registered object. This class implements all features, required till the jdk |
96 |
* the jdk 1.3 inclusive, but does not support the POA that appears since |
* 1.3 inclusive, but does not support the POA that appears since 1.4. The POA |
97 |
* 1.4. The POA is supported by {@link gnu.CORBA.Poa.ORB_1_4}. |
* is supported by {@link gnu.CORBA.Poa.ORB_1_4}. |
98 |
* |
* |
99 |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
100 |
*/ |
*/ |
101 |
public class Functional_ORB |
public class Functional_ORB extends Restricted_ORB |
|
extends Restricted_ORB |
|
102 |
{ |
{ |
103 |
/** |
/** |
104 |
* A server, responsible for listening on requests on some |
* A server, responsible for listening on requests on some local port. The ORB |
105 |
* local port. The ORB may listen on multiple ports and process |
* may listen on multiple ports and process the requests in separate threads. |
106 |
* the requests in separate threads. Normally the server takes |
* Normally the server takes one port per object being served. |
|
* one port per object being served. |
|
107 |
*/ |
*/ |
108 |
class portServer |
class portServer extends Thread |
|
extends Thread |
|
109 |
{ |
{ |
110 |
/** |
/** |
111 |
* The number of the currently running parallel threads. |
* The number of the currently running parallel threads. |
112 |
*/ |
*/ |
113 |
private int running_threads; |
int running_threads; |
114 |
|
|
115 |
/** |
/** |
116 |
* The port on that this portServer is listening for requests. |
* The port on that this portServer is listening for requests. |
123 |
ServerSocket service; |
ServerSocket service; |
124 |
|
|
125 |
/** |
/** |
126 |
* True if the serving node must shutdown due |
* True if the serving node must shutdown due call of the close_now(). |
|
* call of the close_now(). |
|
127 |
*/ |
*/ |
128 |
boolean terminated; |
boolean terminated; |
129 |
|
|
136 |
} |
} |
137 |
|
|
138 |
/** |
/** |
139 |
* Enter the serving loop (get request/process it). |
* Enter the serving loop (get request/process it). All portServer normally |
140 |
* All portServer normally terminate thy threads when |
* terminate thy threads when the Functional_ORB.running is set to false. |
|
* the Functional_ORB.running is set to false. |
|
141 |
*/ |
*/ |
142 |
public void run() |
public void run() |
143 |
{ |
{ |
183 |
|
|
184 |
/** |
/** |
185 |
* Perform a single serving step. |
* Perform a single serving step. |
186 |
|
* |
187 |
* @throws java.lang.Exception |
* @throws java.lang.Exception |
188 |
*/ |
*/ |
189 |
void tick() |
void tick() throws Exception |
|
throws Exception |
|
190 |
{ |
{ |
191 |
serve(this, service); |
serve(this, service); |
192 |
} |
} |
218 |
} |
} |
219 |
|
|
220 |
/** |
/** |
221 |
* A server, responsible for listening on requests on some |
* A server, responsible for listening on requests on some local port and |
222 |
* local port and serving multiple requests (probably to the |
* serving multiple requests (probably to the different objects) on the same |
223 |
* different objects) on the same thread. |
* thread. |
224 |
*/ |
*/ |
225 |
class sharedPortServer |
class sharedPortServer extends portServer |
|
extends portServer |
|
226 |
{ |
{ |
227 |
/** |
/** |
228 |
* Create a new portServer, serving on specific port. |
* Create a new portServer, serving on specific port. |
234 |
|
|
235 |
/** |
/** |
236 |
* Perform a single serving step. |
* Perform a single serving step. |
237 |
|
* |
238 |
* @throws java.lang.Exception |
* @throws java.lang.Exception |
239 |
*/ |
*/ |
240 |
void tick() |
void tick() throws Exception |
|
throws Exception |
|
241 |
{ |
{ |
242 |
Socket request = service.accept(); |
Socket request = service.accept(); |
243 |
serveStep(request, false); |
serveStep(request, false); |
245 |
} |
} |
246 |
|
|
247 |
/** |
/** |
248 |
* The default value where the first instance of this ORB will start |
* The default value where the first instance of this ORB will start looking |
249 |
* looking for a free port. |
* for a free port. |
250 |
*/ |
*/ |
251 |
public static int DEFAULT_INITIAL_PORT = 1126; |
public static int DEFAULT_INITIAL_PORT = 1126; |
252 |
|
|
253 |
/** |
/** |
254 |
* The property of port, on that this ORB is listening for requests from clients. |
* The property of port, on that this ORB is listening for requests from |
255 |
* This class supports one port per ORB only. |
* clients. This class supports one port per ORB only. |
256 |
*/ |
*/ |
257 |
public static final String LISTEN_ON = "gnu.classpath.CORBA.ListenOn"; |
public static final String LISTEN_ON = "gnu.classpath.CORBA.ListenOn"; |
258 |
|
|
262 |
public static final String REFERENCE = "org.omg.CORBA.ORBInitRef"; |
public static final String REFERENCE = "org.omg.CORBA.ORBInitRef"; |
263 |
|
|
264 |
/** |
/** |
265 |
* 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 |
266 |
|
* running. |
267 |
*/ |
*/ |
268 |
public static final String NS_PORT = "org.omg.CORBA.ORBInitialPort"; |
public static final String NS_PORT = "org.omg.CORBA.ORBInitialPort"; |
269 |
|
|
270 |
/** |
/** |
271 |
* 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 |
272 |
|
* running. |
273 |
*/ |
*/ |
274 |
public static final String NS_HOST = "org.omg.CORBA.ORBInitialHost"; |
public static final String NS_HOST = "org.omg.CORBA.ORBInitialHost"; |
275 |
|
|
279 |
public static final String NAME_SERVICE = "NameService"; |
public static final String NAME_SERVICE = "NameService"; |
280 |
|
|
281 |
/** |
/** |
282 |
* The if the client has once opened a socket, it should start sending |
* The if the client has once opened a socket, it should start sending the |
283 |
* the message header in a given time. Otherwise the server will close the |
* message header in a given time. Otherwise the server will close the socket. |
284 |
* socket. This prevents server hang when the client opens the socket, |
* This prevents server hang when the client opens the socket, but does not |
285 |
* but does not send any message, usually due crash on the client side. |
* send any message, usually due crash on the client side. |
286 |
*/ |
*/ |
287 |
public static String START_READING_MESSAGE = |
public static String START_READING_MESSAGE = |
288 |
"gnu.classpath.CORBA.TOUT_START_READING_MESSAGE"; |
"gnu.classpath.CORBA.TOUT_START_READING_MESSAGE"; |
289 |
|
|
290 |
/** |
/** |
291 |
* If the client has started to send the request message, the socket time |
* If the client has started to send the request message, the socket time out |
292 |
* out changes to the specified value. |
* changes to the specified value. |
293 |
*/ |
*/ |
294 |
public static String WHILE_READING = "gnu.classpath.CORBA.TOUT_WHILE_READING"; |
public static String WHILE_READING = |
295 |
|
"gnu.classpath.CORBA.TOUT_WHILE_READING"; |
296 |
|
|
297 |
/** |
/** |
298 |
* If the message body is received, the time out changes to the |
* If the message body is received, the time out changes to the specifice |
299 |
* specifice value. This must be longer, as includes time, required to |
* value. This must be longer, as includes time, required to process the |
300 |
* process the received task. We make it 40 minutes. |
* received task. We make it 40 minutes. |
301 |
*/ |
*/ |
302 |
public static String AFTER_RECEIVING = |
public static String AFTER_RECEIVING = |
303 |
"gnu.classpath.CORBA.TOUT_AFTER_RECEIVING"; |
"gnu.classpath.CORBA.TOUT_AFTER_RECEIVING"; |
308 |
public final String LOCAL_HOST; |
public final String LOCAL_HOST; |
309 |
|
|
310 |
/** |
/** |
311 |
* The if the client has once opened a socket, it should start sending |
* The if the client has once opened a socket, it should start sending the |
312 |
* the message header in a given time. Otherwise the server will close the |
* message header in a given time. Otherwise the server will close the socket. |
313 |
* socket. This prevents server hang when the client opens the socket, |
* This prevents server hang when the client opens the socket, but does not |
314 |
* but does not send any message, usually due crash on the client side. |
* send any message, usually due crash on the client side. |
315 |
*/ |
*/ |
316 |
private int TOUT_START_READING_MESSAGE = 20 * 1000; |
private int TOUT_START_READING_MESSAGE = 20 * 1000; |
317 |
|
|
318 |
// (Here and below, we use * to make the meaning of the constant clearler). |
// (Here and below, we use * to make the meaning of the constant clearler). |
319 |
|
|
320 |
/** |
/** |
321 |
* If the client has started to send the request message, the socket time |
* If the client has started to send the request message, the socket time out |
322 |
* out changes to the specified value. |
* changes to the specified value. |
323 |
*/ |
*/ |
324 |
private int TOUT_WHILE_READING = 2 * 60 * 1000; |
private int TOUT_WHILE_READING = 2 * 60 * 1000; |
325 |
|
|
326 |
/** |
/** |
327 |
* If the message body is received, the time out changes to the |
* If the message body is received, the time out changes to the specifice |
328 |
* specifice value. This must be longer, as includes time, required to |
* value. This must be longer, as includes time, required to process the |
329 |
* process the received task. We make it 40 minutes. |
* received task. We make it 40 minutes. |
330 |
*/ |
*/ |
331 |
private int TOUT_AFTER_RECEIVING = 40 * 60 * 1000; |
private int TOUT_AFTER_RECEIVING = 40 * 60 * 1000; |
332 |
|
|
333 |
/** |
/** |
334 |
* Some clients tend to submit multiple requests over the |
* Some clients tend to submit multiple requests over the same socket. The |
335 |
* same socket. The server waits for the next request on |
* server waits for the next request on the same socket for the duration, |
336 |
* the same socket for the duration, specified |
* specified below. In additions, the request of this implementation also |
337 |
* below. In additions, the request of this implementation also |
* waits for the same duration before closing the socket. The default time is |
338 |
* waits for the same duration before closing the socket. |
* seven seconds. |
|
* The default time is seven seconds. |
|
339 |
*/ |
*/ |
340 |
public static int TANDEM_REQUESTS = 7000; |
public static int TANDEM_REQUESTS = 7000; |
341 |
|
|
342 |
/** |
/** |
343 |
* The map of the already conncted objects. |
* The map of the already conncted objects. |
344 |
*/ |
*/ |
345 |
protected final Connected_objects connected_objects = new Connected_objects(); |
protected final Connected_objects connected_objects = |
346 |
|
new Connected_objects(); |
347 |
|
|
348 |
/** |
/** |
349 |
* The maximal CORBA version, supported by this ORB. The default value |
* The maximal CORBA version, supported by this ORB. The default value 0 means |
350 |
* 0 means that the ORB will not check the request version while trying |
* that the ORB will not check the request version while trying to respond. |
|
* to respond. |
|
351 |
*/ |
*/ |
352 |
protected Version max_version; |
protected Version max_version; |
353 |
|
|
354 |
/** |
/** |
355 |
* Setting this value to false causes the ORB to shutdown after the |
* Setting this value to false causes the ORB to shutdown after the latest |
356 |
* latest serving operation is complete. |
* serving operation is complete. |
357 |
*/ |
*/ |
358 |
protected boolean running; |
protected boolean running; |
359 |
|
|
373 |
private String ns_host; |
private String ns_host; |
374 |
|
|
375 |
/** |
/** |
376 |
* Probably free port, under that the ORB will try listening for |
* Probably free port, under that the ORB will try listening for remote |
377 |
* remote requests first. When the new object is connected, this |
* requests first. When the new object is connected, this port is used first, |
378 |
* port is used first, then it is incremented by 1, etc. If the given |
* then it is incremented by 1, etc. If the given port is not available, up to |
379 |
* port is not available, up to 20 subsequent values are tried and then |
* 20 subsequent values are tried and then the parameterless server socket |
380 |
* the parameterless server socket contructor is called. The constant is |
* contructor is called. The constant is shared between multiple instances of |
381 |
* shared between multiple instances of this ORB. |
* this ORB. |
382 |
*/ |
*/ |
383 |
private static int Port = DEFAULT_INITIAL_PORT; |
private static int Port = DEFAULT_INITIAL_PORT; |
384 |
|
|
386 |
* The port, on that the name service is expected to be running. |
* The port, on that the name service is expected to be running. |
387 |
*/ |
*/ |
388 |
private int ns_port = 900; |
private int ns_port = 900; |
389 |
|
|
390 |
|
/** |
391 |
|
* The name parser. |
392 |
|
*/ |
393 |
|
NameParser nameParser = new NameParser(); |
394 |
|
|
395 |
/** |
/** |
396 |
* The instance, stored in this field, handles the asynchronous dynamic |
* The instance, stored in this field, handles the asynchronous dynamic |
409 |
protected Hashtable identities = new Hashtable(); |
protected Hashtable identities = new Hashtable(); |
410 |
|
|
411 |
/** |
/** |
412 |
* The maximal allowed number of the currently running parallel |
* The maximal allowed number of the currently running parallel threads per |
413 |
* threads per object. For security reasons, this is made private and |
* object. For security reasons, this is made private and unchangeable. After |
414 |
* unchangeable. After exceeding this limit, the NO_RESOURCES |
* exceeding this limit, the NO_RESOURCES is thrown back to the client. |
|
* is thrown back to the client. |
|
415 |
*/ |
*/ |
416 |
private int MAX_RUNNING_THREADS = 256; |
private int MAX_RUNNING_THREADS = 256; |
417 |
|
|
435 |
} |
} |
436 |
|
|
437 |
/** |
/** |
438 |
* If the max version is assigned, the orb replies with the error |
* If the max version is assigned, the orb replies with the error message if |
439 |
* message if the request version is above the supported 1.2 version. |
* the request version is above the supported 1.2 version. This behavior is |
440 |
* This behavior is recommended by OMG, but not all implementations |
* recommended by OMG, but not all implementations respond that error message |
441 |
* respond that error message by re-sending the request, encoded in the older |
* by re-sending the request, encoded in the older version. |
442 |
* version. |
*/ |
|
*/ |
|
443 |
public void setMaxVersion(Version max_supported) |
public void setMaxVersion(Version max_supported) |
444 |
{ |
{ |
445 |
max_version = max_supported; |
max_version = max_supported; |
446 |
} |
} |
447 |
|
|
448 |
/** |
/** |
449 |
* Get the maximal supported GIOP version or null if the version is |
* Get the maximal supported GIOP version or null if the version is not |
450 |
* not checked. |
* checked. |
451 |
*/ |
*/ |
452 |
public Version getMaxVersion() |
public Version getMaxVersion() |
453 |
{ |
{ |
455 |
} |
} |
456 |
|
|
457 |
/** |
/** |
458 |
* Get the currently free port, starting from the initially set port |
* Get the currently free port, starting from the initially set port and going |
459 |
* and going up max 20 steps, then trying to bind into any free |
* up max 20 steps, then trying to bind into any free address. |
|
* address. |
|
460 |
* |
* |
461 |
* @return the currently available free port. |
* @return the currently available free port. |
462 |
* |
* |
463 |
* @throws NO_RESOURCES if the server socked cannot be opened on the |
* @throws NO_RESOURCES if the server socked cannot be opened on the local |
464 |
* local host. |
* host. |
465 |
*/ |
*/ |
466 |
public int getFreePort() |
public int getFreePort() throws BAD_OPERATION |
|
throws BAD_OPERATION |
|
467 |
{ |
{ |
468 |
ServerSocket s; |
ServerSocket s; |
469 |
int a_port; |
int a_port; |
520 |
} |
} |
521 |
|
|
522 |
/** |
/** |
523 |
* Set the port, on that the server is listening for the client requests. |
* Set the port, on that the server is listening for the client requests. If |
524 |
* If only one object is connected to the orb, the server will be |
* only one object is connected to the orb, the server will be try listening |
525 |
* try listening on this port first. It the port is busy, or if more |
* on this port first. It the port is busy, or if more objects are connected, |
526 |
* objects are connected, the subsequent object will receive a larger |
* the subsequent object will receive a larger port values, skipping |
527 |
* port values, skipping unavailable ports, if required. The change |
* unavailable ports, if required. The change applies globally. |
|
* applies globally. |
|
528 |
* |
* |
529 |
* @param a_Port a port, on that the server is listening for requests. |
* @param a_Port a port, on that the server is listening for requests. |
530 |
*/ |
*/ |
534 |
} |
} |
535 |
|
|
536 |
/** |
/** |
537 |
* Connect the given CORBA object to this ORB. After the object is |
* Connect the given CORBA object to this ORB. After the object is connected, |
538 |
* connected, it starts receiving remote invocations via this ORB. |
* it starts receiving remote invocations via this ORB. |
539 |
* |
* |
540 |
* The ORB tries to connect the object to the port, that has been |
* The ORB tries to connect the object to the port, that has been previously |
541 |
* previously set by {@link setPort(int)}. On failure, it tries |
* set by {@link setPort(int)}. On failure, it tries 20 subsequent larger |
542 |
* 20 subsequent larger values and then calls the parameterless |
* values and then calls the parameterless server socked constructor to get |
543 |
* server socked constructor to get any free local port. |
* any free local port. If this fails, the {@link NO_RESOURCES} is thrown. |
|
* If this fails, the {@link NO_RESOURCES} is thrown. |
|
544 |
* |
* |
545 |
* @param object the object, must implement the {@link InvokeHandler}) |
* @param object the object, must implement the {@link InvokeHandler}) |
546 |
* interface. |
* interface. |
560 |
} |
} |
561 |
|
|
562 |
/** |
/** |
563 |
* Connect the given CORBA object to this ORB, explicitly specifying |
* Connect the given CORBA object to this ORB, explicitly specifying the |
564 |
* the object key. |
* object key. |
565 |
* |
* |
566 |
* The ORB tries to connect the object to the port, that has been |
* The ORB tries to connect the object to the port, that has been previously |
567 |
* previously set by {@link setPort(int)}. On failure, it tries |
* set by {@link setPort(int)}. On failure, it tries 20 subsequent larger |
568 |
* 20 subsequent larger values and then calls the parameterless |
* values and then calls the parameterless server socked constructor to get |
569 |
* server socked constructor to get any free local port. |
* any free local port. If this fails, the {@link NO_RESOURCES} is thrown. |
|
* If this fails, the {@link NO_RESOURCES} is thrown. |
|
570 |
* |
* |
571 |
* @param object the object, must implement the {@link InvokeHandler}) |
* @param object the object, must implement the {@link InvokeHandler}) |
572 |
* interface. |
* interface. |
573 |
* @param key the object key, usually used to identify the object from |
* @param key the object key, usually used to identify the object from remote |
574 |
* remote side. |
* side. |
575 |
* |
* |
576 |
* @throws BAD_PARAM if the object does not implement the |
* @throws BAD_PARAM if the object does not implement the |
577 |
* {@link InvokeHandler}). |
* {@link InvokeHandler}). |
589 |
} |
} |
590 |
|
|
591 |
/** |
/** |
592 |
* Connect the given CORBA object to this ORB, explicitly specifying |
* Connect the given CORBA object to this ORB, explicitly specifying the |
593 |
* the object key and the identity of the thread (and port), where the |
* object key and the identity of the thread (and port), where the object must |
594 |
* object must be served. The identity is normally the POA. |
* be served. The identity is normally the POA. |
595 |
* |
* |
596 |
* The new port server will be started only if there is no one |
* The new port server will be started only if there is no one already running |
597 |
* already running for the same identity. Otherwise, the task of |
* for the same identity. Otherwise, the task of the existing port server will |
598 |
* the existing port server will be widened, including duty to serve |
* be widened, including duty to serve the given object. All objects, |
599 |
* the given object. All objects, connected to a single identity by |
* connected to a single identity by this method, will process they requests |
600 |
* this method, will process they requests subsequently in the same |
* subsequently in the same thread. The method is used when the expected |
601 |
* thread. The method is used when the expected number of the |
* number of the objects is too large to have a single port and thread per |
602 |
* objects is too large to have a single port and thread per object. |
* object. This method is used by POAs, having a single thread policy. |
|
* This method is used by POAs, having a single thread policy. |
|
603 |
* |
* |
604 |
* @param object the object, must implement the {@link InvokeHandler}) |
* @param object the object, must implement the {@link InvokeHandler}) |
605 |
* interface. |
* interface. |
606 |
* @param key the object key, usually used to identify the object from |
* @param key the object key, usually used to identify the object from remote |
607 |
* remote side. |
* side. |
608 |
* @param port the port, where the object must be connected. |
* @param port the port, where the object must be connected. |
609 |
* |
* |
610 |
* @throws BAD_PARAM if the object does not implement the |
* @throws BAD_PARAM if the object does not implement the |
611 |
* {@link InvokeHandler}). |
* {@link InvokeHandler}). |
612 |
*/ |
*/ |
613 |
public void connect_1_thread(org.omg.CORBA.Object object, byte[] key, |
public void connect_1_thread(org.omg.CORBA.Object object, byte[] key, |
614 |
java.lang.Object identity |
java.lang.Object identity |
615 |
) |
) |
616 |
{ |
{ |
617 |
sharedPortServer shared = (sharedPortServer) identities.get(identity); |
sharedPortServer shared = (sharedPortServer) identities.get(identity); |
618 |
if (shared == null) |
if (shared == null) |
650 |
*/ |
*/ |
651 |
public void destroy() |
public void destroy() |
652 |
{ |
{ |
|
super.destroy(); |
|
|
|
|
653 |
portServer p; |
portServer p; |
654 |
for (int i = 0; i < portServers.size(); i++) |
for (int i = 0; i < portServers.size(); i++) |
655 |
{ |
{ |
656 |
p = (portServer) portServers.get(i); |
p = (portServer) portServers.get(i); |
657 |
p.close_now(); |
p.close_now(); |
658 |
} |
} |
659 |
|
super.destroy(); |
660 |
} |
} |
661 |
|
|
662 |
/** |
/** |
663 |
* Disconnect the given CORBA object from this ORB. The object will be |
* Disconnect the given CORBA object from this ORB. The object will be no |
664 |
* no longer receiving the remote invocations. In response to the |
* longer receiving the remote invocations. In response to the remote |
665 |
* remote invocation on this object, the ORB will send the |
* invocation on this object, the ORB will send the exception |
666 |
* exception {@link OBJECT_NOT_EXIST}. The object, however, is not |
* {@link OBJECT_NOT_EXIST}. The object, however, is not destroyed and can |
667 |
* destroyed and can receive the local invocations. |
* receive the local invocations. |
668 |
|
* |
669 |
* @param object the object to disconnect. |
* @param object the object to disconnect. |
670 |
*/ |
*/ |
671 |
public void disconnect(org.omg.CORBA.Object object) |
public void disconnect(org.omg.CORBA.Object object) |
688 |
// object implementation. |
// object implementation. |
689 |
if (rmKey == null) |
if (rmKey == null) |
690 |
rmKey = connected_objects.getKey(object); |
rmKey = connected_objects.getKey(object); |
|
|
|
|
// Disconnect the object on any success. |
|
691 |
if (rmKey != null) |
if (rmKey != null) |
692 |
{ |
{ |
693 |
// Find and stop the corresponding portServer. |
// Find and stop the corresponding portServer. |
708 |
} |
} |
709 |
|
|
710 |
/** |
/** |
711 |
* Notifies ORB that the shared service indentity (usually POA) |
* Notifies ORB that the shared service indentity (usually POA) is destroyed. |
712 |
* is destroyed. The matching shared port server is terminated |
* The matching shared port server is terminated and the identity table entry |
713 |
* and the identity table entry is deleted. If this identity |
* is deleted. If this identity is not known for this ORB, the method returns |
714 |
* is not known for this ORB, the method returns without action. |
* without action. |
715 |
* |
* |
716 |
* @param identity the identity that has been destroyed. |
* @param identity the identity that has been destroyed. |
717 |
*/ |
*/ |
722 |
|
|
723 |
sharedPortServer ise = (sharedPortServer) identities.get(identity); |
sharedPortServer ise = (sharedPortServer) identities.get(identity); |
724 |
if (ise != null) |
if (ise != null) |
725 |
synchronized (connected_objects) |
{ |
726 |
{ |
synchronized (connected_objects) |
727 |
ise.close_now(); |
{ |
728 |
identities.remove(identity); |
ise.close_now(); |
729 |
|
identities.remove(identity); |
730 |
|
|
731 |
Connected_objects.cObject obj; |
Connected_objects.cObject obj; |
732 |
Map.Entry m; |
Map.Entry m; |
733 |
Iterator iter = connected_objects.entrySet().iterator(); |
Iterator iter = connected_objects.entrySet().iterator(); |
734 |
while (iter.hasNext()) |
while (iter.hasNext()) |
735 |
{ |
{ |
736 |
m = (Map.Entry) iter.next(); |
m = (Map.Entry) iter.next(); |
737 |
obj = (Connected_objects.cObject) m.getValue(); |
obj = (Connected_objects.cObject) m.getValue(); |
738 |
if (obj.identity == identity) |
if (obj.identity == identity) |
|
{ |
|
739 |
iter.remove(); |
iter.remove(); |
740 |
} |
} |
741 |
} |
} |
742 |
} |
} |
743 |
} |
} |
744 |
|
|
745 |
/** |
/** |
747 |
* |
* |
748 |
* @param ior the ior of the potentially local object. |
* @param ior the ior of the potentially local object. |
749 |
* |
* |
750 |
* @return the local object, represented by the given IOR, |
* @return the local object, represented by the given IOR, or null if this is |
751 |
* or null if this is not a local connected object. |
* not a local connected object. |
752 |
*/ |
*/ |
753 |
public org.omg.CORBA.Object find_local_object(IOR ior) |
public org.omg.CORBA.Object find_local_object(IOR ior) |
754 |
{ |
{ |
777 |
|
|
778 |
Iterator iter = initial_references.keySet().iterator(); |
Iterator iter = initial_references.keySet().iterator(); |
779 |
while (iter.hasNext()) |
while (iter.hasNext()) |
780 |
refs [ p++ ] = (String) iter.next(); |
{ |
781 |
|
refs [ p++ ] = (String) iter.next(); |
782 |
|
} |
783 |
return refs; |
return refs; |
784 |
} |
} |
785 |
|
|
786 |
/** |
/** |
787 |
* Get the IOR reference string for the given object. |
* Get the IOR reference string for the given object. The string embeds |
788 |
* The string embeds information about the object |
* information about the object repository Id, its access key and the server |
789 |
* repository Id, its access key and the server internet |
* internet address and port. With this information, the object can be found |
790 |
* address and port. With this information, the object |
* by another ORB, possibly located on remote computer. |
|
* can be found by another ORB, possibly located on remote |
|
|
* computer. |
|
791 |
* |
* |
792 |
* @param the CORBA object |
* @param the CORBA object |
793 |
* @return the object IOR representation. |
* @return the object IOR representation. |
794 |
* |
* |
795 |
* @throws BAD_PARAM if the object has not been previously |
* @throws BAD_PARAM if the object has not been previously connected to this |
796 |
* connected to this ORB. |
* ORB. |
797 |
* @throws BAD_OPERATION in the unlikely case if the local host |
* |
798 |
* address cannot be resolved. |
* @throws BAD_OPERATION in the unlikely case if the local host address cannot |
799 |
|
* be resolved. |
800 |
* |
* |
801 |
* @see string_to_object(String) |
* @see string_to_object(String) |
802 |
*/ |
*/ |
815 |
|
|
816 |
if (rec == null) |
if (rec == null) |
817 |
throw new BAD_PARAM("The object " + forObject + |
throw new BAD_PARAM("The object " + forObject + |
818 |
" has not been previously connected to this ORB" |
" has not been previously connected to this ORB" |
819 |
); |
); |
820 |
|
|
821 |
IOR ior = createIOR(rec); |
IOR ior = createIOR(rec); |
822 |
|
|
824 |
} |
} |
825 |
|
|
826 |
/** |
/** |
827 |
* Find and return the easily accessible CORBA object, addressed |
* Get the local IOR for the given object, null if the object is not local. |
828 |
* by name. |
*/ |
829 |
|
public IOR getLocalIor(org.omg.CORBA.Object forObject) |
830 |
|
{ |
831 |
|
Connected_objects.cObject rec = connected_objects.getKey(forObject); |
832 |
|
if (rec == null) |
833 |
|
return null; |
834 |
|
else |
835 |
|
return createIOR(rec); |
836 |
|
} |
837 |
|
|
838 |
|
/** |
839 |
|
* Find and return the easily accessible CORBA object, addressed by name. |
840 |
* |
* |
841 |
* @param name the object name. |
* @param name the object name. |
842 |
* @return the object |
* @return the object |
843 |
* |
* |
844 |
* @throws org.omg.CORBA.ORBPackage.InvalidName if the given name |
* @throws org.omg.CORBA.ORBPackage.InvalidName if the given name is not |
845 |
* is not associated with the known object. |
* associated with the known object. |
846 |
*/ |
*/ |
847 |
public org.omg.CORBA.Object resolve_initial_references(String name) |
public org.omg.CORBA.Object resolve_initial_references(String name) |
848 |
throws InvalidName |
throws InvalidName |
849 |
{ |
{ |
850 |
org.omg.CORBA.Object object = null; |
org.omg.CORBA.Object object = null; |
851 |
try |
try |
871 |
} |
} |
872 |
|
|
873 |
/** |
/** |
874 |
* Start the ORBs main working cycle |
* Start the ORBs main working cycle (receive invocation - invoke on the local |
875 |
* (receive invocation - invoke on the local object - send response - |
* object - send response - wait for another invocation). |
|
* wait for another invocation). |
|
876 |
* |
* |
877 |
* The method only returns after calling {@link #shutdown(boolean)}. |
* The method only returns after calling {@link #shutdown(boolean)}. |
878 |
*/ |
*/ |
898 |
portServers.add(subserver); |
portServers.add(subserver); |
899 |
} |
} |
900 |
else |
else |
901 |
{ |
subserver = (portServer) identities.get(obj.identity); |
|
subserver = (portServer) identities.get(obj.identity); |
|
|
} |
|
902 |
|
|
903 |
if (!subserver.isAlive()) |
if (!subserver.isAlive()) |
904 |
{ |
{ |
919 |
/** |
/** |
920 |
* Shutdown the ORB server. |
* Shutdown the ORB server. |
921 |
* |
* |
922 |
* @param wait_for_completion if true, the current thread is |
* @param wait_for_completion if true, the current thread is suspended until |
923 |
* suspended until the shutdown process is complete. |
* the shutdown process is complete. |
924 |
*/ |
*/ |
925 |
public void shutdown(boolean wait_for_completion) |
public void shutdown(boolean wait_for_completion) |
926 |
{ |
{ |
938 |
} |
} |
939 |
|
|
940 |
/** |
/** |
941 |
* Find and return the CORBA object, addressed by the given |
* Find and return the CORBA object, addressed by the given IOR string |
942 |
* IOR string representation. The object can (an usually is) |
* representation. The object can (an usually is) located on a remote |
943 |
* located on a remote computer, possibly running a different |
* computer, possibly running a different (not necessary java) CORBA |
944 |
* (not necessary java) CORBA implementation. |
* implementation. |
945 |
* |
* |
946 |
* @param ior the object IOR representation string. |
* @param ior the object IOR representation string. |
947 |
* |
* |
948 |
* @return the found CORBA object. |
* @return the found CORBA object. |
949 |
* @see object_to_string(org.omg.CORBA.Object) |
* @see object_to_string(org.omg.CORBA.Object) |
950 |
*/ |
*/ |
951 |
public org.omg.CORBA.Object string_to_object(String an_ior) |
public org.omg.CORBA.Object string_to_object(String an_ior) |
952 |
{ |
{ |
953 |
IOR ior = IOR.parse(an_ior); |
return nameParser.corbaloc(an_ior, this); |
954 |
|
} |
955 |
|
|
956 |
|
/** |
957 |
|
* Convert ior reference to CORBA object. |
958 |
|
*/ |
959 |
|
public org.omg.CORBA.Object ior_to_object(IOR ior) |
960 |
|
{ |
961 |
org.omg.CORBA.Object object = find_local_object(ior); |
org.omg.CORBA.Object object = find_local_object(ior); |
962 |
if (object == null) |
if (object == null) |
963 |
{ |
{ |
965 |
try |
try |
966 |
{ |
{ |
967 |
if (impl._get_delegate() == null) |
if (impl._get_delegate() == null) |
968 |
{ |
impl._set_delegate(new IOR_Delegate(this, ior)); |
|
impl._set_delegate(new IOR_Delegate(this, ior)); |
|
|
} |
|
969 |
} |
} |
970 |
catch (BAD_OPERATION ex) |
catch (BAD_OPERATION ex) |
971 |
{ |
{ |
981 |
} |
} |
982 |
|
|
983 |
/** |
/** |
984 |
* Get the default naming service for the case when there no |
* Get the default naming service for the case when there no NameService |
985 |
* NameService entries. |
* entries. |
986 |
*/ |
*/ |
987 |
protected org.omg.CORBA.Object getDefaultNameService() |
protected org.omg.CORBA.Object getDefaultNameService() |
988 |
{ |
{ |
989 |
if (initial_references.containsKey(NAME_SERVICE)) |
if (initial_references.containsKey(NAME_SERVICE)) |
990 |
{ |
return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE); |
|
return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE); |
|
|
} |
|
991 |
|
|
992 |
IOR ior = new IOR(); |
IOR ior = new IOR(); |
993 |
ior.Id = NamingContextExtHelper.id(); |
ior.Id = NamingContextExtHelper.id(); |
1002 |
} |
} |
1003 |
|
|
1004 |
/** |
/** |
1005 |
* Find and return the object, that must be previously connected |
* Find and return the object, that must be previously connected to this ORB. |
1006 |
* to this ORB. Return null if no such object is available. |
* Return null if no such object is available. |
1007 |
* |
* |
1008 |
* @param key the object key. |
* @param key the object key. |
1009 |
* |
* |
1022 |
* @param app the current applet. |
* @param app the current applet. |
1023 |
* |
* |
1024 |
* @param props application specific properties, passed as the second |
* @param props application specific properties, passed as the second |
1025 |
* parameter in {@link #init(Applet, Properties)}. |
* parameter in {@link #init(Applet, Properties)}. Can be <code>null</code>. |
|
* Can be <code>null</code>. |
|
1026 |
*/ |
*/ |
1027 |
protected void set_parameters(Applet app, Properties props) |
protected void set_parameters(Applet app, Properties props) |
1028 |
{ |
{ |
1035 |
{ |
{ |
1036 |
if (para [ i ] [ 0 ].equals(LISTEN_ON)) |
if (para [ i ] [ 0 ].equals(LISTEN_ON)) |
1037 |
Port = Integer.parseInt(para [ i ] [ 1 ]); |
Port = Integer.parseInt(para [ i ] [ 1 ]); |
|
|
|
1038 |
if (para [ i ] [ 0 ].equals(REFERENCE)) |
if (para [ i ] [ 0 ].equals(REFERENCE)) |
1039 |
{ |
{ |
1040 |
StringTokenizer st = new StringTokenizer(para [ i ] [ 1 ], "="); |
StringTokenizer st = |
1041 |
|
new StringTokenizer(para [ i ] [ 1 ], "="); |
1042 |
initial_references.put(st.nextToken(), |
initial_references.put(st.nextToken(), |
1043 |
string_to_object(st.nextToken()) |
string_to_object(st.nextToken()) |
1044 |
); |
); |
1045 |
} |
} |
1046 |
|
|
1047 |
if (para [ i ] [ 0 ].equals(NS_HOST)) |
if (para [ i ] [ 0 ].equals(NS_HOST)) |
1048 |
ns_host = para [ i ] [ 1 ]; |
ns_host = para [ i ] [ 1 ]; |
|
|
|
1049 |
if (para [ i ] [ 0 ].equals(START_READING_MESSAGE)) |
if (para [ i ] [ 0 ].equals(START_READING_MESSAGE)) |
1050 |
TOUT_START_READING_MESSAGE = Integer.parseInt(para [ i ] [ 1 ]); |
TOUT_START_READING_MESSAGE = Integer.parseInt(para [ i ] [ 1 ]); |
|
|
|
1051 |
if (para [ i ] [ 0 ].equals(WHILE_READING)) |
if (para [ i ] [ 0 ].equals(WHILE_READING)) |
1052 |
TOUT_WHILE_READING = Integer.parseInt(para [ i ] [ 1 ]); |
TOUT_WHILE_READING = Integer.parseInt(para [ i ] [ 1 ]); |
|
|
|
1053 |
if (para [ i ] [ 0 ].equals(AFTER_RECEIVING)) |
if (para [ i ] [ 0 ].equals(AFTER_RECEIVING)) |
1054 |
TOUT_AFTER_RECEIVING = Integer.parseInt(para [ i ] [ 1 ]); |
TOUT_AFTER_RECEIVING = Integer.parseInt(para [ i ] [ 1 ]); |
|
|
|
1055 |
try |
try |
1056 |
{ |
{ |
1057 |
if (para [ i ] [ 0 ].equals(NS_PORT)) |
if (para [ i ] [ 0 ].equals(NS_PORT)) |
1061 |
{ |
{ |
1062 |
BAD_PARAM bad = |
BAD_PARAM bad = |
1063 |
new BAD_PARAM("Invalid " + NS_PORT + |
new BAD_PARAM("Invalid " + NS_PORT + |
1064 |
"property, unable to parse '" + |
"property, unable to parse '" + |
1065 |
props.getProperty(NS_PORT) + "'" |
props.getProperty(NS_PORT) + "'" |
1066 |
); |
); |
1067 |
bad.initCause(ex); |
bad.initCause(ex); |
1068 |
throw bad; |
throw bad; |
1069 |
} |
} |
1075 |
* Set the ORB parameters. This method is normally called from |
* Set the ORB parameters. This method is normally called from |
1076 |
* {@link #init(String[], Properties)}. |
* {@link #init(String[], Properties)}. |
1077 |
* |
* |
1078 |
* @param para the parameters, that were passed as the parameters |
* @param para the parameters, that were passed as the parameters to the |
1079 |
* to the <code>main(String[] args)</code> method of the current standalone |
* <code>main(String[] args)</code> method of the current standalone |
1080 |
* application. |
* application. |
1081 |
* |
* |
1082 |
* @param props application specific properties that were passed |
* @param props application specific properties that were passed as a second |
1083 |
* as a second parameter in {@link init(String[], Properties)}). |
* parameter in {@link init(String[], Properties)}). Can be <code>null</code>. |
|
* Can be <code>null</code>. |
|
1084 |
*/ |
*/ |
1085 |
protected void set_parameters(String[] para, Properties props) |
protected void set_parameters(String[] para, Properties props) |
1086 |
{ |
{ |
1087 |
if (para.length > 1) |
if (para.length > 1) |
1088 |
for (int i = 0; i < para.length - 1; i++) |
{ |
1089 |
{ |
for (int i = 0; i < para.length - 1; i++) |
1090 |
if (para [ i ].endsWith("ListenOn")) |
{ |
1091 |
Port = Integer.parseInt(para [ i + 1 ]); |
if (para [ i ].endsWith("ListenOn")) |
1092 |
|
Port = Integer.parseInt(para [ i + 1 ]); |
1093 |
if (para [ i ].endsWith("ORBInitRef")) |
if (para [ i ].endsWith("ORBInitRef")) |
1094 |
{ |
{ |
1095 |
StringTokenizer st = new StringTokenizer(para [ i + 1 ], "="); |
StringTokenizer st = new StringTokenizer(para [ i + 1 ], "="); |
1096 |
initial_references.put(st.nextToken(), |
initial_references.put(st.nextToken(), |
1097 |
string_to_object(st.nextToken()) |
string_to_object(st.nextToken()) |
1098 |
); |
); |
1099 |
} |
} |
|
|
|
|
if (para [ i ].endsWith("ORBInitialHost")) |
|
|
ns_host = para [ i + 1 ]; |
|
1100 |
|
|
1101 |
try |
if (para [ i ].endsWith("ORBInitialHost")) |
1102 |
{ |
ns_host = para [ i + 1 ]; |
1103 |
if (para [ i ].endsWith("ORBInitialPort")) |
try |
1104 |
ns_port = Integer.parseInt(para [ i + 1 ]); |
{ |
1105 |
} |
if (para [ i ].endsWith("ORBInitialPort")) |
1106 |
catch (NumberFormatException ex) |
ns_port = Integer.parseInt(para [ i + 1 ]); |
1107 |
{ |
} |
1108 |
throw new BAD_PARAM("Invalid " + para [ i ] + |
catch (NumberFormatException ex) |
1109 |
"parameter, unable to parse '" + |
{ |
1110 |
props.getProperty(para [ i + 1 ]) + "'" |
throw new BAD_PARAM("Invalid " + para [ i ] + |
1111 |
); |
"parameter, unable to parse '" + |
1112 |
} |
props.getProperty(para [ i + 1 ]) + "'" |
1113 |
} |
); |
1114 |
|
} |
1115 |
|
} |
1116 |
|
} |
1117 |
|
|
1118 |
useProperties(props); |
useProperties(props); |
1119 |
} |
} |
1120 |
|
|
1121 |
private IOR createIOR(Connected_objects.cObject ref) |
/** |
1122 |
throws BAD_OPERATION |
* Create IOR for the given object references. |
1123 |
|
*/ |
1124 |
|
protected IOR createIOR(Connected_objects.cObject ref) |
1125 |
|
throws BAD_OPERATION |
1126 |
{ |
{ |
1127 |
IOR ior = new IOR(); |
IOR ior = new IOR(); |
1128 |
ior.key = ref.key; |
ior.key = ref.key; |
1136 |
} |
} |
1137 |
if (ior.Id == null) |
if (ior.Id == null) |
1138 |
ior.Id = ref.object.getClass().getName(); |
ior.Id = ref.object.getClass().getName(); |
|
|
|
1139 |
try |
try |
1140 |
{ |
{ |
1141 |
ior.Internet.host = InetAddress.getLocalHost().getHostAddress(); |
ior.Internet.host = InetAddress.getLocalHost().getHostAddress(); |
1157 |
* {@link InvokeHandler}). |
* {@link InvokeHandler}). |
1158 |
*/ |
*/ |
1159 |
private void prepareObject(org.omg.CORBA.Object object, IOR ior) |
private void prepareObject(org.omg.CORBA.Object object, IOR ior) |
1160 |
throws BAD_PARAM |
throws BAD_PARAM |
1161 |
{ |
{ |
1162 |
/* |
/* |
1163 |
if (!(object instanceof InvokeHandler)) |
* if (!(object instanceof InvokeHandler)) throw new |
1164 |
throw new BAD_PARAM(object.getClass().getName() + |
* BAD_PARAM(object.getClass().getName() + " does not implement |
1165 |
" does not implement InvokeHandler. " |
* InvokeHandler. " ); |
|
); |
|
1166 |
*/ |
*/ |
1167 |
|
|
1168 |
// If no delegate is set, set the default delegate. |
// If no delegate is set, set the default delegate. |
1172 |
try |
try |
1173 |
{ |
{ |
1174 |
if (impl._get_delegate() == null) |
if (impl._get_delegate() == null) |
1175 |
{ |
impl._set_delegate(new Simple_delegate(this, ior)); |
|
impl._set_delegate(new Simple_delegate(this, ior)); |
|
|
} |
|
1176 |
} |
} |
1177 |
catch (BAD_OPERATION ex) |
catch (BAD_OPERATION ex) |
1178 |
{ |
{ |
1188 |
* @param net_out the stream to write response into |
* @param net_out the stream to write response into |
1189 |
* @param msh_request the request message header |
* @param msh_request the request message header |
1190 |
* @param rh_request the request header |
* @param rh_request the request header |
1191 |
* @param handler the invocation handler that has been used to |
* @param handler the invocation handler that has been used to invoke the |
1192 |
* invoke the operation |
* operation |
1193 |
* @param sysEx the system exception, thrown during the invocation, |
* @param sysEx the system exception, thrown during the invocation, null if |
1194 |
* null if none. |
* none. |
1195 |
* |
* |
1196 |
* @throws IOException |
* @throws IOException |
1197 |
*/ |
*/ |
1198 |
private void respond_to_client(OutputStream net_out, |
private void respond_to_client(OutputStream net_out, |
1199 |
MessageHeader msh_request, |
MessageHeader msh_request, RequestHeader rh_request, |
1200 |
RequestHeader rh_request, |
bufferedResponseHandler handler, SystemException sysEx |
1201 |
bufferedResponseHandler handler, |
) throws IOException |
|
SystemException sysEx |
|
|
) |
|
|
throws IOException |
|
1202 |
{ |
{ |
1203 |
// Set the reply header properties. |
// Set the reply header properties. |
1204 |
ReplyHeader reply = handler.reply_header; |
ReplyHeader reply = handler.reply_header; |
1209 |
reply.reply_status = ReplyHeader.USER_EXCEPTION; |
reply.reply_status = ReplyHeader.USER_EXCEPTION; |
1210 |
else |
else |
1211 |
reply.reply_status = ReplyHeader.NO_EXCEPTION; |
reply.reply_status = ReplyHeader.NO_EXCEPTION; |
|
|
|
1212 |
reply.request_id = rh_request.request_id; |
reply.request_id = rh_request.request_id; |
1213 |
|
|
1214 |
cdrBufOutput out = new cdrBufOutput(50 + handler.getBuffer().buffer.size()); |
cdrBufOutput out = |
1215 |
|
new cdrBufOutput(50 + handler.getBuffer().buffer.size()); |
1216 |
out.setOrb(this); |
out.setOrb(this); |
1217 |
|
|
1218 |
out.setOffset(msh_request.getHeaderSize()); |
out.setOffset(msh_request.getHeaderSize()); |
1219 |
|
|
1220 |
reply.write(out); |
reply.write(out); |
1221 |
|
|
1222 |
// Write the reply data from the handler. |
if (msh_request.version.since_inclusive(1, 2)) |
1223 |
|
{ |
1224 |
|
out.align(8); |
1225 |
|
|
1226 |
|
// Write the reply data from the handler. The handler data already |
1227 |
|
// include the necessary heading zeroes for alignment. |
1228 |
|
} |
1229 |
handler.getBuffer().buffer.writeTo(out); |
handler.getBuffer().buffer.writeTo(out); |
1230 |
|
|
1231 |
MessageHeader msh_reply = new MessageHeader(); |
MessageHeader msh_reply = new MessageHeader(); |
1241 |
} |
} |
1242 |
|
|
1243 |
/** |
/** |
1244 |
* Forward request to another target, as indicated by the passed |
* Forward request to another target, as indicated by the passed exception. |
|
* exception. |
|
1245 |
*/ |
*/ |
1246 |
private void forward_request(OutputStream net_out, MessageHeader msh_request, |
private void forward_request(OutputStream net_out, |
1247 |
RequestHeader rh_request, gnuForwardRequest info |
MessageHeader msh_request, RequestHeader rh_request, gnuForwardRequest info |
1248 |
) |
) throws IOException |
|
throws IOException |
|
1249 |
{ |
{ |
1250 |
MessageHeader msh_forward = new MessageHeader(); |
MessageHeader msh_forward = new MessageHeader(); |
1251 |
msh_forward.version = msh_request.version; |
msh_forward.version = msh_request.version; |
1264 |
|
|
1265 |
if (msh_forward.version.since_inclusive(1, 2)) |
if (msh_forward.version.since_inclusive(1, 2)) |
1266 |
out.align(8); |
out.align(8); |
|
|
|
1267 |
out.write_Object(info.forward_reference); |
out.write_Object(info.forward_reference); |
1268 |
|
|
1269 |
msh_forward.message_size = out.buffer.size(); |
msh_forward.message_size = out.buffer.size(); |
1277 |
/** |
/** |
1278 |
* Contains a single servicing task. |
* Contains a single servicing task. |
1279 |
* |
* |
1280 |
* Normally, each task matches a single remote invocation. |
* Normally, each task matches a single remote invocation. However under |
1281 |
* However under frequent tandem submissions the same |
* frequent tandem submissions the same task may span over several |
1282 |
* task may span over several invocations. |
* invocations. |
1283 |
* |
* |
1284 |
* @param serverSocket the ORB server socket. |
* @param serverSocket the ORB server socket. |
1285 |
* |
* |
1286 |
* @throws MARSHAL |
* @throws MARSHAL |
1287 |
* @throws IOException |
* @throws IOException |
1288 |
*/ |
*/ |
1289 |
private void serve(final portServer p, ServerSocket serverSocket) |
void serve(final portServer p, ServerSocket serverSocket) |
1290 |
throws MARSHAL, IOException |
throws MARSHAL, IOException |
1291 |
{ |
{ |
1292 |
final Socket service; |
final Socket service; |
1293 |
service = serverSocket.accept(); |
service = serverSocket.accept(); |
1325 |
/** |
/** |
1326 |
* A single servicing step, when the client socket is alrady open. |
* A single servicing step, when the client socket is alrady open. |
1327 |
* |
* |
1328 |
* Normally, each task matches a single remote invocation. |
* Normally, each task matches a single remote invocation. However under |
1329 |
* However under frequent tandem submissions the same |
* frequent tandem submissions the same task may span over several |
1330 |
* task may span over several invocations. |
* invocations. |
1331 |
* |
* |
1332 |
* @param service the opened client socket. |
* @param service the opened client socket. |
1333 |
* @param no_resources if true, the "NO RESOURCES" exception |
* @param no_resources if true, the "NO RESOURCES" exception is thrown to the |
1334 |
* is thrown to the client. |
* client. |
1335 |
*/ |
*/ |
1336 |
private void serveStep(Socket service, boolean no_resources) |
void serveStep(Socket service, boolean no_resources) |
1337 |
{ |
{ |
1338 |
try |
try |
1339 |
{ |
{ |
1356 |
} |
} |
1357 |
|
|
1358 |
if (max_version != null) |
if (max_version != null) |
1359 |
if (!msh_request.version.until_inclusive(max_version.major, |
{ |
1360 |
max_version.minor |
if (!msh_request.version.until_inclusive(max_version.major, |
1361 |
) |
max_version.minor |
1362 |
) |
) |
1363 |
{ |
) |
1364 |
OutputStream out = service.getOutputStream(); |
{ |
1365 |
new ErrorMessage(max_version).write(out); |
OutputStream out = service.getOutputStream(); |
1366 |
return; |
new ErrorMessage(max_version).write(out); |
1367 |
} |
return; |
1368 |
|
} |
1369 |
|
} |
1370 |
|
|
1371 |
byte[] r = new byte[ msh_request.message_size ]; |
byte[] r = new byte[ msh_request.message_size ]; |
1372 |
|
|
1400 |
// in 1.2 and higher, align the current position at |
// in 1.2 and higher, align the current position at |
1401 |
// 8 octet boundary. |
// 8 octet boundary. |
1402 |
if (msh_request.version.since_inclusive(1, 2)) |
if (msh_request.version.since_inclusive(1, 2)) |
1403 |
cin.align(8); |
{ |
1404 |
|
cin.align(8); |
1405 |
|
|
1406 |
|
// find the target object. |
1407 |
|
} |
1408 |
|
|
|
// find the target object. |
|
1409 |
InvokeHandler target = |
InvokeHandler target = |
1410 |
(InvokeHandler) find_connected_object(rh_request.object_key); |
(InvokeHandler) find_connected_object(rh_request.object_key); |
1411 |
|
|
1416 |
|
|
1417 |
// TODO log errors about not existing objects and methods. |
// TODO log errors about not existing objects and methods. |
1418 |
bufferedResponseHandler handler = |
bufferedResponseHandler handler = |
1419 |
new bufferedResponseHandler(this, msh_request, rh_reply); |
new bufferedResponseHandler(this, msh_request, rh_reply, |
1420 |
|
rh_request |
1421 |
|
); |
1422 |
|
|
1423 |
SystemException sysEx = null; |
SystemException sysEx = null; |
1424 |
|
|
1454 |
{ |
{ |
1455 |
except.printStackTrace(); |
except.printStackTrace(); |
1456 |
sysEx = |
sysEx = |
1457 |
new UNKNOWN("Unknown", 2, CompletionStatus.COMPLETED_MAYBE); |
new UNKNOWN("Unknown", 2, |
1458 |
|
CompletionStatus.COMPLETED_MAYBE |
1459 |
|
); |
1460 |
|
|
1461 |
org.omg.CORBA.portable.OutputStream ech = |
org.omg.CORBA.portable.OutputStream ech = |
1462 |
handler.createExceptionReply(); |
handler.createExceptionReply(); |
1469 |
{ |
{ |
1470 |
OutputStream sou = service.getOutputStream(); |
OutputStream sou = service.getOutputStream(); |
1471 |
respond_to_client(sou, msh_request, rh_request, handler, |
respond_to_client(sou, msh_request, rh_request, handler, |
1472 |
sysEx |
sysEx |
1473 |
); |
); |
1474 |
} |
} |
1475 |
} |
} |
1476 |
else if (msh_request.message_type == MessageHeader.CLOSE_CONNECTION || |
else if (msh_request.message_type == MessageHeader.CLOSE_CONNECTION || |
1477 |
msh_request.message_type == MessageHeader.MESSAGE_ERROR |
msh_request.message_type == MessageHeader.MESSAGE_ERROR |
1478 |
) |
) |
1479 |
{ |
{ |
1480 |
CloseMessage.close(service.getOutputStream()); |
CloseMessage.close(service.getOutputStream()); |
1481 |
service.close(); |
service.close(); |
1485 |
|
|
1486 |
// TODO log error: "Not a request message." |
// TODO log error: "Not a request message." |
1487 |
if (service != null && !service.isClosed()) |
if (service != null && !service.isClosed()) |
1488 |
{ |
|
1489 |
// Wait for the subsequent invocations on the |
// Wait for the subsequent invocations on the |
1490 |
// same socket for the TANDEM_REQUEST duration. |
// same socket for the TANDEM_REQUEST duration. |
1491 |
service.setSoTimeout(TANDEM_REQUESTS); |
service.setSoTimeout(TANDEM_REQUESTS); |
|
} |
|
1492 |
else |
else |
1493 |
return; |
return; |
1494 |
} |
} |
1512 |
{ |
{ |
1513 |
if (props.containsKey(LISTEN_ON)) |
if (props.containsKey(LISTEN_ON)) |
1514 |
Port = Integer.parseInt(props.getProperty(LISTEN_ON)); |
Port = Integer.parseInt(props.getProperty(LISTEN_ON)); |
|
|
|
1515 |
if (props.containsKey(NS_HOST)) |
if (props.containsKey(NS_HOST)) |
1516 |
ns_host = props.getProperty(NS_HOST); |
ns_host = props.getProperty(NS_HOST); |
|
|
|
1517 |
try |
try |
1518 |
{ |
{ |
1519 |
if (props.containsKey(NS_PORT)) |
if (props.containsKey(NS_PORT)) |
1520 |
ns_port = Integer.parseInt(props.getProperty(NS_PORT)); |
ns_port = Integer.parseInt(props.getProperty(NS_PORT)); |
|
|
|
1521 |
if (props.containsKey(START_READING_MESSAGE)) |
if (props.containsKey(START_READING_MESSAGE)) |
1522 |
TOUT_START_READING_MESSAGE = |
TOUT_START_READING_MESSAGE = |
1523 |
Integer.parseInt(props.getProperty(START_READING_MESSAGE)); |
Integer.parseInt(props.getProperty(START_READING_MESSAGE)); |
|
|
|
1524 |
if (props.containsKey(WHILE_READING)) |
if (props.containsKey(WHILE_READING)) |
1525 |
TOUT_WHILE_READING = |
TOUT_WHILE_READING = |
1526 |
Integer.parseInt(props.getProperty(WHILE_READING)); |
Integer.parseInt(props.getProperty(WHILE_READING)); |
|
|
|
1527 |
if (props.containsKey(AFTER_RECEIVING)) |
if (props.containsKey(AFTER_RECEIVING)) |
1528 |
TOUT_AFTER_RECEIVING = |
TOUT_AFTER_RECEIVING = |
1529 |
Integer.parseInt(props.getProperty(AFTER_RECEIVING)); |
Integer.parseInt(props.getProperty(AFTER_RECEIVING)); |
1531 |
catch (NumberFormatException ex) |
catch (NumberFormatException ex) |
1532 |
{ |
{ |
1533 |
throw new BAD_PARAM("Invalid " + NS_PORT + |
throw new BAD_PARAM("Invalid " + NS_PORT + |
1534 |
"property, unable to parse '" + |
"property, unable to parse '" + props.getProperty(NS_PORT) + |
1535 |
props.getProperty(NS_PORT) + "'" |
"'" |
1536 |
); |
); |
1537 |
} |
} |
1538 |
|
|
1539 |
Enumeration en = props.elements(); |
Enumeration en = props.elements(); |
1542 |
String item = (String) en.nextElement(); |
String item = (String) en.nextElement(); |
1543 |
if (item.equals(REFERENCE)) |
if (item.equals(REFERENCE)) |
1544 |
initial_references.put(item, |
initial_references.put(item, |
1545 |
string_to_object(props.getProperty(item)) |
string_to_object(props.getProperty(item)) |
1546 |
); |
); |
1547 |
} |
} |
1548 |
} |
} |
1549 |
} |
} |
1550 |
|
|
1551 |
/** |
/** |
1552 |
* Get the next instance with a response being received. If all currently |
* Get the next instance with a response being received. If all currently sent |
1553 |
* sent responses not yet processed, this method pauses till at least one of |
* responses not yet processed, this method pauses till at least one of them |
1554 |
* them is complete. If there are no requests currently sent, the method |
* is complete. If there are no requests currently sent, the method pauses |
1555 |
* pauses till some request is submitted and the response is received. |
* till some request is submitted and the response is received. This strategy |
1556 |
* This strategy is identical to the one accepted by Suns 1.4 ORB |
* is identical to the one accepted by Suns 1.4 ORB implementation. |
|
* implementation. |
|
1557 |
* |
* |
1558 |
* The returned response is removed from the list of the currently |
* The returned response is removed from the list of the currently submitted |
1559 |
* submitted responses and is never returned again. |
* responses and is never returned again. |
1560 |
* |
* |
1561 |
* @return the previously sent request that now contains the received |
* @return the previously sent request that now contains the received |
1562 |
* response. |
* response. |
1563 |
* |
* |
1564 |
* @throws WrongTransaction If the method was called from the transaction |
* @throws WrongTransaction If the method was called from the transaction |
1565 |
* scope different than the one, used to send the request. The exception |
* scope different than the one, used to send the request. The exception can |
1566 |
* can be raised only if the request is implicitly associated with some |
* be raised only if the request is implicitly associated with some particular |
1567 |
* particular transaction. |
* transaction. |
1568 |
*/ |
*/ |
1569 |
public Request get_next_response() |
public Request get_next_response() throws org.omg.CORBA.WrongTransaction |
|
throws org.omg.CORBA.WrongTransaction |
|
1570 |
{ |
{ |
1571 |
return asynchron.get_next_response(); |
return asynchron.get_next_response(); |
1572 |
} |
} |
1575 |
* Find if any of the requests that have been previously sent with |
* Find if any of the requests that have been previously sent with |
1576 |
* {@link #send_multiple_requests_deferred}, have a response yet. |
* {@link #send_multiple_requests_deferred}, have a response yet. |
1577 |
* |
* |
1578 |
* @return true if there is at least one response to the previously |
* @return true if there is at least one response to the previously sent |
1579 |
* sent request, false otherwise. |
* request, false otherwise. |
1580 |
*/ |
*/ |
1581 |
public boolean poll_next_response() |
public boolean poll_next_response() |
1582 |
{ |
{ |
1584 |
} |
} |
1585 |
|
|
1586 |
/** |
/** |
1587 |
* Send multiple prepared requests expecting to get a reply. All requests |
* Send multiple prepared requests expecting to get a reply. All requests are |
1588 |
* are send in parallel, each in its own separate thread. When the |
* send in parallel, each in its own separate thread. When the reply arrives, |
1589 |
* reply arrives, it is stored in the agreed fields of the corresponing |
* it is stored in the agreed fields of the corresponing request data |
1590 |
* request data structure. If this method is called repeatedly, |
* structure. If this method is called repeatedly, the new requests are added |
1591 |
* the new requests are added to the set of the currently sent requests, |
* to the set of the currently sent requests, but the old set is not |
1592 |
* but the old set is not discarded. |
* discarded. |
1593 |
* |
* |
1594 |
* @param requests the prepared array of requests. |
* @param requests the prepared array of requests. |
1595 |
* |
* |
1604 |
|
|
1605 |
/** |
/** |
1606 |
* Send multiple prepared requests one way, do not caring about the answer. |
* Send multiple prepared requests one way, do not caring about the answer. |
1607 |
* The messages, containing requests, will be marked, indicating that |
* The messages, containing requests, will be marked, indicating that the |
1608 |
* the sender is not expecting to get a reply. |
* sender is not expecting to get a reply. |
1609 |
* |
* |
1610 |
* @param requests the prepared array of requests. |
* @param requests the prepared array of requests. |
1611 |
* |
* |
1619 |
/** |
/** |
1620 |
* Set the flag, forcing all server threads to terminate. |
* Set the flag, forcing all server threads to terminate. |
1621 |
*/ |
*/ |
1622 |
protected void finalize() |
protected void finalize() throws java.lang.Throwable |
|
throws java.lang.Throwable |
|
1623 |
{ |
{ |
1624 |
running = false; |
running = false; |
1625 |
super.finalize(); |
super.finalize(); |