int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { // Fetching the high res timer's global scale factor ensures that it // is calibrated (if necessary on this platform) at the beginning of // the test. While the timer would otherwise be calibrated on first // use, this introduces delay in the middle of the test's execution. // This leads to failures due to timing assumptions (timeouts, etc.) // within the test itself. (void) ACE_High_Res_Timer::global_scale_factor(); try { CORBA::ORB_var orb = initialize_orb_and_poa(argc, argv); parse_args(argc, argv); test_i servant (orb.in()); CORBA::String_var ior = servant.create_and_activate_server(); write_ior_to_file(ior.in()); orb->run(); } catch(...) { report_exception(); return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR **argv) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); int result = parse_args (argc, argv); if (result != 0) return result; CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); server_i server_servant (quiet, orb.in ()); PortableServer::ObjectId_var id = root_poa->activate_object (&server_servant); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); server_var server_object = server::_narrow (object_act.in ()); CORBA::String_var ior = orb->object_to_string (server_object.in ()); result = write_ior_to_file (ior.in ()); if (result != 0) return result; Server_Task server_tasks (orb.in ()); result = server_tasks.activate (THR_BOUND, number_of_threads); if (result != 0) return result; result = ACE_Thread_Manager::instance ()->wait (); if (result != 0) return result; root_poa->destroy (1, 1); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("server::main"); return -1; } return 0; }
int create_POA_and_register_servant (CORBA::Policy_ptr threadpool_policy, const char *poa_name, PortableServer::POAManager_ptr poa_manager, PortableServer::POA_ptr root_poa, CORBA::ORB_ptr orb, RTCORBA::RTORB_ptr rt_orb) { // Policies for the firstPOA to be created. CORBA::PolicyList policies (3); policies.length (3); // Implicit_activation policy. policies[0] = root_poa->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION); // Thread pool policy. policies[1] = CORBA::Policy::_duplicate (threadpool_policy); // Priority Model policy. policies[2] = rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, 0); // Create the POA under the RootPOA. PortableServer::POA_var poa = root_poa->create_POA (poa_name, poa_manager, policies); // Creation of POAs is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } test_i *servant = new test_i (orb, poa.in (), nap_time); PortableServer::ServantBase_var safe_servant (servant); ACE_UNUSED_ARG (safe_servant); PortableServer::ObjectId_var id = poa->activate_object (servant); CORBA::Object_var object = poa->id_to_reference (id.in ()); test_var test = test::_narrow (object.in ()); int const result = write_ior_to_file (orb, test.in ()); return result; }
int Task::svc (void) { try { CORBA::Object_var object = this->orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); object = this->orb_->resolve_initial_references ("RTORB"); RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in ()); object = this->orb_->resolve_initial_references ("RTCurrent"); RTCORBA::Current_var current = RTCORBA::Current::_narrow (object.in ()); RTCORBA::Priority default_thread_priority = get_implicit_thread_CORBA_priority (this->orb_.in ()); test_i servant (this->orb_.in (), root_poa.in (), nap_time); PortableServer::ObjectId_var id = root_poa->activate_object (&servant); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); test_var test = test::_narrow (object_act.in ()); int result = write_ior_to_file (this->orb_.in (), test.in ()); if (result != 0) return result; poa_manager->activate (); CORBA::ULong stacksize = 0; CORBA::Boolean allow_request_buffering = false; CORBA::ULong max_buffered_requests = 0; CORBA::ULong max_request_buffer_size = 0; RTCORBA::ThreadpoolId threadpool_id_1 = rt_orb->create_threadpool (stacksize, static_threads, dynamic_threads, default_thread_priority, allow_request_buffering, max_buffered_requests, max_request_buffer_size); CORBA::Policy_var threadpool_policy_1 = rt_orb->create_threadpool_policy (threadpool_id_1); CORBA::Boolean allow_borrowing = false; RTCORBA::ThreadpoolLanes lanes (1); lanes.length (1); lanes[0].lane_priority = default_thread_priority; lanes[0].static_threads = static_threads; lanes[0].dynamic_threads = dynamic_threads; RTCORBA::ThreadpoolId threadpool_id_2 = rt_orb->create_threadpool_with_lanes (stacksize, lanes, allow_borrowing, allow_request_buffering, max_buffered_requests, max_request_buffer_size); CORBA::Policy_var threadpool_policy_2 = rt_orb->create_threadpool_policy (threadpool_id_2); result = create_POA_and_register_servant (threadpool_policy_1.in (), "first_poa", poa_manager.in (), root_poa.in (), this->orb_.in (), rt_orb.in ()); if (result != 0) return result; result = create_POA_and_register_servant (threadpool_policy_2.in (), "second_poa", poa_manager.in (), root_poa.in (), this->orb_.in (), rt_orb.in ()); if (result != 0) return result; this->orb_->run (); this->orb_->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return -1; } return 0; }
int Task::svc (void) { try { CORBA::Object_var object = this->orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); object = this->orb_->resolve_initial_references ("RTORB"); RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in ()); object = this->orb_->resolve_initial_references ("RTCurrent"); RTCORBA::Current_var current = RTCORBA::Current::_narrow (object.in ()); default_thread_priority = current->the_priority (); int result = 0; CORBA::ULong stacksize = 0; CORBA::Boolean allow_request_buffering = 0; CORBA::ULong max_buffered_requests = 0; CORBA::ULong max_request_buffer_size = 0; CORBA::PolicyList policies; CORBA::Boolean allow_borrowing = 0; if (number_of_lanes != 0) { get_auto_priority_lanes_and_bands (number_of_lanes, rt_orb.in (), stacksize, static_threads, dynamic_threads, allow_request_buffering, max_buffered_requests, max_request_buffer_size, allow_borrowing, policies, 1); } else if (ACE_OS::strcmp (lanes_file, ACE_TEXT("empty-file")) != 0) { result = get_priority_lanes ("server", lanes_file, rt_orb.in (), stacksize, static_threads, dynamic_threads, allow_request_buffering, max_buffered_requests, max_request_buffer_size, allow_borrowing, policies, 1); if (result != 0) return result; result = get_priority_bands ("server", bands_file, rt_orb.in (), policies, 1); if (result != 0) return result; } else { if (pool_priority == ACE_INT16_MIN) pool_priority = default_thread_priority; RTCORBA::ThreadpoolId threadpool_id = rt_orb->create_threadpool (stacksize, static_threads, dynamic_threads, pool_priority, allow_request_buffering, max_buffered_requests, max_request_buffer_size); policies.length (policies.length () + 1); policies[policies.length () - 1] = rt_orb->create_threadpool_policy (threadpool_id); if (ACE_OS::strcmp (bands_file, ACE_TEXT("empty-file")) != 0) { result = get_priority_bands ("server", bands_file, rt_orb.in (), policies, 1); if (result != 0) return result; } } policies.length (policies.length () + 1); policies[policies.length () - 1] = root_poa->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION); policies.length (policies.length () + 1); policies[policies.length () - 1] = rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, default_thread_priority); PortableServer::POA_var poa = root_poa->create_POA ("RT POA", poa_manager.in (), policies); test_i *servant = new test_i (this->orb_.in (), poa.in ()); PortableServer::ServantBase_var safe_servant (servant); ACE_UNUSED_ARG (safe_servant); test_var test = servant->_this (); result = write_ior_to_file (ior_output_file, this->orb_.in (), test.in ()); if (result != 0) return result; poa_manager->activate (); this->orb_->run (); this->orb_->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }