1 26 27 28 package org.objectweb.openccm.Deployment; 29 30 import org.objectweb.openccm.corba.*; 31 36 public class ServerActivatorImpl extends org.omg.Components.Deployment.ServerActivatorPOA 37 { 38 39 private int last_cs_num; 40 41 42 private java.util.Hashtable c_servers; 43 44 45 private java.util.Hashtable process; 46 47 48 private String localName ; 49 50 51 private String openCCMHomeDir ; 52 53 54 private boolean PDA; 55 56 63 public ServerActivatorImpl(String localName, String openCCMHomeDir){ 64 last_cs_num=0; 65 c_servers= new java.util.Hashtable (); 66 process=new java.util.Hashtable (); 67 this.localName=localName; 68 this.openCCMHomeDir=openCCMHomeDir; 69 this.PDA=false; 70 } 71 72 75 public ServerActivatorImpl(String localName, String openCCMHomeDir,boolean PDA){ 76 last_cs_num=0; 77 c_servers= new java.util.Hashtable (); 78 process=new java.util.Hashtable (); 79 this.localName=localName; 80 this.openCCMHomeDir=openCCMHomeDir; 81 this.PDA=PDA; 82 } 83 84 92 public org.omg.Components.Deployment.ComponentServer 93 create_component_server(org.omg.Components.ConfigValue[] config) 94 throws org.omg.Components.CreateFailure, org.omg.Components.Deployment.InvalidConfiguration 95 { 96 97 org.omg.Components.Deployment.ComponentServer serverRef =null; 98 try{ 99 102 103 String server_name="ComponentServer"+last_cs_num++; 105 106 if(!PDA){ 107 String targetToLaunch =openCCMHomeDir+"/xml/launcher/JCS.xml" ; 109 String args []= {server_name,localName,"-ORBInitRef NameService="+TheORB.getORB() 111 .object_to_string(TheORB.resolve_initial_reference("NameService"))}; 112 org.objectweb.util.launcher.Launcher launcher= 114 new org.objectweb.util.launcher.Launcher(targetToLaunch,"jcs_interne",args); 115 116 java.io.BufferedReader br = new java.io.BufferedReader ( 117 new java.io.InputStreamReader ( 118 launcher.getProcess().getInputStream())); 119 120 br.readLine(); 122 123 serverRef=org.omg.Components.Deployment. 126 ComponentServerHelper.narrow(TheORB.getORB().string_to_object(br.readLine())); 127 128 process.put(server_name+localName,launcher.getProcess()); 130 System.out.println("Component Server ["+server_name+localName+"] started"); 132 } 133 else{ 134 org.objectweb.openccm.Components.ConfigValueImpl[] config1= 136 new org.objectweb.openccm.Components.ConfigValueImpl[1]; 137 138 org.omg.CORBA.Any any= org.objectweb.openccm.corba.TheORB.getORB().create_any(); 139 140 any.insert_string(server_name+localName); 142 config1[0]= new org.objectweb.openccm.Components.ConfigValueImpl("ServerName",any); 143 ComponentServerImpl csi = new ComponentServerImpl(config1); 145 org.omg.CORBA.Object ref = 147 csi._this_object(org.objectweb.openccm.corba.TheORB.getORB()); 148 serverRef=org.omg.Components.Deployment.ComponentServerHelper.narrow(ref); 150 org.objectweb.openccm.corba.NamingContext ns = 152 org.objectweb.openccm.corba.TheNameService.getNamingContext(); 153 154 ns.rebind(server_name+localName, serverRef); 156 } 157 158 c_servers.put(server_name+localName,serverRef); 160 return serverRef; 162 } 163 catch(Exception e){e.printStackTrace();} 164 165 return serverRef; 167 } 168 169 175 public void remove_component_server(org.omg.Components.Deployment.ComponentServer server) 176 throws org.omg.Components.RemoveFailure{ 177 178 org.omg.Components.ConfigValue[] config =server.configuration(); 180 if(!config[0].name.equals("ServerName")) 182 throw new org.omg.Components.RemoveFailure(); 183 184 if(!c_servers.containsKey(config[0].value.extract_string())) 186 throw new org.omg.Components.RemoveFailure(); 187 188 try{ 189 server.remove(); 191 if(!PDA){ 192 Process p=(Process )process.remove(config[0].value.extract_string()); 194 c_servers.remove(config[0].value.extract_string()); 196 p.destroy(); 198 } 199 } 200 catch(Exception e) 201 { 202 e.printStackTrace(); 203 System.out.println(e.getMessage()); 204 } 205 } 206 207 208 212 public void remove_component_server_interne(org.omg.Components.Deployment.ComponentServer server) 213 throws org.omg.Components.RemoveFailure 214 { 215 org.omg.Components.ConfigValue[] config =server.configuration(); 217 if(!config[0].name.equals("ServerName")) 219 throw new org.omg.Components.RemoveFailure(); 220 if(!c_servers.containsKey(config[0].value.extract_string())) 222 throw new org.omg.Components.RemoveFailure(); 223 224 try{ 225 c_servers.remove(config[0].value.extract_string()); 227 228 if(!PDA){ 229 Process p=(Process )process.remove(config[0].value.extract_string()); 231 p.destroy(); 233 } 234 } 235 catch(Exception e){e.printStackTrace(); 236 System.out.println(e.getMessage()); 237 } 238 239 } 240 241 245 public org.omg.Components.Deployment.ComponentServer[] get_component_servers(){ 246 return (org.omg.Components.Deployment.ComponentServer[]) 247 c_servers.values().toArray(new org.omg.Components.Deployment. 248 ComponentServer[c_servers.size()]); 249 } 250 251 } 252 | Popular Tags |