4 * @author Carlos O'Ryan <coryan@uci.edu>
8 #include "ORB_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"
20 Control::Control (size_t peers_expected
,
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
))
31 , peers_ (new Federated_Test::Peer_var
[this->peers_expected_
])
35 Control::~Control (void)
37 delete[] this->peers_
;
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_
)
48 this->peers_
[this->peers_count_
++] =
49 Federated_Test::Peer::_duplicate (peer
);
51 if (this->peers_count_
< this->peers_expected_
)
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_
]
65 for (i
= 0; i
!= this->peers_count_
; ++i
)
67 peer_shutdown
[i
].reset(this->peers_
[i
].in());
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
)
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_
]
100 "Control (%P|%t) Running test for peer %d\n",
102 CORBA::Long experiment_id
= 128 + i
;
103 CORBA::Long base_event_type
= ACE_ES_EVENT_UNDEFINED
;
108 for (j
= 0; j
!= this->peers_count_
; ++j
)
113 this->peers_
[j
]->setup_loopback (experiment_id
,
116 disconnects
[lcount
].reset (new Loopback_Disconnect (loopbacks
[lcount
].in ()));
120 this->peers_
[j
]->setup_loopback (experiment_id
,
121 base_event_type
+ 2);
123 disconnects
[lcount
].reset (new Loopback_Disconnect (loopbacks
[lcount
].in ()));
128 Federated_Test::Experiment_Results_var results
=
129 this->peers_
[i
]->run_experiment (experiment_id
,
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 ());