-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspObserver2.java
More file actions
72 lines (52 loc) · 1.73 KB
/
spObserver2.java
File metadata and controls
72 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package example.progetto;
import peersim.util.*;
import peersim.core.*;
import peersim.config.*;
import peersim.cdsim.*;
import java.util.Random;
import peersim.transport.Transport;
import peersim.cdsim.CDProtocol;
import peersim.edsim.EDProtocol;
import peersim.vector.SingleValueHolder;
import java.util.*;
public class spObserver2 implements Control {
String name;
private static final String PAR_PROT = "protocol";
private static final String PAR_ACCURACY = "accuracy";
/** Protocol identifier */
private final int pid;
/** Accuracy for standard deviation used to stop the simulation */
private final double accuracy;
//Costruttore
public spObserver2(String s){
this.name = s;
accuracy = Configuration.getDouble(name + "." + PAR_ACCURACY, -1);
pid = Configuration.getPid(name + "." + PAR_PROT);
}
public boolean execute() {
long time = peersim.core.CommonState.getTime();
IncrementalStats stats = new IncrementalStats();
int number =0;
for (int i = 0; i < Network.size(); i++)
{
Node n = Network.get(i);
for(int j=0;j<n.protocolSize();j++)
if(n.getProtocol(j) instanceof Linkable)
{
System.out.print("Nodo "+ n.getID()+" Lista vicini: [");
for(int k=0;k<((Linkable)n.getProtocol(j)).degree();k++)
System.out.print(" "+((Linkable)n.getProtocol(j)).getNeighbor(k).getID());
System.out.println(" ]");
break;
}
DinElec protocol = (DinElec) Network.get(i).getProtocol(pid); //2 = DinElec
if (protocol.IsSuperPeer())
number++;
}
stats.add(number);
/* Printing statistics */
System.out.println(name + ": " + " SuperPeers: " + number +" Network size: "+ Network.size());
/* Terminate if accuracy target is reached */
return (stats.getStD()<=accuracy && CommonState.getTime()>0);
}
}