2 #include "AMI_Manager.h"
3 #include "ace/OS_NS_unistd.h"
6 validate_connection (Test::Controller_ptr controller
)
10 #if (TAO_HAS_CORBA_MESSAGING == 1)
11 CORBA::PolicyList_var unused
;
12 controller
->_validate_connection (unused
);
14 controller
->_is_a ("Not_an_IDL_Type");
17 catch (const CORBA::Exception
&)
22 AMI_Manager::AMI_Manager (CORBA::ORB_ptr orb
)
23 : orb_ (CORBA::ORB::_duplicate (orb
))
28 AMI_Manager::start_workers (CORBA::Short worker_count
,
29 CORBA::Long milliseconds
,
30 Test::Controller_ptr controller
)
32 ACE_Thread_Manager thread_manager
;
34 validate_connection(controller
);
36 // ACE_DEBUG ((LM_DEBUG, "Starting %d workers\n", worker_count));
37 Worker
worker (&thread_manager
,
38 controller
, milliseconds
,
41 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
, worker_count
);
43 thread_manager
.wait ();
47 AMI_Manager::shutdown ()
49 this->orb_
->shutdown (false);
52 // ****************************************************************
54 Worker::Worker (ACE_Thread_Manager
*thr_mgr
,
55 Test::Controller_ptr controller
,
56 CORBA::Long milliseconds
,
58 : ACE_Task_Base (thr_mgr
)
59 , controller_ (Test::Controller::_duplicate (controller
))
60 , milliseconds_ (milliseconds
)
61 , orb_ (CORBA::ORB::_duplicate (orb
))
68 // ACE_DEBUG ((LM_DEBUG, "Worker starts\n"));
71 TAO_SYNCH_MUTEX mutex
;
72 int pending_requests
= 2;
73 Test::AMI_ControllerHandler_var handler
;
76 Controller_Handler
*handler_impl
;
77 ACE_NEW_RETURN (handler_impl
,
78 Controller_Handler (&mutex
,
82 CORBA::Object_var poa_object
=
83 this->orb_
->resolve_initial_references("RootPOA");
85 PortableServer::POA_var root_poa
=
86 PortableServer::POA::_narrow (poa_object
.in ());
88 PortableServer::ObjectId_var id
=
89 root_poa
->activate_object (handler_impl
);
91 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
93 PortableServer::ServantBase_var
auto_destroy (handler_impl
);
94 handler
= Test::AMI_ControllerHandler::_narrow (object
.in ());
97 validate_connection(this->controller_
.in());
99 this->controller_
->sendc_worker_started (handler
.in ());
101 // ACE_DEBUG ((LM_DEBUG, "Worker start reported\n"));
103 ACE_Time_Value
tv (0, 1000 * this->milliseconds_
);
106 this->controller_
->sendc_worker_finished (handler
.in ());
108 // ACE_DEBUG ((LM_DEBUG, "Worker completion reported\n"));
112 ACE_Time_Value
tv (0, 1000 * this->milliseconds_
);
113 this->orb_
->run (tv
);
115 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, mutex
, -1);
116 if (pending_requests
== 0)
120 catch (const CORBA::Exception
& ex
)
122 ex
._tao_print_exception ("Exception in svc() method\n");
127 // ****************************************************************
129 Controller_Handler::Controller_Handler (TAO_SYNCH_MUTEX
*mutex
,
130 int *pending_replies
)
132 , pending_replies_ (pending_replies
)
137 Controller_Handler::worker_started ()
139 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, *this->mutex_
);
140 (*this->pending_replies_
)--;
144 Controller_Handler::worker_started_excep
145 (::Messaging::ExceptionHolder
* h
)
149 h
->raise_exception ();
151 catch (const CORBA::Exception
& ex
)
153 ex
._tao_print_exception (
154 "Controller_Handler exception raised in"" worker_started");
159 Controller_Handler::worker_finished ()
161 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, *this->mutex_
);
162 (*this->pending_replies_
)--;
166 Controller_Handler::worker_finished_excep
167 (::Messaging::ExceptionHolder
*h
)
171 h
->raise_exception ();
173 catch (const CORBA::Exception
& ex
)
175 ex
._tao_print_exception (
176 "Controller_Handler exception raised in"" worker_finished");