### Implementation Repository

In the previous example, the client must contact the server at least once. If the server has been moved to a different host or port, or if the server is down, binding between the client and the server fails. Indirect binding through an external location broker like the Implementation Repository solves this problem.

An implementation repository maintains a data structure known as a server table to keep track of the servers. It maintains a registry of known servers, records which server is currently running on which host and at which port number, and starts servers on demand if they are registered to do so.

When a server creates a persistent reference, it sets the address and port number in the profile body of the IOR to point at the implementation repository that is responsible for the server. When a client uses this IOR, it gets connected to the implementation repository, provided the implementation repository is not down. The repository decodes this IOR and uses the POA name from the object key to index into its server table. The repository replies with the current addressing information of the actual server. The client now sends the request to the actual server.

In this example, let's proceed to modify our previous stock factory example to support indirect binding through an implementation repository.

The only thing we have to do for this is to register our childPOA with the implementation repository.

           orb->_tao_add_to_IOR_table ("childPOA", stock_factory.in ());

Then, we stringify all the object references as usual and print them out.

           CORBA::String_var ior = orb->object_to_string (stock_factory.in ());

### Exercise

Modify the server.cpp in the simple server to create the persistent child POA. You can use the same Quoter.idl Stock_i.h Stock_i.cpp Stock_Factory_i.h Stock_Factory_i.cpp Client.cpp You can use this MPC file.

### Solution

Compare your server.cpp with server.cpp file.

### Testing

To test your changes, you need to run four programs. The first step is to start up the Implementation Repository provided with TAO. The Implementation Repository is split into one locator at least one activator. The locator provides the interface visible to the application intending to use the repository (in our case, the client), while the activators do the real work of activating and maintaining servers.

First, we start the locator. We need to dump the IOR of the ImplRepo_Service to a file, so that both the activator and the client can find the locator.

           $ $TAO_ROOT/orbsvcs/ImplRepo_Service/tao_imr_locator -o implrepo.ior -d 0 -ORBobjrefstyle URL &

Second, we start the activator, pointing it to the locator's IOR file.

           $ $TAO_ROOT/orbsvcs/ImplRepo_Service/tao_imr_activator -ORBInitRef ImplRepoService=file://implrepo.ior

              ImR Activator: Starting doc.ece.uci.edu
              ImR Activator: Registered with ImR.

Next, we need to register our server with the implementation repository. We can use the `$TAO_ROOT/orbsvcs/ImplRepo_Service/tao_imr_locator` application provided with TAO to add our server to the server database in the implementation repository.

           $ $TAO_ROOT/orbsvcs/ImplRepo_Service/tao_imr_locator -ORBInitRef
             ImplRepoService=file://implrepo.ior add childPOA -c
             "./server -ORBUseIMR 1 -ORBobjrefstyle URL -ORBInitRef
             ImplRepoService=file://implrepo.ior"

              Successfully registered server

On Windows platforms, use this command instead to register the server in the implementation repository

        $ACE_ROOT/bin/tao_imr -ORBInitRef ImplRepoService=file://implrepo.ior
        add childPOA -c "./server -ORBUseIMR 1 -ORBobjrefstyle URL
        -ORBInitRef ImplRepoService=file://implrepo.ior"

We specify the `-ORBInitRef` option to use the IOR in the `implrepo.ior` file and the `-ORBUseIMR` option to tell the server to use the IMR for notification of its startup and shutdown.

The next step is to generate a simple IOR for our server to be used with the IMR, using the `ior` option, and write it to `stock_factory.ior`.

           $tao_imr -ORBInitRef ImplRepoService=file://implrepo.ior ior
           childPOA -f stock_factory.ior

             corbaloc:iiop:1.1@doc.ece.uci.edu:2690/childPOA

From now, the implementation repository is all set to keep track of our server and do the needful on a method invocation on our server.

Now, execute the client as usual.

           ./client file://stock_factory.ior MSFT RHAT

           The price of a stock in "Microsoft, Inc." is $91
           The price of a stock in "RedHat, Inc." is $210

For testing the persistency of the POA, let's shut down the server and then run the client.

           $tao_imr -ORBInitRef ImplRepoService=file://implrepo.ior
           shutdown childPOA

             Successfully shutdown server

           ./client file://stock_factory.ior MSFT RHAT

             The price of a stock in "RedHat, Inc." is $210
             The price of a stock in "Microsoft, Inc." is $91

### More Reading

More information on Implementation Repository is here.

The Henning and Vinoski CORBA book discusses POA policies in detail. Likewise, the Schmidt and Vinoski columns in C++ Report also include several articles about the POA. Finally, the TAO distribution includes examples that illustrate how to use the POA policies.

Last modified: Sat May 19 17:19:07 CDT 2001