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.services;
00032
00033 import java.util.Vector;
00034
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.proactive.core.ProActiveException;
00037 import org.objectweb.proactive.core.node.Node;
00038 import org.objectweb.proactive.core.node.NodeFactory;
00039 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
00040 import org.objectweb.proactive.core.util.log.Loggers;
00041 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00042 import org.objectweb.proactive.p2p.service.P2PService;
00043 import org.objectweb.proactive.p2p.service.StartP2PService;
00044 import org.objectweb.proactive.p2p.service.util.P2PConstants;
00045
00046
00054 public class P2PDescriptorService implements UniversalService, P2PConstants {
00055 private static final Logger logger = ProActiveLogger.getLogger(Loggers.P2P_DESC_SERV);
00056 protected static String serviceName = P2P_NODE_NAME;
00057 protected int askedNodes = 0;
00058 protected P2PService serviceP2P;
00059 private Vector peerList;
00060 protected String nodeFamilyRegexp = null;
00061
00062 public P2PDescriptorService() {
00063 }
00064
00068 public ProActiveRuntime[] startService() throws ProActiveException {
00069 if (serviceP2P == null) {
00070
00071 P2PService precedentService = this.getPrecedentService();
00072 if (precedentService != null) {
00073
00074 this.serviceP2P = precedentService;
00075 this.serviceP2P.firstContact(this.peerList);
00076 } else {
00077
00078 StartP2PService startServiceP2P = new StartP2PService(this.peerList);
00079 startServiceP2P.start();
00080 this.serviceP2P = startServiceP2P.getP2PService();
00081 }
00082 }
00083
00084
00085 return null;
00086 }
00087
00091 private P2PService getPrecedentService() {
00092 String url = System.getProperty(PROPERTY_ACQUISITION) +
00093 "://localhost:" + System.getProperty(PROPERTY_PORT) + "/" +
00094 P2P_NODE_NAME;
00095 try {
00096 Node serviceNode = NodeFactory.getNode(url);
00097 Object[] ao = serviceNode.getActiveObjects(P2PService.class.getName());
00098 if (ao.length == 1) {
00099 if (logger.isInfoEnabled()) {
00100 logger.info("A precedent P2P service is running");
00101 }
00102 return (P2PService) ao[0];
00103 } else {
00104 if (logger.isInfoEnabled()) {
00105 logger.info("No P2P service is runned");
00106 }
00107 return null;
00108 }
00109 } catch (Exception e) {
00110 if (logger.isInfoEnabled()) {
00111 logger.info("No P2P service is runned");
00112 }
00113 return null;
00114 }
00115 }
00116
00120 public int getNodeNumber() {
00121 return askedNodes;
00122 }
00123
00128 public void setNodeNumber(int nodeNumber) {
00129 this.askedNodes = nodeNumber;
00130 }
00131
00138 public void setNodeNumberToMAX() {
00139 this.askedNodes = MAX_NODE;
00140 }
00141
00145 public String getServiceName() {
00146 return serviceName;
00147 }
00148
00153 public void setAcq(String acq) {
00154 System.setProperty(PROPERTY_ACQUISITION, acq);
00155 }
00156
00161 public void setPort(String port) {
00162 System.setProperty(PROPERTY_PORT, port);
00163 }
00164
00169 public void setNoa(String noa) {
00170 System.setProperty(PROPERTY_NOA, noa);
00171 }
00172
00177 public void setTtu(String ttu) {
00178 System.setProperty(PROPERTY_TTU, ttu);
00179 }
00180
00185 public void setTtl(String ttl) {
00186 System.setProperty(PROPERTY_TTL, ttl);
00187 }
00188
00193 public void setMultiProcNodes(String multi_proc_nodes) {
00194 System.setProperty(PROPERTY_MULTI_PROC_NODES, multi_proc_nodes);
00195 }
00196
00201 public void setXmlPath(String xml_path) {
00202 System.setProperty(PROPERPY_XML_PATH, xml_path);
00203 }
00204
00208 public void setPeerList(String[] peerList) {
00209 this.peerList = new Vector();
00210 for (int i = 0; i < peerList.length; i++) {
00211 this.peerList.add(peerList[i]);
00212 }
00213 }
00214
00218 public int getMAX() {
00219 return MAX_NODE;
00220 }
00221
00225 public P2PService getP2PService() {
00226 return this.serviceP2P;
00227 }
00228
00233 public void setNodeFamilyRegexp(String nodeFamilyRegexp) {
00234 this.nodeFamilyRegexp = nodeFamilyRegexp;
00235 }
00236
00240 public String getNodeFamilyRegexp() {
00241 return this.nodeFamilyRegexp;
00242 }
00243 }