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 lab besides 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

    Here is an example (another HelloWorld of course) where the client uses server's  IORs (and not the Smart Agent - osagent  as in lab 4) 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.

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

  2. User defined exceptions

    Modify your Calculator server (from previous lab)  to raise a user defined exception DivisionBy0.  You will have to add an exception definition to your IDL, to specify that the method(s) that implements the calculator server can throw DivisionBy0exception and to raise and catch the exception where appropriate.

    Pages 177-179 of "Java Programming with CORBA" tell you more about user defined exception. And here is an example: http://www.classes.cs.uchicago.edu/current/51024-1/labs/lab5/UserException/
     

  3. Factory pattern

    The factory (more on the factory method design pattern) will pass its IOR to the client using a file as previously.  The client will use the IOR to locate the factory, call a method createCalculator (or createHelloWorld if you decide a 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 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).

    This example  illustrates how to connect to a remote object without using any proprietary extensions.  It has 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 example.  Observe what is new in Server.java and Client.java.  Note that you can use the Naming Service utility that comes with VisiBroker 4.5 (nameserv) or the one from JDK1.3 (tnameserv).
       
    2. 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.
    3. Start the naming service your factory and your client as described in the example above.