Jacorb specifies the endpoint and implements a persistent CORBA object

Source: Internet
Author: User
I made an orb initialization class for each class. Import Java. util. properties; import Org. OMG. CORBA. *; import Org. OMG. cosnaming. *; import Org. OMG. portableserver. *;/***** @ author chenyi */public class osporbhelper {private Orb orb; private PoA rootpoa; private namingcontextext ncref; private string clientname; private string listenerendpoint = NULL; private string jacorbhomelib = NULL; private string jacorb_ns = NULL; private PoA persistentpoa = NUL L; private Boolean orb_init = false;/***** @ Param props * @ return int */Public int Init (properties props) {try {orb = orb. init (New String [0], props);} catch (exception e) {return-1;} Try {resolve_root_poa ();} catch (exception E) {return-2;} Try {resolve_naming_service ();} catch (exception e) {return-3;} orb_init = true; return 0 ;} /*** get PoA */private void resolve_root_poa () throws E Xception {rootpoa = poahelper. narrow (orb. resolve_initial_references ("rootpoa");/* Create policies */org. OMG. CORBA. policy [] policies = new Org. OMG. CORBA. policy [3]; policies [0] = rootpoa. create_id_assignment_policy (idassignmentpolicyvalue. user_id); policies [1] = rootpoa. create_lifespan_policy (lifespanpolicyvalue. persistent); policies [2] = rootpoa. create_servant_retention_policy (servantretentionp Olicyvalue. retain);/* Create PoA */persistentpoa = rootpoa. create_poa ("persistentpoa", rootpoa. the_poamanager (), policies); // activate the object; otherwise, the request rootpoa cannot be processed in the "hold state. the_poamanager (). activate (); policies [0]. destroy (); policies [1]. destroy (); policies [2]. destroy (); policies = NULL;}/*** obtain a reference to nameservices * the client and server must obtain the root name index before starting */private void resolve_naming_service () throws exception {Org. OMG. CORBA. object objref = orb. resolve_initial_references ("nameservice"); // use namingcontextext instead of namingcontext, ncref = namingcontextexthelper. narrow (objref);} private void init_orb () {} public orb getorb () {return ORB;} public PoA getrootpoa () {return rootpoa;} public namingcontextext getncref () {return ncref;} Public String getclientname () {return clientname;} Public String getl Istenerendpoint () {return listenerendpoint;} Public String evaluate () {return jacorbhomelib;} Public String getjacorb_ns () {return jacorb_ns;} public PoA getpersistentpoa () {return persistentpoa ;} public void clearrootpoa () {This. rootpoa = NULL;}/*** check whether orb initializes * @ return Boolean */Public synchronized Boolean getorbinit () {return orb_init;} public synchronized void setorbinit (Boolean B) {This. orb_init = B ;}} in a main class, the orb attribute is set as follows and orb: props = new properties (); props is initialized. put ("Java. endorsed. dirs "," E:/jacorb/lib "); props. put ("org. OMG. CORBA. orbclass "," org. jacorb. orb. orb "); props. put ("org. OMG. CORBA. orbsingletonclass "," org. jacorb. orb. orbsingleton "); props. put ("orbinitref. nameservice "," corbaloc: 192.168.100.221: 5060/nameservice "); props. put ("jacorb. user_imr "," on "); props. put ("J Acorb. use_imr_endpoint "," on "); props. put ("jacorb. implname "," test "); props. put ("orbdotteddecimaladdresses", 1); props. put ("oaaddress", "IIOP: // 192.168.100.100: 10025"); // start initialize orb osporbhelper orbhelper = new osporbhelper (); int ret = orbhelper. init (props); the method to disable orb is as follows: public void exit () {If (orbhelper. getncref ()! = NULL) {try {namecomponent NC = new namecomponent (clientname, osp_pm_datahandler); namecomponent path [] = new namecomponent [] {NC}; orbhelper. getncref (). unbind (PATH);} catch (exception ex) {ex. printstacktrace ();} Try {namecomponent NC = new namecomponent (clientname, osp_admin_handler); namecomponent path [] = new namecomponent [] {NC}; orbhelper. getncref (). unbind (PATH);} catch (exception ex ){ Ex. printstacktrace ();} Try {orbhelper. getorb (). shutdown (false); orbhelper. getorb (). destroy (); orbhelper. clearrootpoa ();} catch (exception ex) {ex. printstacktrace () ;}} orbhelper. setorbinit (false);} according to this configuration, you can use jacorb to bind the client address to 192.168.100.100 on the local machine, port 10025. If the machine IP address is different, you can modify the string following the corresponding oaaddress. The orbdotteddecimaladdresses attribute is 1, which uses IPv4. To open jacorb. user_imr, you must use a persistent CORBA object and set jacorb. implname so that orb can be initialized. The registration Naming Service is different from the general instantaneous CORBA object. ospipcproxyimpl is a class that implements the IDL-to-be-converted CORBA interface. The Code does not provide the ospipcproxyimpl m_ipcproxy = new ospipcproxyimpl (); // get object reference from the servant // There use persistent POA and active the object using ID. orbhelper. getpersistentpoa (). activate_object_with_id (name. getbytes (), m_ipcproxy); OBJ = orbhelper. getpersistentpoa (). servant_to_reference (m_ipcproxy); // name component, type is "objecttype" and name is "test" namecomponent NC = new namecomponent ("test", "objecttype "); namecomponent path [] = new namecomponent [] {NC}; // bind orbhelper. getncref (). BIND (path, OBJ); system. out. println ("registered successfully ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.