Skip to content

Commit 4267f68

Browse files
committed
Added the support for command line arguments and improved the logging
1 parent 0a22a8e commit 4267f68

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

apache-zookeeper/leader-election/src/main/java/com/sts/allprogtutorials/zk/leaderelection/main/LeaderElectionLauncher.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ public class LeaderElectionLauncher {
2323

2424
public static void main(String[] args) throws IOException {
2525

26-
final String zkURL = "10.127.128.56:2181";
26+
if(args.length < 2) {
27+
System.err.println("Usage: java ");
28+
System.exit(2);
29+
}
30+
31+
final int id = Integer.valueOf(args[0]);
32+
final String zkURL = args[1];
2733

2834
final ExecutorService service = Executors.newSingleThreadExecutor();
2935

30-
final Future<?> status = service.submit(new ProcessNode(4, zkURL));
36+
final Future<?> status = service.submit(new ProcessNode(id, zkURL));
3137

3238
try {
3339
status.get();

apache-zookeeper/leader-election/src/main/java/com/sts/allprogtutorials/zk/leaderelection/nodes/ProcessNode.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ private void attemptForLeaderPosition() {
6363
@Override
6464
public void run() {
6565

66-
System.out.println("Process with id: " + id + " has started!");
66+
if(LOG.isInfoEnabled()) {
67+
LOG.info("Process with id: " + id + " has started!");
68+
}
6769

6870
final String rootNodePath = zooKeeperService.createNode(LEADER_ELECTION_ROOT_NODE, false, false);
6971
if(rootNodePath == null) {

apache-zookeeper/leader-election/src/main/resources/log4j.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</layout>
1010
</appender>
1111

12-
<logger name="org.apache.zookeeper.ZooKeeper">
12+
<logger name="org.apache.zookeeper">
1313
<level value="warn" />
1414
</logger>
1515

0 commit comments

Comments
 (0)