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.services.FaultToleranceService;
00035 import org.objectweb.proactive.core.descriptor.services.P2PDescriptorService;
00036 import org.objectweb.proactive.core.descriptor.services.RMIRegistryLookupService;
00037 import org.objectweb.proactive.core.descriptor.services.SchedulerLookupService;
00038 import org.objectweb.proactive.core.descriptor.services.UniversalService;
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.SingleValueUnmarshaller;
00043 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
00044 import org.objectweb.proactive.core.xml.io.Attributes;
00045 import org.objectweb.proactive.scheduler.GenericJob;
00046 import org.objectweb.proactive.scheduler.Scheduler;
00047 import org.xml.sax.SAXException;
00048
00049
00050 public class ServiceDefinitionHandler extends PassiveCompositeUnmarshaller
00051 implements ProActiveDescriptorConstants {
00052 ProActiveDescriptor pad;
00053 Scheduler scheduler;
00054 protected String serviceId;
00055 private String jobId;
00056
00057 public ServiceDefinitionHandler(ProActiveDescriptor pad) {
00058 super(false);
00059 this.pad = pad;
00060 this.addHandler(RMI_LOOKUP_TAG, new RMILookupHandler());
00061 this.addHandler(FT_CONFIG_TAG, new FaultToleranceHandler());
00062 this.addHandler(P2P_SERVICE_TAG, new P2PServiceHandler());
00063 this.addHandler(PROACTIVE_SCHEDULER_TAG, new ProActiveSchedulerHandler());
00064 }
00065
00066 public ServiceDefinitionHandler(Scheduler scheduler, String jobId,
00067 ProActiveDescriptor pad) {
00068 super(false);
00069 this.pad = pad;
00070 this.scheduler = scheduler;
00071 this.jobId = jobId;
00072 this.addHandler(RMI_LOOKUP_TAG, new RMILookupHandler());
00073 this.addHandler(FT_CONFIG_TAG, new FaultToleranceHandler());
00074 this.addHandler(P2P_SERVICE_TAG, new P2PServiceHandler());
00075 this.addHandler(PROACTIVE_SCHEDULER_TAG, new ProActiveSchedulerHandler());
00076 }
00077
00078
00079
00080
00081 protected void notifyEndActiveHandler(String name,
00082 UnmarshallerHandler activeHandler) throws SAXException {
00083 UniversalService service = (UniversalService) activeHandler.getResultObject();
00084 pad.addService(serviceId, service);
00085 }
00086
00087
00088
00089
00090 public void startContextElement(String name, Attributes attributes)
00091 throws SAXException {
00092 this.serviceId = attributes.getValue("id");
00093 }
00094
00095 protected class RMILookupHandler extends BasicUnmarshaller {
00096 public RMILookupHandler() {
00097 }
00098
00099 public void startContextElement(String name, Attributes attributes)
00100 throws org.xml.sax.SAXException {
00101 String lookupUrl = attributes.getValue("url");
00102 RMIRegistryLookupService rmiService = new RMIRegistryLookupService(lookupUrl);
00103 setResultObject(rmiService);
00104 }
00105 }
00106
00107 protected class ProActiveSchedulerHandler
00108 extends PassiveCompositeUnmarshaller {
00109 protected SchedulerLookupService schedulerLookupService;
00110
00111 public ProActiveSchedulerHandler() {
00112 super(false);
00113 }
00114
00115 public void startContextElement(String name, Attributes attributes)
00116 throws org.xml.sax.SAXException {
00117 String schedulerUrl = attributes.getValue("schedulerUrl");
00118 schedulerLookupService = new SchedulerLookupService(schedulerUrl);
00119
00120 String nbOfNodes = attributes.getValue("numberOfNodes");
00121
00122 if (!checkNonEmpty(nbOfNodes)) {
00123 throw new org.xml.sax.SAXException(
00124 "ProActiveScheduler Tag without any numberOfNodes defined");
00125 }
00126
00127 schedulerLookupService.setNodeNumber(Integer.parseInt(nbOfNodes));
00128
00129 if (scheduler != null) {
00130 String jvmParam = attributes.getValue("jvmParameters");
00131 GenericJob job = scheduler.getTmpJob(jobId);
00132 if (checkNonEmpty(nbOfNodes)) {
00133 job.setJVMParameters(jvmParam);
00134 }
00135
00136 String minNumberOfNodes = attributes.getValue(
00137 "minNumberOfNodes");
00138 if (checkNonEmpty(minNumberOfNodes)) {
00139 schedulerLookupService.setMinNodeNumber(Integer.parseInt(
00140 minNumberOfNodes));
00141 } else {
00142 schedulerLookupService.setMinNodeNumber(Integer.parseInt(
00143 nbOfNodes));
00144 }
00145 }
00146 }
00147
00148 public Object getResultObject() throws org.xml.sax.SAXException {
00149 return schedulerLookupService;
00150 }
00151 }
00152
00153 protected class P2PServiceHandler extends PassiveCompositeUnmarshaller {
00154 protected P2PDescriptorService p2pDescriptorService;
00155
00156 public P2PServiceHandler() {
00157 super(false);
00158 CollectionUnmarshaller ch = new CollectionUnmarshaller(String.class);
00159 ch.addHandler(PEER_TAG, new SingleValueUnmarshaller());
00160 this.addHandler(PEERS_SET_TAG, ch);
00161 }
00162
00163 public void startContextElement(String name, Attributes attributes)
00164 throws org.xml.sax.SAXException {
00165 p2pDescriptorService = new P2PDescriptorService();
00166 String askedNodes = attributes.getValue("nodesAsked");
00167 if (checkNonEmpty(askedNodes)) {
00168 if (askedNodes.equals("MAX")) {
00169 p2pDescriptorService.setNodeNumberToMAX();
00170 } else {
00171 p2pDescriptorService.setNodeNumber(Integer.parseInt(
00172 askedNodes));
00173 }
00174 }
00175
00176 String acq = attributes.getValue("acq");
00177 if (checkNonEmpty(acq)) {
00178 p2pDescriptorService.setAcq(acq);
00179 }
00180
00181 String port = attributes.getValue("port");
00182 if (checkNonEmpty(port)) {
00183 p2pDescriptorService.setPort(port);
00184 }
00185
00186 String noa = attributes.getValue("NOA");
00187 if (checkNonEmpty(noa)) {
00188 p2pDescriptorService.setNoa(noa);
00189 }
00190
00191 String ttu = attributes.getValue("TTU");
00192 if (checkNonEmpty(ttu)) {
00193 p2pDescriptorService.setTtu(ttu);
00194 }
00195
00196 String ttl = attributes.getValue("TTL");
00197 if (checkNonEmpty(ttl)) {
00198 p2pDescriptorService.setTtl(ttl);
00199 }
00200
00201 String multi_proc_nodes = attributes.getValue("multi_proc_nodes");
00202 if (checkNonEmpty(multi_proc_nodes)) {
00203 p2pDescriptorService.setMultiProcNodes(multi_proc_nodes);
00204 }
00205
00206 String xml_path = attributes.getValue("xml_path");
00207 if (checkNonEmpty(xml_path)) {
00208 p2pDescriptorService.setXmlPath(xml_path);
00209 }
00210
00211 String node_family_regexp = attributes.getValue(
00212 "node_family_regexp");
00213 if (checkNonEmpty(node_family_regexp)) {
00214 p2pDescriptorService.setNodeFamilyRegexp(node_family_regexp);
00215 }
00216 }
00217
00218 protected void notifyEndActiveHandler(String name,
00219 UnmarshallerHandler activeHandler) throws SAXException {
00220 String[] peerList = (String[]) activeHandler.getResultObject();
00221 p2pDescriptorService.setPeerList(peerList);
00222 }
00223
00224 public Object getResultObject() throws org.xml.sax.SAXException {
00225 return p2pDescriptorService;
00226 }
00227 }
00228
00229 protected class FaultToleranceHandler extends PassiveCompositeUnmarshaller {
00230 protected FaultToleranceService ftService;
00231
00232 public FaultToleranceHandler() {
00233 FTConfigHandler ftch = new FTConfigHandler();
00234 this.addHandler(FT_CKPTSERVER_TAG, ftch);
00235 this.addHandler(FT_RECPROCESS_TAG, ftch);
00236 this.addHandler(FT_LOCSERVER_TAG, ftch);
00237 this.addHandler(FT_RESSERVER_TAG, ftch);
00238 this.addHandler(FT_GLOBALSERVER_TAG, ftch);
00239 this.addHandler(FT_TTCVALUE_TAG, ftch);
00240 this.addHandler(FT_PROTO_TAG, ftch);
00241 }
00242
00243 public void startContextElement(String name, Attributes attributes)
00244 throws org.xml.sax.SAXException {
00245 this.ftService = new FaultToleranceService();
00246 }
00247
00248 public Object getResultObject() throws org.xml.sax.SAXException {
00249 return this.ftService;
00250 }
00251
00252 protected class FTConfigHandler extends BasicUnmarshaller {
00253 public void startContextElement(String name, Attributes attributes)
00254 throws org.xml.sax.SAXException {
00255 if (FT_RECPROCESS_TAG.equals(name)) {
00256 FaultToleranceHandler.this.ftService.setRecoveryProcessURL(attributes.getValue(
00257 "url"));
00258 } else if (FT_LOCSERVER_TAG.equals(name)) {
00259 FaultToleranceHandler.this.ftService.setLocationServerURL(attributes.getValue(
00260 "url"));
00261 } else if (FT_CKPTSERVER_TAG.equals(name)) {
00262 FaultToleranceHandler.this.ftService.setCheckpointServerURL(attributes.getValue(
00263 "url"));
00264 } else if (FT_RESSERVER_TAG.equals(name)) {
00265 FaultToleranceHandler.this.ftService.setAttachedResourceServer(attributes.getValue(
00266 "url"));
00267 } else if (FT_TTCVALUE_TAG.equals(name)) {
00268 FaultToleranceHandler.this.ftService.setTtcValue(attributes.getValue(
00269 "value"));
00270 } else if (FT_GLOBALSERVER_TAG.equals(name)) {
00271 FaultToleranceHandler.this.ftService.setGlobalServerURL(attributes.getValue(
00272 "url"));
00273 } else if (FT_PROTO_TAG.equals(name)) {
00274 FaultToleranceHandler.this.ftService.setProtocolType(attributes.getValue(
00275 "type"));
00276 }
00277 }
00278 }
00279 }
00280 }