1 31 package org.objectweb.proactive.core.descriptor.xml; 32 33 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 34 import org.objectweb.proactive.core.descriptor.data.VirtualMachine; 35 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 36 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl; 37 import org.objectweb.proactive.core.descriptor.data.VirtualNodeLookup; 38 import org.objectweb.proactive.core.util.UrlBuilder; 39 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller; 40 import org.objectweb.proactive.core.xml.handler.CollectionUnmarshaller; 41 import org.objectweb.proactive.core.xml.handler.PassiveCompositeUnmarshaller; 42 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 43 import org.objectweb.proactive.core.xml.io.Attributes; 44 45 46 53 class DeploymentHandler extends PassiveCompositeUnmarshaller 54 implements ProActiveDescriptorConstants { 55 private ProActiveDescriptor proActiveDescriptor; 56 57 public DeploymentHandler(ProActiveDescriptor proActiveDescriptor) { 64 super(false); 65 this.proActiveDescriptor = proActiveDescriptor; 66 this.addHandler(REGISTER_TAG, new RegisterHandler()); 67 this.addHandler(LOOKUP_TAG, new LookupHandler()); 68 { 69 PassiveCompositeUnmarshaller ch = new PassiveCompositeUnmarshaller(); 70 ch.addHandler(MAP_TAG, new MapHandler()); 71 this.addHandler(MAPPING_TAG, ch); 72 } 73 { 74 PassiveCompositeUnmarshaller ch = new PassiveCompositeUnmarshaller(); 75 ch.addHandler(JVM_TAG, new JVMHandler()); 76 this.addHandler(JVMS_TAG, ch); 77 } 78 } 79 80 private class RegisterHandler extends BasicUnmarshaller { 93 private RegisterHandler() { 94 } 95 96 public void startContextElement(String name, Attributes attributes) 97 throws org.xml.sax.SAXException { 98 String vn = attributes.getValue("virtualNode"); 99 if (!checkNonEmpty(vn)) { 100 throw new org.xml.sax.SAXException ( 101 "register Tag without any virtualnode defined"); 102 } 103 String protocol = attributes.getValue("protocol"); 104 if (!checkNonEmpty(protocol)) { 105 throw new org.xml.sax.SAXException ( 106 "lookup Tag without any protocol defined"); 107 } 108 protocol = UrlBuilder.checkProtocol(protocol); 109 VirtualNodeImpl vnImpl = (VirtualNodeImpl) proActiveDescriptor.createVirtualNode(vn, 110 false); 111 112 vnImpl.setRegistrationProtocol(protocol); 115 } 116 } 117 118 private class LookupHandler extends BasicUnmarshaller { 119 private LookupHandler() { 120 } 121 122 public void startContextElement(String name, Attributes attributes) 123 throws org.xml.sax.SAXException { 124 String vnLookup = attributes.getValue("virtualNode"); 125 if (!checkNonEmpty(vnLookup)) { 126 throw new org.xml.sax.SAXException ( 127 "lookup Tag without any virtualnode defined"); 128 } 129 String protocol = attributes.getValue("protocol"); 130 if (!checkNonEmpty(protocol)) { 131 throw new org.xml.sax.SAXException ( 132 "lookup Tag without any protocol defined"); 133 } 134 String host = attributes.getValue("host"); 135 if (!checkNonEmpty(host) && protocol.equals("rmi")) { 136 throw new org.xml.sax.SAXException ( 137 "within a lookup tag attribute host must be defined for rmi protocol"); 138 } 139 protocol = UrlBuilder.checkProtocol(protocol); 140 String url = UrlBuilder.buildUrl(host, vnLookup, protocol); 141 VirtualNodeLookup vn = (VirtualNodeLookup) proActiveDescriptor.createVirtualNode(vnLookup, 142 true); 143 144 String port = attributes.getValue("port"); 146 147 if (checkNonEmpty(port)) { 149 if (protocol.equals("jini:")) { 150 throw new org.xml.sax.SAXException ( 151 "For a jini lookup, no port number should be specified"); 152 } 153 url = UrlBuilder.buildUrl(host, vnLookup, protocol, 154 new Integer (port).intValue()); 155 vn.setLookupInformations(url, protocol, 156 new Integer (port).intValue()); 157 } else { 160 vn.setLookupInformations(url, protocol, 1099); 161 } 162 } 163 } 164 165 168 private class MapHandler extends PassiveCompositeUnmarshaller { 169 VirtualNode vn; 170 171 private MapHandler() { 172 this.addHandler(JVMSET_TAG, new JvmSetHandler()); 176 } 177 178 public void startContextElement(String name, Attributes attributes) 179 throws org.xml.sax.SAXException { 180 String vnName = attributes.getValue("virtualNode"); 182 if (!checkNonEmpty(vnName)) { 183 throw new org.xml.sax.SAXException ( 184 "mapping defined without specifying virtual node"); 185 } 186 vn = proActiveDescriptor.createVirtualNode(vnName, false); 187 } 188 189 protected void notifyEndActiveHandler(String name, 190 UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException { 191 if (name.equals(JVMSET_TAG)) { 192 String [] vmNames = (String []) activeHandler.getResultObject(); 193 194 if ((vmNames.length > 1) && (vn.getProperty() != null) && 196 (vn.getProperty().equals("unique") || 197 vn.getProperty().equals("unique_singleAO"))) { 198 throw new org.xml.sax.SAXException ( 199 "a set of virtual machine is defined for a virtualNode that is unique"); 200 } 201 if (vmNames.length > 0) { 202 for (int i = 0; i < vmNames.length; i++) { 203 VirtualMachine vm = proActiveDescriptor.createVirtualMachine(vmNames[i]); 204 205 if (vm.getCreatorId() == null) { 206 vm.setCreatorId(vn.getName()); 207 } 208 vn.addVirtualMachine(vm); 209 } 210 } 211 } 212 } 213 214 private class SingleValueUnmarshaller extends BasicUnmarshaller { 218 public void readValue(String value) throws org.xml.sax.SAXException { 219 setResultObject(value); 220 } 221 } 222 224 private class JvmSetHandler extends CollectionUnmarshaller { 225 protected JvmSetHandler() { 226 super(String .class); 227 this.addHandler(VMNAME_TAG, new VmNameHandler()); 228 this.addHandler(CURRENTJVM_TAG, new CurrentJvmHandler()); 229 } 230 231 protected void notifyEndActiveHandler(String name, 232 UnmarshallerHandler activeHandler) 233 throws org.xml.sax.SAXException { 234 if (name.equals(CURRENTJVM_TAG)) { 235 String protocol = (String ) activeHandler.getResultObject(); 236 vn.createNodeOnCurrentJvm(protocol); 237 } else { 238 super.notifyEndActiveHandler(name, activeHandler); 239 } 240 } 241 } 242 244 private class VmNameHandler extends BasicUnmarshaller { 245 private VmNameHandler() { 246 } 247 248 public void startContextElement(String name, Attributes attributes) 249 throws org.xml.sax.SAXException { 250 String vmName = attributes.getValue("value"); 251 if (checkNonEmpty(vmName)) { 252 setResultObject(vmName); 253 } else { 254 throw new org.xml.sax.SAXException ( 255 "The name of the Jvm cannot be set to an empty string"); 256 } 257 } 258 } 259 261 private class CurrentJvmHandler extends BasicUnmarshaller { 262 private CurrentJvmHandler() { 263 } 264 265 public void startContextElement(String name, Attributes attributes) 266 throws org.xml.sax.SAXException { 267 String protocol = attributes.getValue("protocol"); 268 setResultObject(protocol); 269 } 270 } 271 } 273 275 278 private class JVMHandler extends PassiveCompositeUnmarshaller { 279 private VirtualMachine currentVM; 280 281 private JVMHandler() { 282 this.addHandler(CREATION_PROCESS_TAG, new CreationHandler()); 284 } 285 286 public void startContextElement(String name, Attributes attributes) 287 throws org.xml.sax.SAXException { 288 String vmName = attributes.getValue("name"); 290 if (!checkNonEmpty(vmName)) { 291 throw new org.xml.sax.SAXException ( 292 "VirtualMachine defined without name"); 293 } 294 currentVM = proActiveDescriptor.createVirtualMachine(vmName); 295 String nodeNumber = attributes.getValue("nodeNumber"); 296 try { 297 if (checkNonEmpty(nodeNumber)) { 298 currentVM.setHostsNumber(nodeNumber); 299 } 300 } catch (java.io.IOException e) { 301 throw new org.xml.sax.SAXException (e); 302 } 303 } 304 305 308 325 327 330 private class CreationHandler extends PassiveCompositeUnmarshaller { 331 private CreationHandler() { 332 this.addHandler(PROCESS_REFERENCE_TAG, 333 new ProcessReferenceHandler()); 334 } 335 336 protected void notifyEndActiveHandler(String name, 337 UnmarshallerHandler activeHandler) 338 throws org.xml.sax.SAXException { 339 Object o = activeHandler.getResultObject(); 340 if (o == null) { 341 return; 342 } 343 if (o instanceof String ) { 344 proActiveDescriptor.registerProcess(currentVM, (String ) o); 346 } 347 } 348 } 349 350 } 352 353 } 355 | Popular Tags |