Java Reference
In-Depth Information
when the client calls
resolve()
using the name
“
Cor19
„
,itreceives back an
object reference that can be used to make remote method calls to our servant
implementation.
19.4.2.6 Tell the ORB to wait on incoming requests
This last step is simple. We must notify the ORB that everything is ready and
that it should begin listening for requests from clients. The following code should
appear at the end of, but within, the
try/catch
block:
orb.run ();
Generally, this method never returns. It waits until a client invokes a remote
method on the servant and then dispatches that incoming request to the servant
code. When the invocation is complete, the ORB waits again for more incoming
requests.
19.5 Client implementation
The client class begins similarly to the server implementation, by importing
the required packages and starting a
main()
method that encloses all CORBA
activity within a
try/catch
block to catch any CORBA errors. We put the
client application into the
javatech.cor19.client
package under the name
Client
. The client must create and initialize the ORB and obtain a reference
to the
NamingContextExt
, similar to what was done in the server class.
To perform a lookup, we could use the
resolve()
method by providing a
NameComponent
array, as was done for the server. But
NamingContextExt
also includes a
resolve
-
str()
convenience method that accepts a Java
String
and internally performs the conversion necessary to a
NameComponent
array. So the
main()
method in our
Client
class goes as follows:
public static void main (String[] args)
{
try
{
// Create and initialize the ORB
ORB orb
=
ORB.init (args, null);
// Get the root naming context
org.omg.CORBA.Object ns
-
ref =
orb.resolve
-
initial
-
references ("NameService");
NamingContextExt ncRef =
NamingContextExtHelper.narrow (ns
-
ref);
// Get a Cor19Example from the name server.
Cor19Example cor19 =
Cor19ExampleHelper.narrow (ncRef.resolve
-
str
("Cor19"));
Search WWH ::
Custom Search