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.loadbalancing.util;
00032
00033 import java.io.IOException;
00034 import java.rmi.AlreadyBoundException;
00035 import java.util.Iterator;
00036 import java.util.Vector;
00037
00038 import org.objectweb.proactive.ActiveObjectCreationException;
00039 import org.objectweb.proactive.ProActive;
00040 import org.objectweb.proactive.ProActiveInternalObject;
00041 import org.objectweb.proactive.core.ProActiveException;
00042 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00043 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00044 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00045 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
00046 import org.objectweb.proactive.core.event.NodeCreationEvent;
00047 import org.objectweb.proactive.core.event.NodeCreationEventListener;
00048 import org.objectweb.proactive.core.node.Node;
00049 import org.objectweb.proactive.core.node.NodeException;
00050 import org.objectweb.proactive.p2p.loadbalancer.P2PLoadBalancer;
00051 import org.objectweb.proactive.p2p.service.P2PService;
00052 import org.objectweb.proactive.p2p.service.StartP2PService;
00053 import org.objectweb.proactive.p2p.service.node.P2PNodeLookup;
00054 import org.objectweb.proactive.p2p.service.util.P2PConstants;
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 public class startLBoverP2P implements ProActiveInternalObject,
00085 NodeCreationEventListener {
00086 Vector arrivedNodes;
00087
00088 P2PNodeLookup p2pNodeLookup;
00089
00090 Vector loadBalancers;
00091
00092 protected int nodesBooked;
00093
00100 public static void main(String[] args) throws AlreadyBoundException,
00101 ProActiveException {
00102
00103
00104
00105 startLBoverP2P start = (startLBoverP2P) ProActive.newActive(
00106 startLBoverP2P.class.getName(), null);
00107
00108 start.doit("IntegrationTest");
00109 start.killMe();
00110 }
00111
00112 public startLBoverP2P() {
00113 }
00114
00115 public void doit(String JobId) throws ProActiveException {
00116
00117 nodesBooked = 0;
00118 ProActiveConfiguration.load();
00119 ProActiveDescriptor pad;
00120 VirtualNode vn = null;
00121 arrivedNodes = new Vector();
00122 try {
00123 pad = ProActive.getProactiveDescriptor("/user/sboukhal/home/TestLB.xml");
00124 vn = pad.getVirtualNode("IntegrationTest");
00125 ((VirtualNodeImpl) vn).addNodeCreationEventListener(this);
00126 System.out.println("Activation");
00127 vn.activate();
00128 System.out.println("/Activation");
00129 } catch (ProActiveException e2) {
00130 e2.printStackTrace();
00131 }
00132
00133 while (nodesBooked < 9)
00134 try {
00135 Thread.sleep(100);
00136 } catch (InterruptedException e) {
00137 }
00138
00139 System.out.println("[TEST] Starting P2P Infranstructure");
00140
00141 String peersFile = "/user/jbustos/home/peers.file";
00142 StartP2PService sp2ps = new StartP2PService(peersFile);
00143 try {
00144 sp2ps.start();
00145 } catch (ProActiveException e) {
00146 e.printStackTrace();
00147 }
00148
00149 try {
00150 Thread.sleep(1 * 1000);
00151 } catch (InterruptedException e) {
00152 }
00153
00154 Iterator it = arrivedNodes.iterator();
00155
00156 while (it.hasNext()) {
00157 Node remoteNode = (Node) it.next();
00158
00159 sp2ps = (StartP2PService) ProActive.newActive(StartP2PService.class
00160 .getName(), new Object[] { peersFile }, remoteNode);
00161 sp2ps.start();
00162 ProActive.terminateActiveObject(sp2ps, false);
00163
00164 }
00165
00166 arrivedNodes.add(ProActive.getNode());
00167
00168 try {
00169 Thread.sleep(2 * 1000);
00170 } catch (InterruptedException e) {
00171 }
00172 System.out.println("[TEST] Starting P2P LoadBalancer");
00173
00174 String itAddress;
00175 loadBalancers = new Vector();
00176 P2PLoadBalancer p2plb = null;
00177 it = arrivedNodes.iterator();
00178
00179 while (it.hasNext()) {
00180 Node n = (Node) it.next();
00181 itAddress = n.getNodeInformation().getURL();
00182 itAddress = itAddress.substring(0, itAddress.lastIndexOf("/"))
00183 + "/" + P2PConstants.P2P_NODE_NAME;
00184
00185 p2plb = null;
00186 try {
00187 p2plb = (P2PLoadBalancer) ProActive.newActive(
00188 P2PLoadBalancer.class.getName(), null, itAddress);
00189 loadBalancers.add(p2plb);
00190
00191 } catch (ActiveObjectCreationException e) {
00192 e.printStackTrace();
00193 } catch (NodeException e) {
00194 e.printStackTrace();
00195 }
00196 }
00197
00198 try {
00199 Thread.sleep(1000 * 1);
00200 } catch (InterruptedException e) {
00201 }
00202
00203 it = loadBalancers.iterator();
00204 while (it.hasNext()) {
00205 ((P2PLoadBalancer) it.next()).init();
00206 }
00207
00208 try {
00209 Thread.sleep(1000 * 1);
00210 } catch (InterruptedException e) {
00211 }
00212
00213 try {
00214 JacobiDispatcher jacobiTest = new JacobiDispatcher("400", "25",
00215 "3000", P2PService.getLocalP2PService());
00216 } catch (ProActiveException e) {
00217 } catch (Exception e) {
00218 }
00219
00220 }
00221
00222 public void nodeCreated(NodeCreationEvent event) {
00223 arrivedNodes.add(event.getNode());
00224 nodesBooked++;
00225 System.out.println("nodeCreated : "+event.getNode().getNodeInformation().getName());
00226 }
00227
00228 public void killMe() {
00229 try {
00230 ProActive.getBodyOnThis().terminate();
00231 } catch (IOException e) {
00232 }
00233 }
00234 }