KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > utobcast > draw > Main


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: dream@objectweb.org
20  *
21  * Initial developer(s): Vivien Quema
22  * Contributor(s):
23  */

24
25 package utobcast.draw;
26
27 import java.net.InetAddress JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
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 /**
43  * A class that defines a main method to launch the example.
44  */

45 public class Main
46 {
47
48   /**
49    * Starts a new MonitoringPump
50    *
51    * @param args command line arguments
52    * @throws Exception if an error occurs.
53    */

54   public static void main(String JavaDoc[] args) throws Exception JavaDoc
55   {
56     Factory f = FactoryFactory.getFactory();
57     Map JavaDoc ctx = new HashMap JavaDoc();
58
59     // Create the composite
60
ctx.put("naming-service", Registry.getRegistry("zirconium.inrialpes.fr"));
61     Component composite = (Component) f.newComponent("utobcast.draw.Draw", ctx);
62
63     // Start the composite
64
Fractal.getLifeCycleController(composite).startFc();
65
66     // Configure process membership
67

68     //Create 5 processes
69

70     TCPProcess[] tcpProcesses = new TCPProcess[3];
71     tcpProcesses[0] = new TCPProcess((short) 0, InetAddress.getLocalHost(),
72         30000);
73     tcpProcesses[1] = new TCPProcess((short) 1, InetAddress.getLocalHost(),
74         30001);
75     tcpProcesses[2] = new TCPProcess((short) 2, InetAddress.getLocalHost(),
76         30002);
77     // tcpProcesses[3] = new TCPProcess((short) 3, InetAddress.getLocalHost(),
78
// 30003);
79
// tcpProcesses[4] = new TCPProcess((short) 4, InetAddress.getLocalHost(),
80
// 30004);
81

82     ContentController contentController = Fractal
83         .getContentController(composite);
84
85     for (int i = 0; i < tcpProcesses.length; i++)
86     {
87       Component node = Util.getComponentByName(contentController, Integer
88           .toString(i));
89       ContentController cc = Fractal.getContentController(node);
90       ProcessMembership processMembershipItf = (ProcessMembership) Util
91           .getComponentByName(cc, "UTOBcastProtocol/ProcessMembership")
92           .getFcInterface(ProcessMembership.ITF_NAME);
93       processMembershipItf.setLeader(tcpProcesses[0]);
94       processMembershipItf.setBackup(tcpProcesses[1]);
95       processMembershipItf.setMyself(tcpProcesses[i]);
96     }
97
98     // Retrieve the process membership of the leader
99
ProcessMembership leaderProcessMembershipItf = (ProcessMembership) Util
100         .getComponentByName(contentController,
101             "0/UTOBcastProtocol/ProcessMembership").getFcInterface(
102             ProcessMembership.ITF_NAME);
103
104     // Retrieve the process membership of the leader
105
ProcessMembership backupMembershipItf = (ProcessMembership) Util
106         .getComponentByName(contentController,
107             "1/UTOBcastProtocol/ProcessMembership").getFcInterface(
108             ProcessMembership.ITF_NAME);
109
110     for (int i = 0; i < tcpProcesses.length; i++)
111     {
112       leaderProcessMembershipItf.addProcess(tcpProcesses[i]);
113       backupMembershipItf.addProcess(tcpProcesses[i]);
114     }
115
116   }
117 }
Popular Tags