## Stock Database definition for the Stock Quoter Publisher/Subscriber Real-time CORBA Service

The Stock Database class is used to install, update and publish the information of all the stocks. It uses the singleton design pattern.

        typedef ACE_Singleton Stock_Database_Singleton;
        #define STOCK_DATABASE Stock_Database_Singleton::instance()

ACE_Singleton simply ensures that we create one single instance of the Stock_Database class at runtime, even if multiple threads all try to create one at the same time.

### Implementing the Constructor

The main steps of this function are described as follows:

- Create an array of stock names.

- Create a StockInfo object for each stock with the corresponding stock name and initialize its high, low and last values randomly.

- Insert the StockInfo objects into stock map, using the stock name as the key.

### Implementing the get_stock_info () function

The main steps of this function are described as follows:

- Get the read thread mutex of the stock map.

- Locate the stock in the stock database with the same stock name given in the argument.

- Create a StockInfo object of the former stock and return it.

### Implementing the publish_stock_info () function

This function is called by the Stock Distributor server's thread function to notify the Stock Broker client the state change of the stock it interested in.

- Get the read thread mutex of the stock map.

For each stock in the stock database, do the following steps:

- Initialze the StockName object with the name of the stock.

- Call the push_StockName () function of StockNameConsumer object (given in the argument), using the former StockName object.

### Implementing the svc () function

This function will be run when the stock database is started. This function is used to calculate the new high, low and last values of each stock in the stock database.

- Get the write thread mutex of the stock map.

- Calculate the new values for the stock.

- Sleep for a while.

Note: The get_stock_info (), publish_stock_info (), and svc () functions should have mutual exclusion of the stock map.

Email: shanshan.jiang@vanderbilt.edu