org/objectweb/proactive/loadbalancing/util/startLBoverP2P.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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  * ProActive: The Java(TM) library for Parallel, Distributed, Concurrent
00060  * computing with Security and Mobility
00061  * 
00062  * Copyright (C) 1997-2006 INRIA/University of Nice-Sophia Antipolis Contact:
00063  * proactive@objectweb.org
00064  * 
00065  * This library is free software; you can redistribute it and/or modify it under
00066  * the terms of the GNU Lesser General Public License as published by the Free
00067  * Software Foundation; either version 2.1 of the License, or any later version.
00068  * 
00069  * This library is distributed in the hope that it will be useful, but WITHOUT
00070  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00071  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
00072  * details.
00073  * 
00074  * You should have received a copy of the GNU Lesser General Public License
00075  * along with this library; if not, write to the Free Software Foundation, Inc.,
00076  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00077  * 
00078  * Initial developer(s): The ProActive Team
00079  * http://www.inria.fr/oasis/ProActive/contacts.html Contributor(s):
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                 //Node n = NodeFactory.createNode("rmi://psychoquack:2805/StartTest");
00104                 
00105                 startLBoverP2P start = (startLBoverP2P) ProActive.newActive(
00106                                 startLBoverP2P.class.getName(), null/*,n*/);
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 }

Generated on Mon Jan 22 15:16:11 2007 for ProActive by  doxygen 1.5.1