Skip to content

Commit

Permalink
使用log4J来打日志
Browse files Browse the repository at this point in the history
  • Loading branch information
jrjsjtu committed Feb 7, 2018
1 parent aaf426a commit 94af2a7
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 9 deletions.
Binary file added FastTest/KVClient.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions FastTest/KVClient.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<hosts>
<host>
<ip>127.0.0.1:50000</ip>
<ip>127.0.0.1:50001</ip>
<ip>127.0.0.1:50002</ip>
</host>
</hosts>
Binary file added FastTest/KVServer.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions FastTest/KVServer1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<hosts>
<host>
<ip>127.0.0.1:50000</ip>
<ip>127.0.0.1:50001</ip>
<ip>127.0.0.1:50002</ip>
</host>
<KVServerPort>30000</KVServerPort>
<KVSharding>0</KVSharding>
</hosts>
10 changes: 10 additions & 0 deletions FastTest/KVServer2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<hosts>
<host>
<ip>127.0.0.1:50000</ip>
<ip>127.0.0.1:50001</ip>
<ip>127.0.0.1:50002</ip>
</host>
<KVServerPort>30001</KVServerPort>
<KVSharding>1</KVSharding>
</hosts>
Binary file added FastTest/RaftServer.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions FastTest/RaftServer1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<host>
<ip>127.0.0.1:50000</ip>
<clusterSize>3</clusterSize>
</host>
5 changes: 5 additions & 0 deletions FastTest/RaftServer2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<host>
<ip>127.0.0.1:50001</ip>
<clusterSize>3</clusterSize>
</host>
41 changes: 41 additions & 0 deletions FastTest/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

trap 'onCtrlC' INT
function onCtrlC () {
for id in ${proc_id_RaftServer[*]}
do
kill -9 ${id}
echo "kill Raft Server pid "${id}
done

for id in ${proc_id_KVServer[*]}
do
kill -9 ${id}
echo "kill KV Server pid "${id}
done
exit 0
}

nohup java -jar RaftServer.jar RaftServer2.xml 1>/dev/null 2>/dev/null &
echo "init Raft Server1 port:50000"
sleep 4s
nohup java -jar RaftServer.jar RaftServer1.xml 1>/dev/null 2>/dev/null &
echo "init Raft Server2 port:50001"
sleep 4s
nohup java -jar KVServer.jar KVServer1.xml 1>/dev/null 2>/dev/null &
echo "init KV Server1 port:30000 shard 0"
sleep 2s
nohup java -jar KVServer.jar KVServer2.xml 1>/dev/null 2>/dev/null &
echo "init KV Server2 port:30001 shard 1"
sleep 2s

proc_name="RaftServer.jar"
proc_name2="KVServer.jar"

name_suffixx="\>"

proc_id_RaftServer=`ps -ef|grep -i ${proc_name}${name_suffixx}|grep -v "grep"|awk '{print $2}'`
proc_id_KVServer=`ps -ef|grep -i ${proc_name2}${name_suffixx}|grep -v "grep"|awk '{print $2}'`


java -jar KVClient.jar KVClient.xml
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>EasyRaft.worker.MainWorker</mainClass>
<mainClass>KV.Client.KVClient</mainClass>
</transformer>
</transformers>
</configuration>
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/KV/Client/KVClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import EasyRaft.client.RaftClient;
import EasyRaft.client.callBack.RaftCallBack;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import Utils.RaftLogger;
Expand Down Expand Up @@ -76,14 +80,26 @@ public static void main(String[] args){
}

KVClient kvClient = new KVClient(clientConfig);
long start = System.currentTimeMillis();
try {
kvClient.put("aaa1","ccc");
System.out.println(kvClient.get("aaa1"));
} catch (Exception e) {
e.printStackTrace();
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
while(true){
try {
System.out.println("输入1代表写入KV,输入2代表查询KV");
String s = bf.readLine();
if(s.equals("1")){
System.out.println("请输入Key");
String key = bf.readLine();
System.out.println("请输入Value");
String value = bf.readLine();
kvClient.put(key,value);
}else if(s.equals("2")){
System.out.println("请输入Key");
String key = bf.readLine();
System.out.println("key 为 " + key + "的 value 为");
System.out.println(kvClient.get(key));
}
} catch (Exception e) {
e.printStackTrace();
}
}

System.out.println("finish uses " + (System.currentTimeMillis() -start));
}
}

0 comments on commit 94af2a7

Please sign in to comment.