The URLNaming example
The URLNaming example illustrates how to use the URL Naming Service provided
by VisiBroker for Java. This service allows you to associate a URL (Uniform
Resource Locator) with an object's IOR (Interoperable Object Reference).
Once a URL has been bound to an object, client applications can obtain
a reference to the object by specifying the URL as a string instead of
the object's name. In this example, we use the Bank
example discussed earlier to illustrate URL Naming.
From this example, you will learn how to:
-
Use the URL Naming Service
Directory Contents
-
Bank.idl
IDL interface for the 'Bank' object.
-
Server.java
Bank server. Creates an instance of the Bank and calls org.omg.CORBA.BOA.impl_is_ready()
to make this object available to client programs. The Bank Server
implementation implements two methods: open, which opens a bank
account, and balance, which returns the balance in a person's
account whose name is provided as input (by generating a random number).
In this example, the server uses the Resolver class's force_register
method to associate a URL with the object's IOR.
-
Client.java
This is the Bank client. It binds to an account object and invokes
balance() on the object reference obtained. To bind to the account object,
the client provides as a command line argument the URL name with which
the object is associated.
-
Makefile(vbmake.bat on Windows): Used to build all the test targets.
Building this example
Typing make (or vbmake on Windows) in the URLNaming
subdirectory will cause the Bank.idl to be run through
the idl2java compiler. It will also build the following classes for the
examples described above:
-
Server.class
-
Client.class
Running this example
To run this example, first make sure that the VisiBroker Smart Agent (osagent
executable) is running on your network. Then start the gatekeeper (or a
http server) using the command:
prompt> gatekeeper &
(start gatekeeper on Windows)
Note: The gatekeeper will not run under JDK1.0.2. The solution to
this problem is to upgrade to JDK1.1.0 or higher.
Then start the Bank Server using the command:
prompt> vbj Server http://hostname:15000/Bank_Manager.ior &
(start vbj Server http://hostname:15000/Bank_Manager.ior on Windows)
// make the server run in the background
Note that in the above command line, the hostname should be replaced
with the hostname where the gatekeeper or the http server is running. Also
note that the .ior extension is required for the filename if the gatekeeper
is involved and not if the http server is used. Next, open a user's bank
account and query the balance in the account using the command
prompt> vbj Client http://hostname:15000/Bank_Manager.ior john
or
prompt> vbj Client http://hostname:15000/Bank_Manager.ior
// uses a default name for the account
Return to the top-level examples page.