root / src / messages / PredecessorMessage.java @ 1
History | View | Annotate | Download (1.22 KB)
1 |
package messages; |
---|---|
2 |
|
3 |
import chord.ChordManager; |
4 |
import chord.ConnectionInfo; |
5 |
import peer.Peer; |
6 |
|
7 |
import java.net.InetAddress; |
8 |
import java.net.UnknownHostException; |
9 |
|
10 |
public class PredecessorMessage extends Message { |
11 |
|
12 |
private ConnectionInfo ci;
|
13 |
private String ipAddress; |
14 |
private int port; |
15 |
|
16 |
public PredecessorMessage(ConnectionInfo ci,String ipAddress,int port) { |
17 |
this.ci = ci;
|
18 |
this.ipAddress = ipAddress;
|
19 |
this.port = port;
|
20 |
} |
21 |
|
22 |
@Override
|
23 |
public void handleMessage() { |
24 |
if(ChordManager.predecessor == null || |
25 |
ChordManager.numberInInterval(ChordManager.predecessor.getHashedKey(), ChordManager.peerHash,ci.getHashedKey())) |
26 |
ChordManager.predecessor = ci; |
27 |
} |
28 |
|
29 |
@Override
|
30 |
public String toString() { |
31 |
String returnString = null; |
32 |
try {
|
33 |
returnString = "PREDECESSOR " + ChordManager.peerHash + " " + InetAddress.getLocalHost().getHostAddress() + " " + Peer.port; |
34 |
} catch (UnknownHostException e) { |
35 |
e.printStackTrace(); |
36 |
} |
37 |
return returnString;
|
38 |
} |
39 |
@Override
|
40 |
public String getIpAddress() { |
41 |
return this.ipAddress; |
42 |
} |
43 |
|
44 |
@Override
|
45 |
public int getPort() { |
46 |
return this.port; |
47 |
} |
48 |
} |