-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfiguration.java
More file actions
131 lines (93 loc) · 4.94 KB
/
Copy pathConfiguration.java
File metadata and controls
131 lines (93 loc) · 4.94 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
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
121
122
123
124
125
126
127
128
129
130
131
import java.io.*;
import java.util.*;
public class Configuration extends Module {
private HashMap<String, Configuration.PeerInfo> peerList;
private HashMap<String, String> commonInfo;
public HashMap<String, PeerInfo> getPeerList() {
return peerList;
}
public HashMap<String,String> getCommonInfo() {
return commonInfo;
}
public class PeerInfo
{
private int peerID;
private String hostName;
private int portNumber;
private boolean hasFile;
protected void setPeerID(int peerID)
{
this.peerID = peerID;
}
public int getPeerID()
{
return peerID;
}
protected void setHostName(String hostName)
{
this.hostName = hostName;
}
public String getHostName()
{
return hostName;
}
protected void setPortNumber(int portNumber)
{
this.portNumber = portNumber;
}
public int getPortNumber()
{
return portNumber;
}
protected void setHasFile(boolean hasFile)
{
this.hasFile = hasFile;
}
public boolean getHasFile()
{
return hasFile;
}
}
@Override
public void initialConfiguration() {
String st;
boolean hasFile;
peerList = new HashMap<String, Configuration.PeerInfo>();
PeerInfo node = null;
try {
BufferedReader in = new BufferedReader(new FileReader(Constants.PEER_CFG_FILE));
while((st = in.readLine()) != null)
{
node = new PeerInfo();
String tokens[] = st.split(" ");
node = new Configuration.PeerInfo();
node.setPeerID(Integer.parseInt(tokens[0]));
node.setHostName(tokens[1]);
node.setPortNumber(Integer.parseInt(tokens[2]));
hasFile = (Integer.parseInt(tokens[3]) == 1) ? true : false;
node.setHasFile(hasFile);
getPeerList().put(tokens[0], node);
}
in.close();
} catch(IOException e)
{
System.out.println("There was a problem opening the peer configuration file. Make sure the file exists");
}
//read in config info
commonInfo = new LinkedHashMap<String, String>();
try {
BufferedReader in = new BufferedReader(new FileReader(Constants.COMMON_CFG_FILE));
while((st = in.readLine()) != null)
{
String tokens[] = st.split(" ");
commonInfo.put(tokens[0], tokens[1]);
}
in.close();
} catch(IOException e)
{
System.out.println(e.getMessage());
//System.out.println("There was a problem opening the common configuration file. Make sure the file exists");
}
//System.out.println("CONFIG COMPLETE");
}
}