Request/Response CORBA Stock Quoter Service (Assignment 1)

Overview

In this assignment, you will implement a simple Stock Quoter service using CORBA. Applications can use this service to determine the current value of a stock. In this service, CORBA remote operations are used to request the current stock quote from a particular machine in a network.

CORBA IDL Specification

The CORBA Stock Quoter service will be designed as a client/server pair using the following IDL specification:

// IDL schema definition for Stock Quoter service.
module Stock
{
  exception Invalid_Stock {};
  exception Invalid_Quoter {};

  /**
   * @class Quoter
   *
   * @brief Access Stock information.
   */
  interface Quoter {
    /// Returns the current stock value or throws an exception.
    long get_quote (in string stock_name) 
      raises (Invalid_Stock);
  };
  
  /**
   * @class Quoter
   *
   * @brief Factory that creates Quoter objects.
   */
  interface Quoter_Factory {

    /// Returns an object reference to a new Quoter selected 
    /// by name e.g., "Dow Jones," "Reuters," etc.
    Quoter create_quoter (in string name)
      raises (Invalid_Quoter);
  };
};
You will use the TAO CORBA IDL compiler to translate this specification into client-side stubs and server-side skeletons. The client application (which you must write) will use the stubs as a proxy to access the Stock Quoter service implemented by the server. In addition, you must also write the server, which implements the Quoter_Factory::create_quoter() and Quoter::get_quote() operations that provide the Stock Quoter service.

Server Functionality

On the server-side, you'll need to define a pair of classes that inherit from the skeletons generated by the IDL compiler. The C++ classes for this should look something like the following:

// Servant that implements the Quoter interface.

class Quoter_i : public virtual POA_Stock::Quoter, 
                 public virtual PortableServer::RefCountServantBase
{
public:
  // ...
  CORBA::Long get_quote (const char *stock_name);
};

class Quoter_Factory_i : public virtual POA_Stock::Quoter_Factory,
                         public virtual PortableServer::RefCountServantBase
{
public:
  // ...
  Quoter::Quoter_ptr create_quoter (const char *name);
};
To implement the Quoter_Factory_i::create_quoter() method you'll need to use explicit activiation with user-defined IDs, i.e., POA::activiate_object_with_id(). You'll need to use an STL std::map that maps names of the stock quoters (i.e., "Dow Jones" and "Reuters") to object references to Quoter instances. To implement the Quoter_i::get_quote() method you'll need to use an STL std::map that maps stock names (i.e., "BEAS," "IBM," and "MSFT") to stock quotes.

In addition, you'll need to implement a main() function that dynamically creates an instance of Quoter_Factory_i, obtains and activates the RootPOA, and then calls CORBA::ORB::run() method to run the server's event loop. To make your life easy, the server should write its IOR to a file before it calls the ORB's run() method (later, we'll use more advanced techniques, such as a Naming Service). Thus, when your server is started, you should create a file that contains something like the following

IOR:000000000000001649444c3a43756269745...
if you use the -ORBObjRefStyle IOR IOR format or

iioploc://1.1@tango.dre.vanderbilt.edu:10015/P35ad159600081a38/\0\1server
if you use the -ORBObjRefStyle URL IOR format. For more information on these options, please see the TAO online options documentation.

Client Functionality

The client program should read the name of the file that contains the IOR discussed above. When the client starts up, it will read the contents of this file into a string and use the CORBA::string_to_object() method to convert the string into an object reference. This object reference will then be downcast via _narrow() to an object reference for the Quoter::Quoter_Factory interface. At this point, the client should call the Quoter::Quoter_Factory::create_quoter() factory method via the object reference to obtain an object reference to the appropriate Quoter::Quoter_ptr from the server. After the client application has bound to an object reference for the Quoter::Quoter interface, it can call the get_quote() method via the object reference. For the purposes of the assignment, you can make the client-side driver program very simple. The client can read a command from its standard input and send it to the server. For example, you could type the following commands to the client:

% ./client tango.dre.vanderbilt.edu
> create "Dow Jones"
> get "MSFT"
Current value of MSFT is $100
If anything fails to work properly the client should simply print out the appropriate exception and exit with a return status of 1. If everything works correctly, the program should exit with a return status of 0.


Learning and Using CORBA

We will be using the TAO CORBA Object Request Broker (ORB) implementation. Please see the online help for information on how to setup your TAO development environment on EECS's computing system. If you'd prefer to use TAO on your laptop or home PC you can download it from deuce.doc.wustl.edu/Download.html.


Concluding Remarks

This first CORBA assignment is very simple. However, it will illustrate the basic skills required to become adept at using CORBA component middleware to developed distributed applications. Subsequent assignments will build on this assignment, so make sure you get it working correctly.


Back to CS 396 home page.