1 24 25 package utobcast.basic; 26 27 import java.net.InetAddress ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 import org.objectweb.dream.adl.FactoryFactory; 32 import org.objectweb.dream.protocol.utobcast.ProcessMembership; 33 import org.objectweb.dream.util.Util; 34 import org.objectweb.fractal.adl.Factory; 35 import org.objectweb.fractal.api.Component; 36 import org.objectweb.fractal.api.control.ContentController; 37 import org.objectweb.fractal.rmi.registry.Registry; 38 import org.objectweb.fractal.util.Fractal; 39 40 import utobcast.TCPProcess; 41 42 45 public class Main 46 { 47 48 54 public static void main(String [] args) throws Exception 55 { 56 Factory f = FactoryFactory.getFactory(); 57 Map ctx = new HashMap (); 58 59 ctx.put("naming-service", Registry.getRegistry("localhost")); 61 Component composite = (Component) f.newComponent( 62 "utobcast.basic.UTOBcastExample(33333)", ctx); 63 64 ContentController contentController = Fractal 66 .getContentController(composite); 67 68 Component[] nodes = contentController.getFcSubComponents(); 70 TCPProcess[] tcpProcesses = new TCPProcess[nodes.length]; 71 for (int i = 0; i < nodes.length; i++) 72 { 73 tcpProcesses[i] = new TCPProcess((short) i, InetAddress.getLocalHost(), 74 30000 + i); 75 } 76 77 for (int i = 0; i < nodes.length; i++) 79 { 80 ContentController cc = Fractal.getContentController(nodes[i]); 82 Component utoBcastProtocol = Util.getComponentByName(cc, 83 "UTOBcastProtocol"); 84 Fractal.getLifeCycleController(utoBcastProtocol).startFc(); 85 ProcessMembership processMembershipItf = (ProcessMembership) Util 87 .getComponentByName(cc, "UTOBcastProtocol/ProcessMembership") 88 .getFcInterface(ProcessMembership.ITF_NAME); 89 processMembershipItf.setLeader(tcpProcesses[0]); 90 processMembershipItf.setBackup(tcpProcesses[1]); 91 processMembershipItf.setMyself(tcpProcesses[i]); 92 } 93 94 ProcessMembership leaderProcessMembershipItf = (ProcessMembership) Util 96 .getComponentByName(contentController, 97 "0/UTOBcastProtocol/ProcessMembership").getFcInterface( 98 ProcessMembership.ITF_NAME); 99 100 ProcessMembership backupMembershipItf = (ProcessMembership) Util 102 .getComponentByName(contentController, 103 "1/UTOBcastProtocol/ProcessMembership").getFcInterface( 104 ProcessMembership.ITF_NAME); 105 106 for (int i = 0; i < tcpProcesses.length; i++) 107 { 108 leaderProcessMembershipItf.addProcess(tcpProcesses[i]); 109 backupMembershipItf.addProcess(tcpProcesses[i]); 110 } 111 112 Fractal.getLifeCycleController(composite).startFc(); 114 115 } 116 } | Popular Tags |