Lab 5. More CORBA programming: IORs. User defined exceptions. Factory pattern. Naming Services.

This lab consist of several examples and simple programming problems. There are no deliverables for the labbesides Milestone 2. However, you need to understand all examples and make sure you know how to solve all programming problems below.

  1. Using IOR (Interoperable Object Reference) example

    Copy the directory /stage/classes/current/51024-1/pub/CORBA/IOR . This is an example (another HelloWorld of course) where the client uses server's IORs (and not the Smart Agent - osagent as in lab 5) to locate the server.

    The server obtains its IOR (using object_to_string method and writes it to a file. The client reads the file and and uses the IOR and the string_to_object method to find the server.

    Start your server and the client using vbj. To look at the info contained into the IOR use the printIOR command.

  2. User defined exceptions

    Modify your Calculator server (from the previous lab) to raise a user-defined exception DivisionBy0. You will have to:

    An example of user defined exceptions can be found at /stage/classes/current/51024-1/pub/CORBA/UserException.
    Pages 177-179 of "Java Programming with CORBA" tell you more about user defined exceptions.

  3. Factory pattern

    The factory (more on the factory method design pattern) will pass its IOR to the client using a file as before. The client will use the IOR to locate the factory, and call a method createCalculator (or createHelloWorld if you decide to make a factory of HelloWorld objects) to get an object reference to a Calculator (or HelloWorld) object.

    You will have to create a factory object that has a method createCalculator which starts a new calculator server and returns a calculator reference object. The client will use this object reference to call the calculator method(s) and compute what it needs. At the end the client will ask the factory to destroy the calculator object created for him. Examples from Chapter 10 of "Java Programming with CORBA" might be useful in implementing the factory.

  1. Add two more servers to the factory:
  2. Naming Services

    We located services so far in two ways: in Lab. 5 we used Smart Agents (osagent), and here we used IORs. Let's try a third way for service location, namely Naming Service.

    Naming Service allows you to "name" objects and then refer to them by their name. In order to use the Naming Service, you have to start it and/or locate it. You name a service using the method bind(name, object) and locate it using the method resolve(name).

    The examples at ${VBROKER_HOME}/examples/vbroker/basic/bank_naming/ and ${VBROKER_HOME}/examples/vbroker/interop/ illustrate how to connect to a remote object without using any proprietary extensions. Both examples show a simple AccountManager interface to open an Account and to query the balance in that account. The server publishes its IOR into the root context of the Naming Server, which is then retrieved by the client.

    Steps:

    1. Take a look at the basic bank naming example. Observe what is new in Server.java and Client.java. Read the documentation in bank_naming.html. Compare the Java and C++ versions.
    2. Take a look at the example ${VBROKER_HOME}/examples/vbroker/interop/. Observe what is new in Server.java and Client.java. Read the documentation in interop.html.
      Note that you can use the Naming Service utility that comes with VisiBroker 7 (nameserv) or the one from JDK1.5 (tnameserv).
      To verify which Naming Service utilities are available run:
      $ which tnameserv
      and
      $ which nameserv
      To use tnameserv, try:
      $ tnameserv -ORBInitialPort 9999 &
      and save the IOR in a file called ns.ior
    3. Adapt YourFactory and YourClient to use Naming Service instead of IORs.
      1. In YourFactory:
        • obtain a reference to the Naming Service and narrow it to be a naming context.
        • create the naming context to label the object.
        • bind the name to the object.
          Warning: choose an unique name for your object (for example you could include your student ID in the name)
      2. In YourClient:
        • obtain a reference to the Naming Service and narrow it to be a naming context.
        • create the naming context needed to distinguish the object by the name wanted.
        • resolve the object.
    4. Start the naming service your factory and your client as described in the example above.