1 28 29 30 package org.objectweb.corba.runtime; 31 32 36 public class Runtime 37 { 38 static private String _class_name = "Runtime"; 39 static private FactoryFinderService _ff_service; 40 static private RegistrationService _reg_service; 41 static private MainThread _main_thread; 42 static private org.omg.CORBA.ORB _orb; 44 45 static { 46 _ff_service = new FactoryFinderServiceImpl(); 48 _ff_service.system_configuration_complete(new SystemConfigurationImpl()); 50 51 _reg_service = new RegistrationServiceImpl(); 53 _reg_service.system_configuration_complete(new SystemConfigurationImpl()); 55 56 String entrypt = "org.objectweb.corba.runtime.ORBFactoryImpl.create_factory"; 58 _ff_service.register_service_factory(ORBService.SERVICE_ID, null, entrypt); 59 60 ORBFactory fact = (ORBFactory)getFFService().find_service_factory(ORBService.SERVICE_ID); 62 fact.add_default_initializer("org.objectweb.corba.runtime.DebugORBInitializerImpl"); 63 64 entrypt = "org.objectweb.corba.runtime.POAFactoryImpl.create_factory"; 66 _ff_service.register_service_factory(POAService.SERVICE_ID, null, entrypt); 67 68 _main_thread = new SingleORBWorker(); 70 _main_thread.startThread(); 71 72 _orb = null; 73 } 74 75 79 static public FactoryFinderService 80 getFFService() 81 { 82 return _ff_service; 83 } 84 85 static public RegistrationService 86 getRegistrationService() 87 { 88 return _reg_service; 89 } 90 91 static public MainThread 92 getMainThread() 93 { 94 return _main_thread; 95 } 96 97 static public org.omg.CORBA.ORB 98 getORB() 99 { 100 return _orb; 101 } 102 103 static public Servant 104 loadServant(RuntimeConfiguration config) 105 { 106 final String opname = "loadServant"; 107 108 String [] sids = config.service_ids; 110 String [] entrypts = config.service_entrypts; 111 112 for (int i=0;i<sids.length;i++) { 113 _ff_service.register_service_factory(sids[i], null, entrypts[i]); 114 } 115 116 String archloc = config.archive_location; 118 119 if (archloc!=null) { 121 TheClassLoader.addResource(archloc); 122 } 123 124 String entrypt = config.archive_entrypoint; 126 Object obj = TheClassLoader.newInstance(entrypt); 127 128 if (obj==null) { 130 final String msg = "FAILED (servant not created)"; 132 TheLogger.error(_class_name, opname, msg); 133 } 134 135 Servant servant = null; 137 try { 138 servant = (Servant)obj; 139 } catch (ClassCastException ex) { 140 final String msg = "FAILED (not a servant)"; 142 TheLogger.error(_class_name, opname, msg); 143 } 144 145 ORBService orbs = null; 148 SystemFactory orbfact = _ff_service.find_service_factory(ORBService.SERVICE_ID); 149 150 ORBConfiguration orbcfg = new ORBConfigurationImpl(config.orb_initializers, 152 config.value_factories, 153 config.initial_references, 154 config.stringified_initial_references); 155 156 orbs = (ORBService)orbfact.create_system_component(orbcfg); 157 158 try { 160 ORBServiceImpl orbimpl = (ORBServiceImpl)orbs; 161 _orb = orbimpl.getORB(); 162 } catch (ClassCastException ex) { 163 } 165 166 POAService poas = null; 170 SystemFactory poafact = _ff_service.find_service_factory(POAService.SERVICE_ID); 171 172 POAConfiguration poacfg = new POAConfigurationImpl(null, null, orbs); 175 poas = (POAService)poafact.create_system_component(poacfg); 176 177 ServantConfiguration scfg = new ServantConfigurationImpl(orbs, poas); 179 servant.system_configuration_complete(scfg); 180 181 byte[] oid = System.getProperty("runtime.id").getBytes(); 184 org.omg.CORBA.Object ref = poas.create_ref_with_id(oid, servant.type_id()); 185 186 poas.activate_servant_with_id(servant, oid); 188 189 RegistrationService regs = _reg_service; 191 String iorfile = System.getProperty("runtime.iorfile"); 193 if (iorfile!=null) { 194 FileRegistrationScheme filescheme = (FileRegistrationScheme)regs.get_scheme(FileRegistrationScheme.SCHEME_ID); 196 filescheme.write_ior(iorfile, ref, orbs); 197 } 198 199 String insname = System.getProperty("runtime.id"); 201 INSRegistrationScheme insscheme = (INSRegistrationScheme)regs.get_scheme(INSRegistrationScheme.SCHEME_ID); 202 insscheme.bind(insname, ref, orbs); 203 204 return servant; 205 } 206 207 static public void 208 loadMain(RuntimeConfiguration config) 209 { 210 String archloc = config.archive_location; 212 213 if (archloc!=null) { 215 TheClassLoader.addResource(archloc); 216 } 217 218 ORBService orbs = null; 220 SystemFactory orbfact = _ff_service.find_service_factory(ORBService.SERVICE_ID); 221 222 ORBConfiguration orbcfg = new ORBConfigurationImpl(config.orb_initializers, 224 config.value_factories, 225 config.initial_references, 226 config.stringified_initial_references); 227 228 orbs = (ORBService)orbfact.create_system_component(orbcfg); 229 230 String entrypt = config.archive_entrypoint; 235 Class [] argc = { ORBService.class }; 236 Object [] argv = { orbs }; 237 238 Runnable run = null; 239 try { 240 run = (Runnable )TheClassLoader.newInstance(entrypt, argc, argv); 241 } catch (ClassCastException ex) { 242 final String opname = "loadMain"; 244 final String msg = "FAILED (not a runnable)"; 245 TheLogger.error(_class_name, opname, msg); 246 } 247 248 run.run(); 249 } 250 } 251 | Popular Tags |