00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.descriptor.xml;
00032
00033 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00034 import org.objectweb.proactive.core.descriptor.data.VirtualMachine;
00035 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00036 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
00037 import org.objectweb.proactive.core.descriptor.data.VirtualNodeLookup;
00038 import org.objectweb.proactive.core.util.UrlBuilder;
00039 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller;
00040 import org.objectweb.proactive.core.xml.handler.CollectionUnmarshaller;
00041 import org.objectweb.proactive.core.xml.handler.PassiveCompositeUnmarshaller;
00042 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
00043 import org.objectweb.proactive.core.xml.io.Attributes;
00044
00045
00053 class DeploymentHandler extends PassiveCompositeUnmarshaller
00054 implements ProActiveDescriptorConstants {
00055 private ProActiveDescriptor proActiveDescriptor;
00056 private boolean activate = true;
00057
00058
00059
00060
00061
00062
00063
00064 public DeploymentHandler(ProActiveDescriptor proActiveDescriptor) {
00065 super(false);
00066 this.proActiveDescriptor = proActiveDescriptor;
00067 this.addHandler(REGISTER_TAG, new RegisterHandler());
00068 this.addHandler(LOOKUP_TAG, new LookupHandler());
00069
00070 {
00071 PassiveCompositeUnmarshaller ch = new PassiveCompositeUnmarshaller();
00072 ch.addHandler(MAP_TAG, new MapHandler());
00073 this.addHandler(MAPPING_TAG, ch);
00074 }
00075
00076 {
00077 PassiveCompositeUnmarshaller ch = new PassiveCompositeUnmarshaller();
00078 ch.addHandler(JVM_TAG, new JVMHandler());
00079 this.addHandler(JVMS_TAG, ch);
00080 }
00081 }
00082
00090 public DeploymentHandler(ProActiveDescriptor proActiveDescriptor,
00091 boolean activate) {
00092 super(false);
00093 this.activate = activate;
00094 this.proActiveDescriptor = proActiveDescriptor;
00095 this.addHandler(REGISTER_TAG, new RegisterHandler());
00096 this.addHandler(LOOKUP_TAG, new LookupHandler());
00097
00098 {
00099 PassiveCompositeUnmarshaller ch = new PassiveCompositeUnmarshaller();
00100 ch.addHandler(MAP_TAG, new MapHandler());
00101 this.addHandler(MAPPING_TAG, ch);
00102 }
00103
00104 {
00105 PassiveCompositeUnmarshaller ch = new PassiveCompositeUnmarshaller();
00106 ch.addHandler(JVM_TAG, new JVMHandler());
00107 this.addHandler(JVMS_TAG, ch);
00108 }
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 private class RegisterHandler extends BasicUnmarshaller {
00124 private RegisterHandler() {
00125 }
00126
00127 public void startContextElement(String name, Attributes attributes)
00128 throws org.xml.sax.SAXException {
00129 String vn = attributes.getValue("virtualNode");
00130
00131 if (!checkNonEmpty(vn)) {
00132 throw new org.xml.sax.SAXException(
00133 "register Tag without any virtualnode defined");
00134 }
00135
00136 String protocol = attributes.getValue("protocol");
00137
00138 if (!checkNonEmpty(protocol)) {
00139 protocol = System.getProperty(
00140 "proactive.communication.protocol");
00141 }
00142
00143 protocol = UrlBuilder.checkProtocol(protocol);
00144
00145 VirtualNodeImpl vnImpl = (VirtualNodeImpl) proActiveDescriptor.createVirtualNode(vn,
00146 false);
00147
00148
00149
00150 vnImpl.setRegistrationProtocol(protocol);
00151 }
00152 }
00153
00154 private class LookupHandler extends BasicUnmarshaller {
00155 private LookupHandler() {
00156 }
00157
00158 public void startContextElement(String name, Attributes attributes)
00159 throws org.xml.sax.SAXException {
00160 String vnLookup = attributes.getValue("virtualNode");
00161
00162 if (!checkNonEmpty(vnLookup)) {
00163 throw new org.xml.sax.SAXException(
00164 "lookup Tag without any virtualnode defined");
00165 }
00166
00167 String protocol = attributes.getValue("protocol");
00168
00169 if (!checkNonEmpty(protocol)) {
00170 throw new org.xml.sax.SAXException(
00171 "lookup Tag without any protocol defined");
00172 }
00173
00174 String host = attributes.getValue("host");
00175
00176 if (!checkNonEmpty(host) && protocol.equals("rmi")) {
00177 throw new org.xml.sax.SAXException(
00178 "within a lookup tag attribute host must be defined for rmi protocol");
00179 }
00180
00181 protocol = UrlBuilder.checkProtocol(protocol);
00182
00183
00184 VirtualNodeLookup vn = (VirtualNodeLookup) proActiveDescriptor.createVirtualNode(vnLookup,
00185 true);
00186
00187
00188 String port = attributes.getValue("port");
00189
00190
00191 if (checkNonEmpty(port)) {
00192 if (protocol.equals("jini:")) {
00193 throw new org.xml.sax.SAXException(
00194 "For a jini lookup, no port number should be specified");
00195 }
00196
00197 vn.setLookupInformations(host, protocol, port);
00198
00199
00200
00201 } else {
00202 vn.setLookupInformations(host, protocol, "1099");
00203 }
00204 }
00205 }
00206
00210 private class MapHandler extends PassiveCompositeUnmarshaller {
00211 VirtualNode vn;
00212
00213 private MapHandler() {
00214
00215
00216
00217 this.addHandler(JVMSET_TAG, new JvmSetHandler());
00218 }
00219
00220 public void startContextElement(String name, Attributes attributes)
00221 throws org.xml.sax.SAXException {
00222
00223 String vnName = attributes.getValue("virtualNode");
00224
00225 if (!checkNonEmpty(vnName)) {
00226 throw new org.xml.sax.SAXException(
00227 "mapping defined without specifying virtual node");
00228 }
00229
00230 vn = proActiveDescriptor.createVirtualNode(vnName, false);
00231 }
00232
00233 protected void notifyEndActiveHandler(String name,
00234 UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
00235 if (name.equals(JVMSET_TAG)) {
00236 String[] vmNames = (String[]) activeHandler.getResultObject();
00237
00238
00239 if ((vmNames.length > 1) && (vn.getProperty() != null) &&
00240 (vn.getProperty().equals("unique") ||
00241 vn.getProperty().equals("unique_singleAO"))) {
00242 throw new org.xml.sax.SAXException(
00243 "a set of virtual machine is defined for a virtualNode that is unique");
00244 }
00245
00246 if (vmNames.length > 0) {
00247 for (int i = 0; i < vmNames.length; i++) {
00248 VirtualMachine vm = proActiveDescriptor.createVirtualMachine(vmNames[i]);
00249
00250 vn.addVirtualMachine(vm);
00251 }
00252 }
00253 }
00254 }
00255
00256
00257
00258
00259 private class JvmSetHandler extends CollectionUnmarshaller {
00260 protected JvmSetHandler() {
00261 super(String.class);
00262 this.addHandler(VMNAME_TAG, new VmNameHandler());
00263 this.addHandler(CURRENTJVM_TAG, new CurrentJvmHandler());
00264 }
00265
00266 protected void notifyEndActiveHandler(String name,
00267 UnmarshallerHandler activeHandler)
00268 throws org.xml.sax.SAXException {
00269 if (name.equals(CURRENTJVM_TAG)) {
00270
00271
00272
00273 if (activate) {
00274 String protocol = (String) activeHandler.getResultObject();
00275
00276 if (!checkNonEmpty(protocol)) {
00277 protocol = System.getProperty(
00278 "proactive.communication.protocol");
00279 }
00280
00281 vn.createNodeOnCurrentJvm(protocol);
00282 } else {
00283 throw new org.xml.sax.SAXException(
00284 "The use of the currentJVM tag is banned");
00285 }
00286 } else {
00287 super.notifyEndActiveHandler(name, activeHandler);
00288 }
00289 }
00290
00291
00292 private class VmNameHandler extends BasicUnmarshaller {
00293 private VmNameHandler() {
00294 }
00295
00296 public void startContextElement(String name,
00297 Attributes attributes) throws org.xml.sax.SAXException {
00298 String vmName = attributes.getValue("value");
00299
00300 if (checkNonEmpty(vmName)) {
00301 setResultObject(vmName);
00302 } else {
00303 throw new org.xml.sax.SAXException(
00304 "The name of the Jvm cannot be set to an empty string");
00305 }
00306 }
00307 }
00308
00309 private class CurrentJvmHandler extends BasicUnmarshaller {
00310 private CurrentJvmHandler() {
00311 }
00312
00313 public void startContextElement(String name,
00314 Attributes attributes) throws org.xml.sax.SAXException {
00315 String protocol = attributes.getValue("protocol");
00316 setResultObject(protocol);
00317 }
00318 }
00319 }
00320 }
00321
00322
00323
00327 private class JVMHandler extends PassiveCompositeUnmarshaller {
00328 private VirtualMachine currentVM;
00329
00330 private JVMHandler() {
00331 this.addHandler(ACQUISITION_TAG, new AcquisitionHandler());
00332 this.addHandler(CREATION_PROCESS_TAG, new CreationHandler());
00333 }
00334
00335 public void startContextElement(String name, Attributes attributes)
00336 throws org.xml.sax.SAXException {
00337
00338 String vmName = attributes.getValue("name");
00339
00340 if (!checkNonEmpty(vmName)) {
00341 throw new org.xml.sax.SAXException(
00342 "VirtualMachine defined without name");
00343 }
00344
00345 currentVM = proActiveDescriptor.createVirtualMachine(vmName);
00346
00347 String nodeNumber = attributes.getValue("askedNodes");
00348
00349 try {
00350 if (checkNonEmpty(nodeNumber)) {
00351 currentVM.setNbNodes(nodeNumber);
00352 }
00353 } catch (java.io.IOException e) {
00354 throw new org.xml.sax.SAXException(e);
00355 }
00356 }
00357
00361 private class AcquisitionHandler extends PassiveCompositeUnmarshaller {
00362 private AcquisitionHandler() {
00363 this.addHandler(SERVICE_REFERENCE_TAG,
00364 new ProcessReferenceHandler());
00365 }
00366
00367 protected void notifyEndActiveHandler(String name,
00368 UnmarshallerHandler activeHandler)
00369 throws org.xml.sax.SAXException {
00370 Object o = activeHandler.getResultObject();
00371
00372 if (o == null) {
00373 return;
00374 }
00375
00376 proActiveDescriptor.registerService(currentVM, (String) o);
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00403
00404 }
00405
00406
00407
00411 private class CreationHandler extends PassiveCompositeUnmarshaller {
00412 private CreationHandler() {
00413 this.addHandler(PROCESS_REFERENCE_TAG,
00414 new ProcessReferenceHandler());
00415 }
00416
00417 protected void notifyEndActiveHandler(String name,
00418 UnmarshallerHandler activeHandler)
00419 throws org.xml.sax.SAXException {
00420 Object o = activeHandler.getResultObject();
00421
00422 if (o == null) {
00423 return;
00424 }
00425
00426 if (o instanceof String) {
00427
00428 proActiveDescriptor.registerProcess(currentVM, (String) o);
00429 }
00430 }
00431 }
00432
00433
00434 }
00435
00436
00437 }