1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class ServerActivatorImpl 38 extends org.omg.CORBA.LocalObject 39 implements Servant, org.omg.Components.Deployment.ServerActivatorOperations 40 { 41 static private String _class_name = "ServerActivatorImpl"; 43 static final private String _type_id = org.omg.Components.Deployment.ServerActivatorHelper.id(); 44 private ORBService _orb_service; 45 private org.omg.CosNaming.NamingContext _local_ns; 46 private java.util.ArrayList _cs_refs; private int _cs_count; 48 49 public 51 ServerActivatorImpl() 52 { 53 _orb_service = null; 55 _local_ns = null; 56 _cs_refs = new java.util.ArrayList (); 57 _cs_count = 0; 58 } 59 60 64 static public Servant 65 create_servant() 66 { 67 return new ServerActivatorImpl(); 68 } 69 70 74 78 final public void 79 system_configuration_complete(SystemConfiguration cfg) 80 { 81 ServantConfiguration scfg = (ServantConfiguration)cfg; 83 _orb_service = scfg.orb_service(); 84 85 org.omg.CORBA.Object obj = null; 87 obj = _orb_service.resolve_initial_references("LocalNameService"); 88 89 if (obj==null) { 91 final String opname = "system_configuration_complete"; 93 final String msg = "FAILED (local NS not found)"; 94 TheLogger.error(_class_name, opname, msg); 95 return ; 96 } 97 98 _local_ns = org.omg.CosNaming.NamingContextHelper.narrow(obj); 99 100 String typeid = org.omg.Components.ConfigValueHelper.id(); 102 org.omg.CORBA.portable.ValueFactory fact = ConfigValueFactoryImpl.create_factory(); 103 _orb_service.register_valuefactory(new ValueFactoryImpl(typeid, fact)); 104 } 105 106 final public void 107 destroy() 108 { 109 org.omg.Components.Deployment.ComponentServer[] refs = get_component_servers(); 111 for (int i=0;i<refs.length;i++) { 112 try { 113 refs[i].remove(); 114 } catch (org.omg.Components.RemoveFailure ex) { 115 final String opname = "destroy"; 117 TheLogger.debug(_class_name, opname, "IGNORE", ex); 118 return ; 119 } 120 } 121 122 _cs_refs.clear(); 124 125 } 127 128 132 final public String 133 type_id() 134 { 135 return _type_id; 136 } 137 138 final public org.omg.PortableServer.Servant 139 as_native_servant() 140 { 141 return new org.omg.Components.Deployment.ServerActivatorPOATie(this); 142 } 143 144 148 final public org.omg.Components.Deployment.ComponentServer 149 create_component_server(org.omg.Components.ConfigValue[] config) 150 throws org.omg.Components.CreateFailure, 151 org.omg.Components.Deployment.InvalidConfiguration 152 { 153 157 final String opname = "create_component_server"; 158 String msg = null; 159 String optionstr = System.getProperty("os.option.str"); 161 String libdir = System.getProperty("ECM.install.lib.dir"); 162 String xmldir = System.getProperty("ECM.install.launcher.dir"); 163 164 String insname = "ComponentServer"+_cs_count++; 166 String targetxml = xmldir+java.io.File.separator+"corba_runtime.xml"; 167 168 String ns_ior = _orb_service.object_to_string(_local_ns); 170 org.omg.CORBA.Object obj = _orb_service.resolve_initial_references("ExtComponentInstallation"); 171 String extci_ior = _orb_service.object_to_string(obj); 172 173 String [] args = { 174 "-Darchive.location="+libdir+java.io.File.separator+"ccm_runtime_cs.jar", 175 "-Darchive.entrypoint=org.objectweb.ccm.runtime.ComponentServerImpl.create_servant", 176 "-Druntime.id="+insname, 177 "-ArchiveLocation "+libdir+java.io.File.separator+"ccm_runtime_cs.jar", 178 "-ArchiveEntrypoint org.objectweb.ccm.runtime.ComponentServerImpl.create_servant", 179 "-RuntimeId "+insname, 180 "-ORBInitRef NameService="+ns_ior, 181 "-ORBInitRef ExtComponentInstallation="+extci_ior 182 }; 183 184 org.objectweb.util.launcher.Launcher launcher = null; 186 launcher = new org.objectweb.util.launcher.Launcher(targetxml, "corba_runtime", args); 187 188 msg = "launcher started, wait on stderr/stdout"; 190 TheLogger.debug(_class_name, opname, msg); 191 java.lang.Process csprocess = launcher.getProcess(); 192 java.io.InputStream err = csprocess.getErrorStream(); 193 java.io.InputStream out = csprocess.getInputStream(); 194 java.io.BufferedInputStream berr = new java.io.BufferedInputStream (err); 195 java.io.BufferedInputStream bout = new java.io.BufferedInputStream (out); 196 try { 197 int errnum = 0; 198 int outnum = 0; 199 while (((errnum=berr.available())<=0) && 200 ((outnum=bout.available())<=0)) { 201 Thread.currentThread().sleep(500); 203 } 204 205 if (errnum>0) { 207 byte[] line = new byte[errnum]; 208 berr.read(line, 0, errnum); 209 210 msg = "(STDERR)"+new String (line); 211 TheLogger.debug(_class_name, opname, msg); 212 } 213 214 if (outnum>0) { 215 byte[] line = new byte[outnum]; 216 bout.read(line, 0, outnum); 217 218 msg = "(STDOUT)"+new String (line); 219 TheLogger.debug(_class_name, opname, msg); 220 } 221 222 new SAConsoleReader(berr,bout).start(); 224 } catch (java.lang.Exception ex) { 225 TheLogger.debug(_class_name, opname, "IGNORE", ex); 227 } 228 229 RegistrationService regs = org.objectweb.corba.runtime.Runtime.getRegistrationService(); 231 INSRegistrationScheme insscheme = (INSRegistrationScheme)regs.get_scheme(INSRegistrationScheme.SCHEME_ID); 232 obj = insscheme.lookup_in_ns(insname, _local_ns); 233 234 if (obj==null) { 236 msg = "FAILED ("+insname+" not found in local NS)"; 237 TheLogger.error(_class_name, opname, msg); 238 } 239 240 org.omg.Components.Deployment.ComponentServer cs = org.omg.Components.Deployment.ComponentServerHelper.narrow(obj); 241 242 _cs_refs.add(cs); 244 245 246 return cs; 247 } 248 249 final public void 250 remove_component_server(org.omg.Components.Deployment.ComponentServer server) 251 throws org.omg.Components.RemoveFailure 252 { 253 org.omg.Components.Deployment.ComponentServer[] refs = get_component_servers(); 255 int i=0; 256 for (;i<refs.length;i++) { 257 if (server._is_equivalent(refs[i])) { 258 _cs_refs.remove(i); 259 server.remove(); 262 263 265 break; 266 } 267 } 268 269 if (i==refs.length) { 271 throw new org.omg.Components.RemoveFailure(); 272 } 273 } 274 275 final public org.omg.Components.Deployment.ComponentServer[] 276 get_component_servers() 277 { 278 return (org.omg.Components.Deployment.ComponentServer[])_cs_refs.toArray(new org.omg.Components.Deployment.ComponentServer[0]); 279 } 280 } 281 282 class SAConsoleReader 286 extends java.lang.Thread 287 { 288 static private String _class_name = "SAConsoleReader"; 290 private java.io.BufferedInputStream _err; 291 private java.io.BufferedInputStream _out; 292 private boolean _running; 293 294 public 296 SAConsoleReader(java.io.BufferedInputStream out, 297 java.io.BufferedInputStream err) 298 { 299 _err = err; 301 _out = out; 302 _running = false; 303 } 304 305 309 final public void 310 stopReader() 311 { 312 _running = false; 313 } 314 315 319 final public void 320 run() 321 { 322 final String opname = "run"; 323 _running = true; 324 325 while (_running) { 326 try { 327 int errnum = 0; 328 int outnum = 0; 329 while (((errnum=berr.available())<=0) && 330 ((outnum=bout.available())<=0)) { 331 Thread.currentThread().sleep(100); 333 } 334 335 if (errnum>0) { 337 byte[] line = new byte[errnum]; 338 berr.read(line, 0, errnum); 339 340 msg = "(STDERR)"+new String (line); 341 TheLogger.debug(_class_name, opname, msg); 342 } 343 344 if (outnum>0) { 345 byte[] line = new byte[outnum]; 346 bout.read(line, 0, outnum); 347 348 msg = "(STDOUT)"+new String (line); 349 TheLogger.debug(_class_name, opname, msg); 350 } 351 352 } catch (java.lang.Exception ex) { 353 TheLogger.debug(_class_name, opname, "IGNORE", ex); 355 } 356 } 357 } 358 } 359 | Popular Tags |