1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package jgroup.relacs.simulator;
20
21 import java.rmi.RemoteException;
22 import java.util.Iterator;
23
24 import jgroup.core.ConfigManager;
25 import jgroup.core.ConfigurationException;
26 import jgroup.relacs.config.DistributedSystemConfig;
27 import jgroup.relacs.config.Domain;
28 import jgroup.relacs.config.DomainSet;
29 import jgroup.relacs.config.Host;
30 import jgroup.relacs.config.HostSet;
31
32
33
34
35
36
37
38
39
40 public class PartitionSimulator
41 {
42
43 public static void main(String[] argv)
44 {
45 if (argv.length == 0)
46 throw new IllegalArgumentException("Wrong number of arguments");
47 int reachability = Integer.parseInt(argv[0]);
48 System.out.println("Domain reachability=" + reachability);
49 try {
50 ConfigManager.init();
51 } catch (ConfigurationException e) {
52 e.printStackTrace();
53 }
54 DistributedSystemConfig dsc = ConfigManager.getDistributedSystem();
55 DomainSet domains = dsc.getDomainSet();
56 for (Iterator<Domain> iter = domains.iterator(); iter.hasNext();) {
57 Domain domain = iter.next();
58 for (Iterator<Domain> iterator = domains.iterator(); iterator.hasNext();) {
59 Domain otherDomain = iterator.next();
60 if (!domain.equals(otherDomain)) {
61 setReachability(reachability, domain, otherDomain);
62 }
63 }
64 HostSet d1Hosts = domain.getHostSet();
65 for (Iterator<Host> i = d1Hosts.iterator(); i.hasNext();) {
66 Host host = i.next();
67 try {
68 ((SocketStatus) host.get("SocketStatus")).commit();
69 } catch (RemoteException e) {
70 e.printStackTrace();
71 }
72 }
73 }
74 }
75
76 private static void setReachability(int reachability, Domain d1, Domain d2)
77 {
78 HostSet d1Hosts = d1.getHostSet();
79 for (Iterator<Host> iter = d1Hosts.iterator(); iter.hasNext();) {
80 Host h1 = iter.next();
81 System.out.print(h1.getHostName() + "(" + reachability + "): ");
82 try {
83 SocketStatus status = (SocketStatus) h1.lookup("SocketStatus");
84 h1.put("SocketStatus", status);
85 for (Iterator<Host> iterator = d2.getHostSet().iterator(); iterator.hasNext();) {
86 Host h2 = iterator.next();
87 status.setStatus(h2.getAddress(), reachability);
88 System.out.print(h2.getHostName() + " ");
89 }
90 System.out.println();
91 } catch (Exception e) {
92 iter.remove();
93 System.out.println(h1.getHostName() + " is not available");
94 }
95 }
96 }
97
98 }