summaryrefslogtreecommitdiff
path: root/TAO/docs/tutorials/Quoter/RTCORBA/docs/database.html
blob: 07ff35a8cf34296b1b89517fe590fe8b2d3d3a83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!-- $Id$ -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Stock Database definition for the Stock Quoter Publisher/Subscriber Real-time CORBA Service</title>
</head>

<body
 text = "#000000"
 link = "#000fff"
 vLink= "#ff0f0f"
 aLink = "#0000ff"
 bgColor = "#ffffff">

<hr><h2>Stock Database definition for the Stock Quoter Publisher/Subscriber Real-time CORBA Service</h2><hr>

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

<PRE>
    typedef ACE_Singleton<Stock_Database, ACE_Thread_Mutex> Stock_Database_Singleton;
    #define STOCK_DATABASE Stock_Database_Singleton::instance()
</PRE>

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.

<h3>Implementing the Constructor</h3>

The main steps of this function are described as follows: <P>

<li>Create an array of stock names.</li> <P>

<li>Create a StockInfo object for each stock with the corresponding stock name and initialize
its high, low and last values randomly.</li> <P>

<li>Insert the StockInfo objects into stock map, using the stock name as the key.</li> <P>

<hr><h3>Implementing the get_stock_info () function</h3>

The main steps of this function are described as follows: <P>

<li>Get the read thread mutex of the stock map.</li> <P>

<li>Locate the stock in the stock database with the same stock name given in the argument.</li> <P>

<li>Create a StockInfo object of the former stock and return it.</li> <P>

<hr><h3>Implementing the publish_stock_info () function</h3>

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. <P>

<li>Get the read thread mutex of the stock map.</li> <P>

For each stock in the stock database, do the following steps: <P>

<li>Initialze the StockName object with the name of the stock.</li> <P>

<li>Call the push_StockName () function of StockNameConsumer object (given in the argument),
using the former StockName object.</li> <P>

<hr><h3>Implementing the svc () function</h3>

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. <P>

<li>Get the write thread mutex of the stock map.</li> <P>

<li>Calculate the new values for the stock.</li> <P>

<li>Sleep for a while.</li> <P>

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

<hr><b>Email: </b><a href="mailto:"</a<ADDRESS>shanshan.jiang@vanderbilt.edu</ADDRESS>

</body>

</html>