ACE+TAO-7_0_8
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / lib / Control.cpp
blobffcc2320f5ace546bde59fe6f5623ef82fb9648a
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"
18 #include <memory>
20 Control::Control (size_t peers_expected,
21 size_t iterations,
22 int do_dump_history,
23 CORBA::ORB_ptr orb,
24 PortableServer::POA_ptr poa)
25 : peers_expected_ (peers_expected)
26 , iterations_ (iterations)
27 , do_dump_history_ (do_dump_history)
28 , orb_ (CORBA::ORB::_duplicate (orb))
29 , poa_ (PortableServer::POA::_duplicate (poa))
30 , peers_count_ (0)
31 , peers_ (new Federated_Test::Peer_var[this->peers_expected_])
35 Control::~Control (void)
37 delete[] this->peers_;
40 void
41 Control::join (Federated_Test::Peer_ptr peer)
44 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
45 if (this->peers_count_ == this->peers_expected_)
46 return;
48 this->peers_[this->peers_count_++] =
49 Federated_Test::Peer::_duplicate (peer);
51 if (this->peers_count_ < this->peers_expected_)
52 return;
55 /// Automatically shutdown the ORB
56 ACE_Utils::Auto_Functor<CORBA::ORB,ORB_Shutdown> orb_shutdown (this->orb_.in ());
58 /// Automatically shutdown the peers
59 typedef ACE_Utils::Auto_Functor<Federated_Test::Peer,Shutdown<Federated_Test::Peer> > Peer_Shutdown;
60 ACE_Auto_Basic_Array_Ptr<Peer_Shutdown> peer_shutdown (
61 new Peer_Shutdown[this->peers_count_]
64 size_t i;
65 for (i = 0; i != this->peers_count_; ++i)
67 peer_shutdown[i].reset(this->peers_[i].in());
70 ACE_DEBUG ((LM_DEBUG,
71 "Control (%P|%t) Building the federation\n"));
73 /// Build the EC federation
74 for (i = 0; i != this->peers_count_; ++i)
76 for (size_t j = 0; j != this->peers_count_; ++j)
78 if (i != j)
80 this->peers_[j]->connect (this->peers_[i].in ());
85 /// ... run the test(s) ...
86 for (i = 0; i != this->peers_count_; ++i)
88 /// ... automatically release the object references ...
89 ACE_Auto_Basic_Array_Ptr<Federated_Test::Loopback_var> loopbacks (
90 new Federated_Test::Loopback_var[2*this->peers_count_]
93 /// ... and automatically disconnect the loopbacks ...
94 typedef Auto_Disconnect<Federated_Test::Loopback> Loopback_Disconnect;
95 ACE_Auto_Basic_Array_Ptr<std::unique_ptr<Loopback_Disconnect> > disconnects (
96 new std::unique_ptr<Loopback_Disconnect>[2*this->peers_count_]
99 ACE_DEBUG ((LM_DEBUG,
100 "Control (%P|%t) Running test for peer %d\n",
101 i));
102 CORBA::Long experiment_id = 128 + i;
103 CORBA::Long base_event_type = ACE_ES_EVENT_UNDEFINED;
105 size_t lcount = 0;
107 size_t j;
108 for (j = 0; j != this->peers_count_; ++j)
110 if (j != i)
112 loopbacks[lcount] =
113 this->peers_[j]->setup_loopback (experiment_id,
114 base_event_type);
116 disconnects[lcount].reset (new Loopback_Disconnect (loopbacks[lcount].in ()));
117 lcount++;
119 loopbacks[lcount] =
120 this->peers_[j]->setup_loopback (experiment_id,
121 base_event_type + 2);
123 disconnects[lcount].reset (new Loopback_Disconnect (loopbacks[lcount].in ()));
124 lcount++;
128 Federated_Test::Experiment_Results_var results =
129 this->peers_[i]->run_experiment (experiment_id,
130 this->iterations_);
132 ACE_Sample_History history (results->length ());
133 for (CORBA::ULong k = 0; k != results->length (); ++k)
134 history.sample (results[k]);
136 // We use a fake scale factor because the peer already converted
137 // to microseconds...
138 const ACE_UINT32 fake_scale_factor = 1;
140 ACE_Basic_Stats stats;
141 history.collect_basic_stats (stats);
142 stats.dump_results (ACE_TEXT("Total"), fake_scale_factor);
144 if (this->do_dump_history_)
146 history.dump_samples (ACE_TEXT("HISTORY"), fake_scale_factor);
151 PortableServer::POA_ptr
152 Control::_default_POA (void)
154 return PortableServer::POA::_duplicate (this->poa_.in ());