PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::create_object_group ( CORBA::ULong group_id, const PortableServer::ObjectId &oid, const char * type_id, const PortableGroup::Criteria & the_criteria) { if (CORBA::is_nil (this->poa_.in ())) throw CORBA::INTERNAL (); // Create a reference for the ObjectGroup corresponding to the // RepositoryId of the object being created. CORBA::Object_var object_group = this->poa_->create_reference_with_id (oid, type_id); TAO_PG_ObjectGroup_Map_Entry * group_entry = 0; ACE_NEW_THROW_EX (group_entry, TAO_PG_ObjectGroup_Map_Entry, CORBA::NO_MEMORY ( CORBA::SystemException::_tao_minor_code ( TAO::VMCID, ENOMEM), CORBA::COMPLETED_NO)); auto_ptr<TAO_PG_ObjectGroup_Map_Entry> safe_group_entry (group_entry); // Set the RepositoryId associated with the created ObjectGroup_Map // entry. group_entry->type_id = CORBA::string_dup (type_id); group_entry->group_id = group_id; group_entry->object_group = object_group; CORBA::ULong len = the_criteria.length (); group_entry->properties.length (len); for (CORBA::ULong i = 0; i < len; ++i) group_entry->properties[i] = the_criteria[i]; { ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0); if (this->object_group_map_.bind (oid, group_entry) != 0) throw PortableGroup::ObjectNotCreated (); } (void) safe_group_entry.release (); return object_group._retn (); }
CORBA::Object_ptr TAO::Object_Group_Creator::create_infrastructure_managed_group ( const char * type_id) { CORBA::Object_var group = CORBA::Object::_nil (); if (this->have_replication_manager_) { // set typeid properties PortableGroup::Properties properties (1); properties.length (3); properties[0].nam.length (1); properties[0].nam[0].id = PortableGroup::PG_MEMBERSHIP_STYLE; properties[0].val <<= PortableGroup::MEMB_INF_CTRL; PortableGroup::InitialNumberMembersValue inm(2); properties[1].nam.length (1); properties[1].nam[0].id = PortableGroup::PG_INITIAL_NUMBER_MEMBERS; properties[1].val <<= inm; PortableGroup::MinimumNumberMembersValue mnm(1); properties[2].nam.length (1); properties[2].nam[0].id = PortableGroup::PG_MINIMUM_NUMBER_MEMBERS; properties[2].val <<= mnm; this->replication_manager_->set_type_properties ( type_id, properties); ::PortableGroup::GenericFactory::FactoryCreationId_var creation_id; PortableGroup::Criteria criteria (1); criteria.length (1); criteria[0].nam.length (1); criteria[0].nam[0].id = PortableGroup::PG_MEMBERSHIP_STYLE; criteria[0].val <<= PortableGroup::MEMB_APP_CTRL; group = this->replication_manager_->create_object ( type_id, criteria, creation_id ); } else { ACE_ERROR ((LM_ERROR, ACE_TEXT("%T %n (%P|%t): Object_Group_Creator: infrastructure managed group requires Replication Manager\n") )); } return group._retn (); }
int LB_server::create_object_group (void) { try { const char *repository_id = "IDL:Test/Basic:1.0"; PortableGroup::Criteria criteria (1); criteria.length (1); PortableGroup::Property &property = criteria[0]; property.nam.length (1); property.nam[0].id = CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle"); PortableGroup::MembershipStyleValue msv = PortableGroup::MEMB_APP_CTRL; property.val <<= msv; this->object_group_ = this->lm_->create_object (repository_id, criteria, this->fcid_.out ()); CORBA::String_var ior = this->orb_->object_to_string (this->object_group_.in ()); this->write_ior_to_file (ior.in ()); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "Exception raised while creating object group"); return -1; } return 1; }
CORBA::Object_ptr TAO::Object_Group_Creator::create_group ( const char * role, int write_iors) { CORBA::Object_var group = CORBA::Object::_nil (); PortableGroup::ObjectGroupId group_id = 0; CORBA::String_var type_id; ::PortableGroup::FactoryInfos_var infos = this->registry_->list_factories_by_role (role, type_id); CORBA::ULong count = infos->length (); ACE_ERROR ((LM_INFO, ACE_TEXT ("%T %n (%P|%t): Object_Group_Creator: ") ACE_TEXT ("found %u factories for %s : %s\n"), static_cast<unsigned> (count), role, type_id.in ())); if (count > 0) { /////////////////////////// // Begin with an empty IOGR ::PortableGroup::GenericFactory::FactoryCreationId_var creation_id; if (this->have_replication_manager_) { ////////////////////////////////////////////////////// // note infrastructure controlled because we want the // ReplicationManager to manage the object after it's created. // Initial number members = 0 because we do not want the Replication // Manager to populate the group. // Minimum number of members = 0 because we do not want the // Replication Manager to replace failed members. // Semi-active, because that's what we do. PortableGroup::Criteria criteria (3); criteria.length (4); criteria[0].nam.length (1); criteria[0].nam[0].id = PortableGroup::PG_MEMBERSHIP_STYLE; criteria[0].val <<= PortableGroup::MEMB_INF_CTRL; criteria[1].nam.length (1); criteria[1].nam[0].id = PortableGroup::PG_INITIAL_NUMBER_MEMBERS; criteria[1].val <<= PortableGroup::InitialNumberMembersValue (0); criteria[2].nam.length (1); criteria[2].nam[0].id = PortableGroup::PG_MINIMUM_NUMBER_MEMBERS; criteria[2].val <<= PortableGroup::MinimumNumberMembersValue (0); criteria[3].nam.length (1); criteria[3].nam[0].id = FT::FT_REPLICATION_STYLE; criteria[3].val <<= FT::SEMI_ACTIVE; group = this->replication_manager_->create_object ( type_id.in (), criteria, creation_id ); //@@ this is a bit of a hack creation_id >>= group_id; }
CORBA::Object_ptr join_object_group (CORBA::ORB_ptr orb, CosLoadBalancing::LoadManager_ptr lm, const PortableGroup::Location & location) { CORBA::Object_var ns_object = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow (ns_object.in ()); CosNaming::Name name (1); name.length (1); name[0].id = "RoundtripObjectGroup"; name[0].kind = "Object Group"; CORBA::Object_var group; try { group = nc->resolve (name); } catch (const CosNaming::NamingContext::NotFound& ) { // Object group not created. Create one. const char repository_id[] = "IDL:Test/Roundtrip:1.0"; PortableGroup::Criteria criteria (1); criteria.length (1); PortableGroup::Property & property = criteria[0]; property.nam.length (1); property.nam[0].id = CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle"); PortableGroup::MembershipStyleValue msv = PortableGroup::MEMB_APP_CTRL; property.val <<= msv; PortableGroup::GenericFactory::FactoryCreationId_var fcid; group = lm->create_object (repository_id, criteria, fcid.out ()); try { nc->bind (name, group.in ()); PortableGroup::Properties props (1); props.length (1); props[0].nam.length (1); props[0].nam[0].id = CORBA::string_dup ("org.omg.CosLoadBalancing.StrategyInfo"); CosLoadBalancing::StrategyInfo strategy_info; strategy_info.name = CORBA::string_dup (strategy); if (ACE_OS::strcasecmp (strategy, "LeastLoaded") == 0 && (reject_threshold != 0 || critical_threshold != 0 || dampening != 0)) { CORBA::ULong len = 1; PortableGroup::Properties & props = strategy_info.props; if (reject_threshold != 0) { const CORBA::ULong i = len - 1; props.length (len++); props[i].nam.length (1); props[i].nam[0].id = CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.RejectThreshold"); props[i].val <<= reject_threshold; } if (critical_threshold != 0) { const CORBA::ULong i = len - 1; props.length (len++); props[i].nam.length (1); props[i].nam[0].id = CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.CriticalThreshold"); props[i].val <<= critical_threshold; } if (dampening != 0) { const CORBA::ULong i = len - 1; props.length (len++); props[i].nam.length (1); props[i].nam[0].id = CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.Dampening"); props[i].val <<= dampening; } } props[0].val <<= strategy_info; lm->set_default_properties (props); } catch (const CosNaming::NamingContext::AlreadyBound& ) { // Somebody beat us to creating the object group. Clean up // the one we created. lm->delete_object (fcid.in ()); group = nc->resolve (name); } } Roundtrip * roundtrip_impl; ACE_NEW_THROW_EX (roundtrip_impl, Roundtrip (orb), CORBA::NO_MEMORY ()); PortableServer::ServantBase_var owner_transfer (roundtrip_impl); Test::Roundtrip_var roundtrip = roundtrip_impl->_this (); group = lm->add_member (group.in (), location, roundtrip.in ()); return group._retn (); }
int NS_group_svc::group_create ( const ACE_TCHAR* group_name, const ACE_TCHAR* policy ) { if (group_name == 0 || policy == 0 ) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("group_create args not provided\n")), -2); } /// Validate load balancing strategy policy string FT_Naming::LoadBalancingStrategyValue strategy; if (false == determine_policy_string (policy, strategy)) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%s is not a valid policy.\n"), policy), -2); } try { /// Verify that the group does not already exist /// Group names must be unique if ( true == group_exist (group_name)) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Group %s already exists\n"), group_name), -1); } PortableGroup::Criteria criteria (1); criteria.length (1); PortableGroup::Property &property = criteria[0]; property.nam.length (1); property.nam[0].id = CORBA::string_dup ( "org.omg.PortableGroup.MembershipStyle"); PortableGroup::MembershipStyleValue msv = PortableGroup::MEMB_APP_CTRL; property.val <<= msv; CORBA::Object_var obj = this->naming_manager_->create_object_group ( ACE_TEXT_ALWAYS_CHAR (group_name), strategy, criteria); if (CORBA::is_nil (obj.in ())) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("\nUnable to create group %s.\n"), group_name), -1); } } catch (const CORBA::Exception&) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("\nUnable to create group %s\n"), group_name), -1); } return 0; }
CORBA::Boolean TAO_LB_ObjectReferenceFactory::find_object_group ( const char * repository_id, CORBA::ULong & index, PortableGroup::ObjectGroup_out object_group) { if (!this->load_managed_object (repository_id, index)) return false; PortableGroup::ObjectGroup_var group; if (this->table_.find (repository_id, group) != 0) { if (ACE_OS::strcasecmp (this->object_groups_[index], "CREATE") == 0) { PortableGroup::Criteria criteria (1); criteria.length (1); PortableGroup::Property & property = criteria[0]; property.nam.length (1); property.nam[0].id = CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle"); // Configure for application-controlled membership. PortableGroup::MembershipStyleValue msv = PortableGroup::MEMB_APP_CTRL; property.val <<= msv; PortableGroup::GenericFactory::FactoryCreationId_var fcid; group = this->lm_->create_object (repository_id, criteria, fcid.out ()); CORBA::ULong const len = this->fcids_.size (); this->fcids_.size (len + 1); // Incremental growth. Yuck! this->fcids_[len] = fcid; } else { group = this->orb_->string_to_object (this->object_groups_[index]); } if (this->table_.bind (repository_id, group) != 0) { if (TAO_debug_level > 0) ORBSVCS_ERROR ((LM_ERROR, "TAO_LB_ObjectReferenceFactory::" "find_object_group - " "Couldn't bind object group reference.\n")); throw CORBA::INTERNAL (); } object_group = group._retn (); } return 1; }