Stock Server subsystem

The Stock Server subsystem stores and dispatches stock data, using CommonPoint Persistent storage and RPC services.

This subsystem stores a year's worth of 1993 stock data for four companies. This data consists of stock information for each individual trading day. Each day's information consists of the high price, the low price, the closing price, the volume of stock traded, and the date. This information is defined in the TStockDay class that is discussed in, "Common Classes" on page 68.

Stock Browser provides access to the stock data using a client-server architecture. The implementation of the client-server code currently supports access to data on the same machine, but supporting access between machines only requires changing the statements that create the service reference and service definition (within TPickerPresenter::HandleOpen and TStockDispatcher::LaunchStockServer).

For information on CommonPoint client-server support, see
Distributed Computing.

CommonPoint RPC services require you to derive classes from MRemoteCaller and MRemoteDispatcher to implement remote procedure calls, and suggest you create an implementation class to perform the work for the dispatcher. TStockCaller, TStockDispatcher, and TStockServer serve this purpose.
These classes derive from Taligent mixin classes and the Stock Server's protocol class, MStockDatabase, which defines the calls that can be made by Stock
Server clients.

NOTE The Stock Server currently reads in the data from a disk dictionary generated by a setup routine. In the future, the data might come from an online stock service.


MStockDatabase defines the abstract protocol for classes that maintain and export stock data. MStockDatabase defines the abstract protocol for classes that maintain and export stock data. It provides functions for copying information about stocks.

TStockDatabase derives from MStockDatabase and implements standard CommonPoint class functionality, such as streaming operators. It does not implement CopyAvailableNames, CopyAllStocks, CopyStock, CopyStockData or GetTimeStamp, however, and remains abstract.

TStockServer is the server. It owns a TDiskDictionaryOf object that contains a persistent store of stock data.

TStockCaller is derived from MStockDatabase and MRemoteCaller. It is the class used by clients such as the Stock Picker to communicate with the Stock Server. From the client's perspective, TStockCaller is the Stock Server. It overrides each MStockDatabase function to begin a remote procedure call request to the Stock Server, to stream out the function arguments, wait for and stream back the results, and return them to the client.

TStockDispatcher is derived from MStockDispatcher. From a program point of view TStockDispatcher is the Stock Server. Objects of this class receive and dispatch to a TStockServer object the requests made by the TStockCaller object. This dispatching happens as follows: TStockDispatcher implements several "stub" functions and registers them with the CommonPoint RPC services. When a request is made to the Stock Server, one of the dispatcher's stub functions is called automatically. It streams in the function arguments and calls the appropriate function on the Stock Server object owned by the dispatcher. When the TStockServer function completes, the TStockDispatcher object streams the function results back to the TStockCaller that made the original RPC request. Then that TStockCaller object streams in and returns the results to its
client object.

TRemoteStockData is a concrete class derived from TStockData. It doesn't hold the actual stock data--it is aware of how to access it. Each time it is necessary to call TRemoteStockData::CopyData function to obtain data, TRemoteStockData goes back to the Stock Server and retrieves the data. It owns a TStockCaller object for this purpose.

You should note that TRemoteStockData catches no exceptions. If the Stock Server is inaccessible, TStockCaller catches the resultant TRemoteCallException and throws a TStockException with a kCouldNotComplete error code. It is up to the object using TRemoteStockData or TStockCaller to catch TStockException objects. If the Stock Viewer catches such an exception, it displays an error message in place of the graphed stock data.

Every service, such as the Stock Server, that runs under the CommonPoint application system needs to be able to shut down gracefully. TStockServerShutdownHandler is a simple example of what any service must do to be shutdown-friendly and provides a way for the CommonPoint system to shut down the Stock Server. All it does is create a TStockCaller object and make a call to its ExitDispatcher function, telling the TStockDispatcher object not to accept any more requests.

This is an easy way to avoid concurrency issues, because requests to the Stock Server are queued up in the order they are sent, and the ExitDispatcher call is the last request. For example, when a shutdown handler registers with the system shutdown server, it creates a thread in the client's address space which is used to dispatch method calls to the shutdown handler. Thus, shutdown methods such as CompleteShutdown execute in this thread set up by the system shutdown service.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker