-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package EasyRaft.worker; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
||
/** | ||
* Created by jrj on 18-1-11. | ||
*/ | ||
public class XMLReader { | ||
private int leaderPort; | ||
XMLReader(String path){ | ||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
|
||
try { | ||
DocumentBuilder db = dbf.newDocumentBuilder(); | ||
Document document = db.parse(path); | ||
NodeList hostList = document.getElementsByTagName("port"); | ||
|
||
//遍历每一个book节点 | ||
for (int i = 0; i < hostList.getLength(); i++) { | ||
Node host = hostList.item(i); | ||
leaderPort = Integer.parseInt(host.getFirstChild().getNodeValue()); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public int getLeaderPort(){ | ||
return leaderPort; | ||
} | ||
public static void main(String[] args){ | ||
new XMLReader("/home/jrj/Desktop/idea-IU-163.12024.16/java_learn/EasyRaft/src/main/java/EasyRaft/worker/config.xml"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<hosts> | ||
<host> | ||
<ip>192.168.1.22</ip> | ||
</host> | ||
<clusterSize> | ||
5 | ||
</clusterSize> | ||
<leaderPort> | ||
<port>30303</port> | ||
</leaderPort> | ||
</hosts> |