summaryrefslogtreecommitdiff
path: root/TAO/docs/tutorials/Quoter/RTCORBA/docs/broker.html
blob: 58c00fce654b6ba4418c3487ecddeb652b6a4969 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!-- $Id$ -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Stock Broker implementation 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 Broker implementation for the Stock Quoter Publisher/Subscriber Real-time CORBA Service</h2><hr>

<h3>Implementation of StockBrokerHome interface</h3>

This interface is used to register the necessary factories and mappings with the specified orb and 
create StockBroker objects. <P>

The Stock_StockBrokerHome_i class is generated automatically by the IDL compiler (using the -GI flag),
which is a subclass of POA_Stock::StockBrokerHome class. <P>

This class is also a subclass of ACE_Event_Handler, which can be used as an event handler. <P>

<h4>Implementing the Constructor</h4>

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

<li>Register the necessary factories and mappings with the specified orb.</li>

<PRE>
    Stock::StockName_init *stockname_factory = new Stock::StockName_init;
    orb->register_value_factory (stockname_factory->tao_repository_id (),
                                 stockname_factory
                                 ACE_ENV_ARG_PARAMETER);

    Stock::Cookie_init *cookie_factory = new Stock::Cookie_init;
    orb->register_value_factory (cookie_factory->tao_repository_id (),
                                 cookie_factory
                                 ACE_ENV_ARG_PARAMETER);

    Stock_PriorityMapping::register_mapping (orb);
</PRE>

<li>Register this class as an event handler with the ORB to catch ctrl-c from the command line. </li>

<PRE>
    if (orb_->orb_core ()->reactor ()->register_handler (SIGINT, this) == -1)
      ACE_DEBUG ((LM_DEBUG, "ERROR: Failed to register as a signal handler: %p\n", 
                  "register_handler\n"));
</PRE>

<h4>Implementing the create () member function</h4>

<li>If there is no instance of the StockBroker object in the StockBrokerHome object then create one. 
The "orb_", "dist", and "stock_name" are in the arguments of the create () function. 
Since the broker has nothing to do with any of the RTCORBA mechanisms, we can activate it under the
default_POA, which is the RootPOA. </li>

<PRE>
    Stock_StockBroker_i *broker = new Stock_StockBroker_i (orb_, dist, stock_name);
    PortableServer::ServantBase_var owner_transfer = broker;
    this->broker_ = broker->_this ();
</PRE>

<li>Return the StockBroker object. </li>

<PRE>
    return Stock::StockBroker::_duplicate (this->broker_.in ());
</PRE>

<h4>Implementing the handle_signal () member function</h4>

<li>Shutdown the broker object and the orb used by it. </li>

<PRE>
    this->broker_->shutdown ();
    
    this->orb_->shutdown (0);
</PRE>

<hr><h3>Implementation of StockBroker interface</h3>

This interface is used for Stock Broker client. <P>
The Stock_StockBroker_i class is generated automatically by the IDL compiler (using the -GI flag),
which is a subclass of POA_Stock::StockBroker class. <P>

<h4>Implementing the Constructor</h4>

<PRE>
    Stock_StockBroker_i (CORBA::ORB_ptr orb,
                         Stock::StockDistributor_ptr dist,
                         const char *stock_name)
      : orb_ (CORBA::ORB::_duplicate (orb)),
        quoter_ (Stock::StockQuoter::_nil()),
        consumer_ (0),
        distributor_ (Stock::StockDistributor::_duplicate (dist))
</PRE>

The "quoter_", "consumer_", and "distributor_" are four private members of the Stock_StockBroker_i class. 
They stand for the StockQuoter object that is used to get detailed stock information, the StockNameConsumer 
object that is used to get notification of updates, and the StockDistributor object that the StockBroker object 
is used to unsubscribe to. <P>

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

<li>Get a reference to the RTORB.</li>

<li>Initialize a CORBA::PolicyList object.</li>

<li>Create a CLIENT_PROPAGATED priority model policy and add it into the former CORBA::PolicyList object.</li>

<li>Create a child POA using the former CORBA::PolicyList and narrow it to RTPOA.</li>

<li>Create a new instance of the StockNameConsumer object with the specified name and activate it 
under the former RTPOA.</li>

<PRE>
    CORBA::Object_var obj = orb->resolve_initial_references ("RTORB");
    RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (obj.in ());
    
    TAO::Utils::PolicyList_Destroyer consumer_policies (1);
    consumer_policies.length (1);
    
    consumer_policies[0]
      = rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED,
                                              Stock::Priority_Mapping::MEDIUM);
    
    PortableServer::POA_var poa = this->_default_POA ();
    PortableServer::POAManager_var poa_mgr = poa->the_POAManager ();
    
    PortableServer::POA_var child_poa
      = poa->create_POA ("StockNameConsumer_POA",
                         poa_mgr.in (),
                         consumer_policies);
    
    RTPortableServer::POA_var rt_poa = RTPortableServer::POA::_narrow (child_poa.in ());
    
    this->consumer_ = new Stock_StockNameConsumer_i (*this, stock_name);
    PortableServer::ServantBase_var nameconsumer_owner_transfer = this->consumer_;
    rt_poa->activate_object (this->consumer_);
</PRE>

<h4>Implementing the get_consumer_notifier () member function</h4>

<li>Return the StockNameConsumer object created by the Constructor.</li>

<PRE>
    Stock::StockNameConsumer_var consumer = this->consumer_->_this ();
    return consumer._retn();
</PRE>

<h4>Implementing the connect_quoter_info () member function</h4>

<li>Duplicate a StockQuoter object using the StockQuoter object reference "c" in the argument.</li>

<PRE>
    quoter_ = Stock::StockQuoter::_duplicate (c);
</PRE>

<h4>Implementing the disconnect_quoter_info () member function</h4>

<li>Destroy the StockQuoter object and return it.</li>

<PRE>
    Stock::StockQuoter_var old_quoter = this->quoter_;
    this->quoter_ = Stock::StockQuoter::_nil();
    return old_quoter._retn ();
</PRE>

<h4>Implementing the get_connection_quoter_info () member function</h4>

<li>Return the StockQuoter object.</li>

<PRE>
    return Stock::StockQuoter::_duplicate (this->quoter_);
</PRE>

<h4>Implementing the shutdown () member function</h4>

<li>Unsubscribe the StockBroker object.</li>

<PRE>
    this->distributor_->unsubscribe_notifier (this->consumer_->cookie ());
</PRE>

<li>Deactivate the StockBroker object.</li>

<PRE>  
    ::Stock::StockBroker_var broker = this->_this ();
    PortableServer::ObjectId_var oid = this->_default_POA ()->reference_to_id (broker.in ());
  
    this->_default_POA ()->deactivate_object (oid.in ()); 
</PRE>

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

</body>

</html>