## Execution programs for the Stock Quoter Publisher/Subscriber Real-time CORBA Service

There are three execution programs (*.cpp files that have the main () functions) in this system: Distributor, Broker and Admin. Each of them belongs to the corresponding project defined in the StockQuoter.mpc file.

### Building the Distributor program

The Distributor.cpp file is used for this purpose. It contains the main () function and is used to generated the Distributor execution file. The main steps in this file are described as follows:

- Initalize the ORB.

- Parse the command-line arguments, which give the stock distributor notification rate and the stock database update rate.

- Get the RootPOA.

- Activate the POAManager.

- Create a StockDistributor factory object, which will then create a StockDistributor object.

        Stock_StockDistributorHome_i stock_distributor_home (orb.in ());
        Stock::StockDistributor_var stock_distributor = stock_distributor_home.create ();

- Register the StockDistributor servant with the Naming Service or write the object reference of the StockDistributor object to a file such that other projects can read it when they are bootstrapping.

- Set the initial notification rate of the StockDistributor object.

- Set the database update rate.

- Enter into the event looping.

- Cleanup the POA and ORB.

### Building the Broker program

The Broker.cpp file is used for this purpose. It contains the main () function and is used to generated the Broker execution file. The main steps in this file are described as follows:

- Initalize the ORB.

- Parse the command-line arguments, which give the stock name and the priority of the StockBroker object (actually, the priority of the StockNameConsumer object that the StockBroker object contains).

- Get the RootPOA.

- Activate the POAManager.

- Create a StockBroker factory object, which will then create a StockBroker object.

        Stock_StockBrokerHome_i stock_broker_home (orb, stock_name, priority);
        Stock::StockBroker_var stock_broker = stock_broker_home.create ();

- Read and destringify the StockDistributor object's IOR or use Naming Service to get the object reference and narrow it to a StockDistributor object reference.

- Create a StockBroker factory object and use it to create a StockBroker object.

        Stock_StockBrokerHome_i stock_broker_home (orb.in ());
        Stock::StockBroker_var stock_broker = stock_broker_home.create (stock_distributor.in (), stock_name.c_str ());

- Create a new consumer; initialize it; subscribe it with the Stock Distributor server.

        Stock::StockNameConsumer_var consumer = stock_broker->get_consumer_notifier ();
        Stock::Cookie_var cookie = stock_distributor->subscribe_notifier (consumer, priority_level);
        consumer->cookie (cookie.in ());

- Set the cookie attribute of the consumer.

        consumer->cookie (cookie.in ());

- Get the object reference to a StockQuoter that's been activated at the appropriate priority.

        Stock::StockQuoter_var stock_quoter = stock_distributor->provide_quoter_info (cookie.in ());

- Stash the StockQuoter object reference away for later use.

        stock_broker->connect_quoter_info (stock_quoter);

- Enter into the event looping.

- Cleanup the POA and ORB.

### Building the Admin program

The Admin.cpp file is used for this purpose. It contains the main () function and is used to generated Admin execution file. The main steps in this file are described as follows:

- Initalize the ORB.

- Parse the command-line arguments, which give the option of different operations of StockDistributor interface.

- Read and destringify the StockDistributor object's IOR or use Naming Service to get the object reference and narrow it to a StockDistributor object reference.

- Call the operations of StockDistributor interface:

        start: Start the distributor.
        stop: Stop the distributor.
        rate: Change the notification rate of the distributor.

- Cleanup the ORB.

### Running the Stock Quoter Service

When executing the programs, they should be executed in the following order:

        Distributor
        Broker
        Admin

You can run more than one Broker program at the same time. Each of them should be given different stock name that it is interested in. All the stock information is installed in the Stock Database. The number of stocks can easily be extended by adding items to the stock_names array of the Stock Database constuctor.

Email: shanshan.jiang@vanderbilt.edu