-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReplicaHandler.java
61 lines (57 loc) · 1.44 KB
/
ReplicaHandler.java
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
public class ReplicaHandler
{
private Replica r;
ReplicaHandler(int id, String ip)
{
r=new Replica(id,ip);
}
public void startAntiEntropy()
{
}
public Instruction waitForInstructions() throws IOException
{
ServerSocket ss= new ServerSocket(2000);
//System.out.println(n);
ss.setReuseAddress(true);
ss.setSoTimeout(0);
//n++;
try
{
Socket s = ss.accept();
s.setReuseAddress(true);
s.setSoTimeout(0);
//System.out.println(s.getSoTimeout() );
//System.out.println(s.getReuseAddress() );
InputStream is = s.getInputStream();
ObjectInputStream ois = new ObjectInputStream(is);
Instruction I=null;
I=(Instruction)ois.readObject();
is.close();
s.close();
ss.close();
return I;
}
catch(Exception e)
{
System.out.println(e.getLocalizedMessage());
return null;
}
}
public void executeInstruction(Instruction I)
{
if(I.getInst().equals("startAntiEntropy"))
{
r.setServerConnection(I.getReplicaIP());
if(I.getOrder()==0)
{
r.selectToSend();
r.receiveWriteFromReplica();
}
else
{
r.receiveWriteFromReplica();
r.selectToSend();
}
}
}
}