Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / LongUpcalls / Manager.cpp
blob6d6eac005d37fdc7fdae7364bdf5fd9659d0ae31
2 #include "Manager.h"
3 #include "ace/OS_NS_unistd.h"
5 static void
6 validate_connection (Test::Controller_ptr controller)
8 try
10 #if (TAO_HAS_CORBA_MESSAGING == 1)
11 CORBA::PolicyList_var unused;
12 controller->_validate_connection (unused);
13 #else
14 controller->_is_a ("Not_an_IDL_Type");
15 #endif
17 catch (const CORBA::Exception&)
22 Manager::Manager (CORBA::ORB_ptr orb)
23 : orb_ (CORBA::ORB::_duplicate (orb))
27 void
28 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);
40 worker.activate (THR_NEW_LWP | THR_JOINABLE, worker_count);
42 thread_manager.wait ();
45 void
46 Manager::shutdown (void)
48 this->orb_->shutdown (0);
52 // ****************************************************************
54 Worker::Worker (ACE_Thread_Manager *thr_mgr,
55 Test::Controller_ptr controller,
56 CORBA::Long milliseconds)
57 : ACE_Task_Base (thr_mgr)
58 , controller_ (Test::Controller::_duplicate (controller))
59 , milliseconds_ (milliseconds)
63 int
64 Worker::svc (void)
66 // ACE_DEBUG ((LM_DEBUG, "Worker starts\n"));
67 try
69 validate_connection(this->controller_.in());
71 this->controller_->worker_started ();
73 // ACE_DEBUG ((LM_DEBUG, "Worker start reported\n"));
75 ACE_Time_Value tv (0, 1000 * this->milliseconds_);
76 ACE_OS::sleep (tv);
78 this->controller_->worker_finished ();
80 // ACE_DEBUG ((LM_DEBUG, "Worker completion reported\n"));
82 catch (const CORBA::Exception& ex)
84 ex._tao_print_exception ("Exception in svc() method\n");
86 return 0;