-
Notifications
You must be signed in to change notification settings - Fork 0
/
BayouHandler.java
120 lines (109 loc) · 3.54 KB
/
BayouHandler.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
public class BayouHandler
{
public void initiateClientToServer(String ipClient, Write w)
{
Instruction I = new Instruction("Write",w);
sendInstructionToClien(I,ipClient);
}
public void startClient(String ipClient, String ipReplica)
{
ClientHandler c = new ClientHandler(ipClient);
clients.add(c);
Instruction I= new Instruction("connectToServer",ipReplica);
sendInstructionToClient(I,ipClient);
}
public void clientDisconnect(Client i)
{
Client i = Init.nullClient;
}
public void clientReconnect(Client i, Replica j)
{
startClient(i,j);
}
public void pause()
{
}
public void continue()
{
}
public void printLog()
{
for(Node n: totalNodes)
{
printLog(n);
}
}
public void printLog(i)
{
}
public void isolate(Node i)
{
Node n = totalNodes.get(i);
totalNodes.remove(i);
partitionedNodes.add(n);
}
public void reconnect(Node i)
{
Node n = partitionedNodes.get(i);
totalNodes.add(n);
}
public void breakConnection(Node i, Node j)
{
}
//-------------------------------------------------------------------------------------------------------//
public void runAntiEntropy(Replica i, Replica j)
{
Instruction toJ=new Instruction("startAntiEntropy",Bayou.getIP(i.getId()),0);
sendInstructionToReplica(toJ,Bayou.getIP(j.getId()));
Instruction toI=new Instruction("startAntiEntropy",Bayou.getIP(j.getId()),1);
sendInstructionToReplica(toI,Bayou.getIP(i.getId()));
/*j.selectToSend(); //j sends write to i
i.receiveWriteFromReplica(); //i receives writes from j
i.selectToSend();
j.receiveWriteFromReplica(); */
}
public void runAntiEntropy(PrimaryReplica i, Replica j)
{
//where primaryReplica is the one used on this current server
Instruction toJ=new Instruction("startAntiEntropy",Bayou.getIP(i.getId()),0);
sendInstructionToReplica(toJ,Bayou.getIP(j.getId()));
i.receiveWriteFromReplica(); //i receives writes from j
i.selectToSend();
}
public void sendInstructionToReplica(Instruction I,String IP)
{
try{
InetAddress svr = InetAddress.getByName(IP);
// Thread.sleep(3000); //wait for 3 seconds before sending to ensure process has completed processing and is waiting to receive
Socket skt = new Socket(svr,2000);
OutputStream os = skt.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(V);
oos.close();
os.close();
skt.close();
// Thread.sleep(1000);
}
catch(Exception e)
{
}
}
public void sendInstructionToClient(Instruction I,String IP)
{
try{
InetAddress svr = InetAddress.getByName(IP);
// Thread.sleep(3000); //wait for 3 seconds before sending to ensure process has completed processing and is waiting to receive
Socket skt = new Socket(svr,2002);
OutputStream os = skt.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(V);
oos.close();
os.close();
skt.close();
// Thread.sleep(1000);
}
catch(Exception e)
{
}
}
}