The Stock_StockQuoter_i class is generated automatically by the IDL compiler (using the -GI flag), which is a subclass of POA_Stock::StockQuoter class.
Stock::StockInfo *stock = STOCK_DATABASE->get_stock_info (stock_name);
The Stock_StockDistributorHome_i class is generated automatically by the IDL compiler (using the -GI flag), which is a subclass of POA_Stock::StockDistributorHome class.
This class is also a subclass of ACE_Event_Handler, which can be used as an event handler.
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"));
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);
STOCK_DATABASE->activate (THR_NEW_LWP | THR_JOINABLE, 1);
CORBA::Object_var obj = orb_->resolve_initial_references ("RTORB");
RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (obj.in ());
TAO::Utils::PolicyList_Destroyer policies (2);
policies.length (2);
policies[0] =
rt_orb->create_priority_model_policy (RTCORBA::SERVER_DECLARED,
Stock::Priority_Mapping::VERY_LOW);
RTCORBA::ThreadpoolLanes lanes (5); lanes.length (5);
for (CORBA::ULong i = 0; i < lanes.length (); ++i)
{
lanes[i].lane_priority = static_cast (i);
lanes[i].static_threads = 5;
lanes[i].dynamic_threads = 0;
}
RTCORBA::ThreadpoolId threadpool_id =
rt_orb->create_threadpool_with_lanes (1024*1024,
lanes,
false, false, 0, 0);
policies[1] = rt_orb->create_threadpool_policy (threadpool_id);
PortableServer::POA_var poa = this->_default_POA ();
PortableServer::POAManager_var poa_mgr = poa->the_POAManager ();
PortableServer::POA_var child_poa =
poa->create_POA ("StockDistributor_POA",
poa_mgr.in (),
policies);
this->rt_poa_ = RTPortableServer::POA::_narrow (child_poa.in ());
this->create_distributor ();
StockDistributor_i *servant = new StockDistributor_i (this->rt_poa_.in ());
PortableServer::ServantBase_var distributor_owner_transfer = servant;
this->dist_id_ = this->rt_poa_->activate_object (servant);
obj = this->rt_poa_->id_to_reference (this->dist_id_.in ());
return Stock::StockDistributor::_narrow (obj.in ());
CORBA::Object_var obj (this->rt_poa_->id_to_reference (this->dist_id_.in ()));
Stock::StockDistributor_var dist (Stock::StockDistributor::_narrow (obj.in ()));
dist->shutdown ();
this->orb_->shutdown (true);
The Stock_StockDistributor_i class is generated automatically by the IDL compiler (using the -GI flag), which is a subclass of POA_Stock::StockDistributor class.
StockDistributor_i::StockDistributor_i (RTPortableServer::POA_ptr poa)
: rate_ (3), // Default is 3 seconds (3000 milliseconds).
active_ (false),
rt_poa_ (RTPortableServer::POA::_duplicate (poa)),
orb_ (CORBA::ORB::_duplicate (poa->_get_orb ()))
The "rate_" and "active_" are two private members of the Stock_StockDistributor_i class. They stand
for the notification rate and the active state of the StockDistributor object.
CookieMap::const_iterator iter = this->subscribers_list_.find (ck->cookie_id ());
Stock_StockQuoter_i *quoter = new Stock_StockQuoter_i;
PortableServer::ServantBase_var owner_transfer (quoter);
PortableServer::ObjectId *oid =
this->rt_poa_->activate_object_with_priority (quoter,
iter->second.second);
CORBA::Object_var obj = rt_poa_->id_to_reference (*oid);
Stock::StockQuoter_var quoter_var = ::Stock::StockQuoter::_narrow (obj.in ());
The main steps of this thread function are described as follows:
While the state of the StockDistributor object is active, continue the following looping:
for (Stock_StockDistributor_i::CookieMap::iterator iter = this->subscribers_list_.begin ();
iter != this->subscribers_list_.end ();
++iter)
{
try
{
// Set the designated priority for current request.
CORBA::Object_var obj = orb_->resolve_initial_references ("RTCurrent");
RTCORBA::Current_var rt_current =
RTCORBA::Current::_narrow (obj);
rt_current->the_priority (iter->second.second);
// Tell the database to push its information to the
// , which passes along the CORBA priority
// in the service_context list of the GIOP message.
STOCK_DATABASE->publish_stock_info (iter->second.first);
}
catch (CORBA::Exception &ex)
{
ACE_PRINT_EXCEPTION (ex, "Stock_StockDistributor_i::svc: ");
}
}
this->stop ();
::Stock::StockDistributor_var dist = this->_this ();
PortableServer::ObjectId_var oid = this->rt_poa_->reference_to_id (dist.in ());
this->rt_poa_->deactivate_object (oid.in ());