Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / lib / Control.cpp
blobc2fdf77cc4ac64efd7868c22bd864fa12693c464
1 /**
2 * @file Control.cpp
4 * @author Carlos O'Ryan <coryan@uci.edu>
5 */
7 #include "Control.h"
8 #include "ORB_Shutdown.h"
9 #include "Shutdown.h"
10 #include "Auto_Disconnect.h"
12 #include "orbsvcs/Event_Service_Constants.h"
14 #include "ace/High_Res_Timer.h"
15 #include "ace/Sample_History.h"
16 #include "ace/Basic_Stats.h"
17 #include "ace/Auto_Ptr.h"
19 Control::Control (size_t peers_expected,
20 size_t iterations,
21 int do_dump_history,
22 CORBA::ORB_ptr orb,
23 PortableServer::POA_ptr poa)
24 : peers_expected_ (peers_expected)
25 , iterations_ (iterations)
26 , do_dump_history_ (do_dump_history)
27 , orb_ (CORBA::ORB::_duplicate (orb))
28 , poa_ (PortableServer::POA::_duplicate (poa))
29 , peers_count_ (0)
30 , peers_ (new Federated_Test::Peer_var[this->peers_expected_])
34 Control::~Control (void)
36 delete[] this->peers_;
39 void
40 Control::join (Federated_Test::Peer_ptr peer)
43 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
44 if (this->peers_count_ == this->peers_expected_)
45 return;
47 this->peers_[this->peers_count_++] =
48 Federated_Test::Peer::_duplicate (peer);
50 if (this->peers_count_ < this->peers_expected_)
51 return;
54 /// Automatically shutdown the ORB
55 ACE_Utils::Auto_Functor<CORBA::ORB,ORB_Shutdown> orb_shutdown (this->orb_.in ());
57 /// Automatically shutdown the peers
58 typedef ACE_Utils::Auto_Functor<Federated_Test::Peer,Shutdown<Federated_Test::Peer> > Peer_Shutdown;
59 ACE_Auto_Basic_Array_Ptr<Peer_Shutdown> peer_shutdown (
60 new Peer_Shutdown[this->peers_count_]
63 size_t i;
64 for (i = 0; i != this->peers_count_; ++i)
66 peer_shutdown[i].reset(this->peers_[i].in());
69 ACE_DEBUG ((LM_DEBUG,
70 "Control (%P|%t) Building the federation\n"));
72 /// Build the EC federation
73 for (i = 0; i != this->peers_count_; ++i)
75 for (size_t j = 0; j != this->peers_count_; ++j)
77 if (i != j)
79 this->peers_[j]->connect (this->peers_[i].in ());
84 /// ... run the test(s) ...
85 for (i = 0; i != this->peers_count_; ++i)
87 /// ... automatically release the object references ...
88 ACE_Auto_Basic_Array_Ptr<Federated_Test::Loopback_var> loopbacks (
89 new Federated_Test::Loopback_var[2*this->peers_count_]
92 /// ... and automatically disconnect the loopbacks ...
93 typedef Auto_Disconnect<Federated_Test::Loopback> Loopback_Disconnect;
94 ACE_Auto_Basic_Array_Ptr<auto_ptr<Loopback_Disconnect> > disconnects (
95 new auto_ptr<Loopback_Disconnect>[2*this->peers_count_]
98 ACE_DEBUG ((LM_DEBUG,
99 "Control (%P|%t) Running test for peer %d\n",
100 i));
101 CORBA::Long experiment_id = 128 + i;
102 CORBA::Long base_event_type = ACE_ES_EVENT_UNDEFINED;
104 size_t lcount = 0;
106 size_t j;
107 for (j = 0; j != this->peers_count_; ++j)
109 if (j != i)
111 loopbacks[lcount] =
112 this->peers_[j]->setup_loopback (experiment_id,
113 base_event_type);
115 ACE_auto_ptr_reset (disconnects[lcount],
116 new Loopback_Disconnect (
117 loopbacks[lcount].in ()));
118 lcount++;
120 loopbacks[lcount] =
121 this->peers_[j]->setup_loopback (experiment_id,
122 base_event_type + 2);
124 ACE_auto_ptr_reset (disconnects[lcount],
125 new Loopback_Disconnect (
126 loopbacks[lcount].in ()));
127 lcount++;
131 Federated_Test::Experiment_Results_var results =
132 this->peers_[i]->run_experiment (experiment_id,
133 this->iterations_);
135 ACE_Sample_History history (results->length ());
136 for (CORBA::ULong k = 0; k != results->length (); ++k)
137 history.sample (results[k]);
139 // We use a fake scale factor because the peer already converted
140 // to microseconds...
141 const ACE_UINT32 fake_scale_factor = 1;
143 ACE_Basic_Stats stats;
144 history.collect_basic_stats (stats);
145 stats.dump_results (ACE_TEXT("Total"), fake_scale_factor);
147 if (this->do_dump_history_)
149 history.dump_samples (ACE_TEXT("HISTORY"), fake_scale_factor);
154 PortableServer::POA_ptr
155 Control::_default_POA (void)
157 return PortableServer::POA::_duplicate (this->poa_.in ());