Skip to content

Commit 915f67b

Browse files
author
chengyitian
committed
AJ-531: upgrade all 'log output' from sout to slf4j-simple;
1 parent 553deec commit 915f67b

13 files changed

+78
-33
lines changed

src/com/xxdb/DBConnection.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ public boolean connect(String hostName, int port, String userId, String password
779779
bt = (BasicTable) conn_.run("select host,port,(memoryUsed/1024.0/1024.0/1024.0)/maxMemSize as memLoad,ratio(connectionNum,maxConnections) as connLoad,avgLoad from rpc(getControllerAlias(),getClusterPerf) where mode=0",0);
780780
break;
781781
} catch (Exception e) {
782-
System.out.println("ERROR getting other data nodes, exception: " + e.getMessage());
782+
log.error("ERROR getting other data nodes, exception: " + e.getMessage());
783783
Node node1 = new Node();
784784
if (isConnected()) {
785785
ExceptionType type = parseException(e.getMessage(), node1);
@@ -926,7 +926,7 @@ else if (type == ExceptionType.ET_NODENOTAVAIL)
926926
throw e;
927927
}
928928
}else {
929-
System.out.println(e.getMessage());
929+
log.error(e.getMessage());
930930
return false;
931931
}
932932
}
@@ -951,11 +951,11 @@ public ExceptionType parseException(String msg, Node node){
951951
index = msg.indexOf(">");
952952
String ipport = msg.substring(index + 1);
953953
if (!Pattern.matches("\\d+", ipport)) {
954-
System.out.println("The control node you are accessing is not the leader node of the highly available (raft) cluster.");
954+
log.error("The control node you are accessing is not the leader node of the highly available (raft) cluster.");
955955
return ExceptionType.ET_NOTLEADER;
956956
} else {
957957
parseIpPort(ipport, node);
958-
System.out.println("New leader is " + node.hostName + ":" + node.port);
958+
log.info("New leader is " + node.hostName + ":" + node.port);
959959
return ExceptionType.ET_NEWLEADER;
960960
}
961961
}else if ((index = msg.indexOf("<DataNodeNotAvail>")) != -1){
@@ -967,7 +967,7 @@ public ExceptionType parseException(String msg, Node node){
967967
conn_.getNode(lastNode);
968968
node.hostName = "";
969969
node.port = 0;
970-
System.out.println(msg);
970+
log.info(msg);
971971
return ExceptionType.ET_NODENOTAVAIL;
972972
}else if ((index = msg.indexOf("The datanode isn't initialized yet. Please try again later")) != -1){
973973
node.hostName = "";

src/com/xxdb/ExclusiveDBConnectionPool.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import java.util.ArrayList;
55
import java.util.LinkedList;
66
import java.util.List;
7-
87
import com.xxdb.data.BasicStringVector;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
910

1011

1112
public class ExclusiveDBConnectionPool implements DBConnectionPool {
@@ -15,6 +16,8 @@ public class ExclusiveDBConnectionPool implements DBConnectionPool {
1516
private final Object finishedTasklock_ = new Object();
1617
private int finishedTaskCount_ = 0;
1718

19+
private static final Logger log = LoggerFactory.getLogger(ExclusiveDBConnectionPool.class);
20+
1821
private class AsyncWorker implements Runnable {
1922
private DBConnection conn_;
2023
private final Thread workThread_;
@@ -63,7 +66,7 @@ public void run() {
6366
}
6467
}
6568
conn_.close();
66-
System.out.println("ExclusiveDBConnectionPool AsyncWorker terminated peacefully.");
69+
log.info("ExclusiveDBConnectionPool AsyncWorker terminated peacefully.");
6770
}
6871
}
6972

@@ -140,7 +143,7 @@ public void execute(DBTask task, int timeOut) {
140143
public void waitForThreadCompletion() {
141144
try {
142145
synchronized (finishedTasklock_) {
143-
System.out.println("Waiting for tasks to complete, remain Task: " + (tasksCount_-finishedTaskCount_));
146+
log.info("Waiting for tasks to complete, remain Task: " + (tasksCount_-finishedTaskCount_));
144147
while (finishedTaskCount_ >= 0) {
145148
if (finishedTaskCount_ < tasksCount_) {
146149
finishedTasklock_.wait();

src/com/xxdb/data/BasicArrayVector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.fasterxml.jackson.annotation.JsonIgnore;
1010
import com.xxdb.io.ExtendedDataInput;
1111
import com.xxdb.io.ExtendedDataOutput;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214

1315

1416
public class BasicArrayVector extends AbstractVector {
@@ -20,6 +22,8 @@ public class BasicArrayVector extends AbstractVector {
2022
private int capacity;
2123
private int scale_ = -1;
2224

25+
private static final Logger log = LoggerFactory.getLogger(BasicArrayVector.class);
26+
2327
public BasicArrayVector(DATA_TYPE type, int size){
2428
this(type, size, -1);
2529
}
@@ -251,7 +255,7 @@ public Vector getSubVector(int[] indices) {
251255
try {
252256
return new BasicArrayVector(value);
253257
} catch (Exception e) {
254-
System.out.println(e.getMessage());
258+
log.error(e.getMessage());
255259
e.printStackTrace();
256260
return null;
257261
}

src/com/xxdb/data/BasicTable.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.xxdb.compression.VectorDecompressor;
66
import com.xxdb.io.ExtendedDataInput;
77
import com.xxdb.io.ExtendedDataOutput;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
810

911
/**
1012
*
@@ -18,6 +20,8 @@ public class BasicTable extends AbstractEntity implements Table{
1820
private Map<String, Integer> colNamesIndex = new HashMap<String, Integer>();
1921
private int[] colCompresses = null;
2022

23+
private static final Logger log = LoggerFactory.getLogger(BasicTable.class);
24+
2125
public BasicTable(ExtendedDataInput in) throws IOException{
2226
int rows = in.readInt();
2327
int cols = in.readInt();
@@ -272,7 +276,7 @@ else if (columns.get(i).getDataType().getValue() >= 65)
272276
jsonStr.append("}");
273277
}
274278
}catch (Exception e){
275-
System.out.println(e.getMessage());
279+
log.error(e.getMessage());
276280
e.printStackTrace();
277281
}
278282
return jsonStr.toString();

src/com/xxdb/data/Utils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import java.util.Calendar;
88
import java.util.HashMap;
99
import java.util.Map;
10-
1110
import com.xxdb.data.Entity.DATA_CATEGORY;
1211
import com.xxdb.data.Entity.DATA_FORM;
1312
import com.xxdb.data.Entity.DATA_TYPE;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1415

1516

1617
public class Utils {
@@ -25,6 +26,8 @@ public class Utils {
2526

2627
public static int SCALE = -1;
2728

29+
private static final Logger log = LoggerFactory.getLogger(Utils.class);
30+
2831
public static void setFormat(int scale){
2932
SCALE = scale;
3033
}
@@ -630,7 +633,7 @@ public void printAll(){
630633
}
631634
}
632635
avg = sum / times.size();
633-
System.out.println(prefix + "avg = " + avg + " min = " + min + " max = " + max);
636+
log.info(prefix + "avg = " + avg + " min = " + min + " max = " + max);
634637
}
635638
}
636639

src/com/xxdb/io/AbstractExtendedDataOutputStream.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.xxdb.io;
22

33

4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46
import java.io.FilterOutputStream;
57
import java.io.IOException;
68
import java.io.OutputStream;
@@ -17,6 +19,8 @@ public abstract class AbstractExtendedDataOutputStream extends FilterOutputStrea
1719
protected long[] longBuf;
1820
protected double[] doubleBuf;
1921

22+
private static final Logger log = LoggerFactory.getLogger(AbstractExtendedDataOutputStream.class);
23+
2024
public AbstractExtendedDataOutputStream(OutputStream out) {
2125
super(out);
2226
}
@@ -227,7 +231,7 @@ public static byte[] getResolveZeroByteArray(byte[] originalArray) {
227231
byte[] newArray;
228232
if (indexOfZero != -1) {
229233
// Create a new array containing only the elements before 0.
230-
System.out.println("The input String contains '\0', it will be dropped start from '\0' to last.");
234+
log.warn("The input String contains '\0', it will be dropped start from '\0' to last.");
231235
newArray = new byte[indexOfZero];
232236
System.arraycopy(originalArray, 0, newArray, 0, indexOfZero);
233237
} else {

src/com/xxdb/route/PartitionedTableAppender.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import com.xxdb.ExclusiveDBConnectionPool;
88
import com.xxdb.data.*;
99
import com.xxdb.data.Vector;
10-
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1112
import java.io.IOException;
1213
import java.util.*;
1314

@@ -27,6 +28,8 @@ public class PartitionedTableAppender {
2728
private List<ArrayList<Integer>> chunkIndices;
2829
private String appendScript;
2930

31+
private static final Logger log = LoggerFactory.getLogger(PartitionedTableAppender.class);
32+
3033
public PartitionedTableAppender(String dbUrl, String tableName, String partitionColName, DBConnectionPool pool) throws Exception {
3134
this(dbUrl, tableName, partitionColName, null, pool);
3235
}
@@ -187,7 +190,7 @@ public static void main(String[] args){
187190
appender.append(new BasicTable(colNames, cols));
188191
}
189192
catch(Exception ex){
190-
System.out.println(ex.getMessage());
193+
log.error(ex.getMessage());
191194
}
192195
}
193196
}

src/com/xxdb/streaming/client/AbstractClient.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.xxdb.data.*;
1515
import com.xxdb.data.Vector;
1616
import com.xxdb.data.Void;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
1719

1820
abstract class AbstractClient implements MessageDispatcher {
1921
protected static final int DEFAULT_PORT = 8849;
@@ -38,6 +40,8 @@ abstract class AbstractClient implements MessageDispatcher {
3840

3941
private Daemon daemon = null;
4042

43+
private static final Logger log = LoggerFactory.getLogger(AbstractClient.class);
44+
4145
class ReconnectItem {
4246
/**
4347
* 0: connected and received message schema
@@ -301,15 +305,15 @@ public void activeCloseConnection(Site site) {
301305
if (verNum >= 995)
302306
params.add(new BasicBoolean(true));
303307
conn.run("activeClosePublishConnection", params);
304-
System.out.println("Successfully closed publish connection");
308+
log.info("Successfully closed publish connection");
305309
} catch (IOException ioex) {
306310
throw ioex;
307311
} finally {
308312
conn.close();
309313
}
310314
} catch (Exception ex) {
311315
ex.printStackTrace();
312-
System.out.println("Unable to actively close the publish connection from site " + site.host + ":" + site.port);
316+
log.error("Unable to actively close the publish connection from site " + site.host + ":" + site.port);
313317
}
314318

315319
try {
@@ -575,7 +579,7 @@ protected void unsubscribeInternal(String host, int port, String tableName, Stri
575579
for (int i = 0; i < sites.length; i++)
576580
sites[i].closed = true;
577581
}
578-
System.out.println("Successfully unsubscribed table " + fullTableName);
582+
log.info("Successfully unsubscribed table " + fullTableName);
579583
} catch (Exception ex) {
580584
throw ex;
581585
} finally {

src/com/xxdb/streaming/client/Daemon.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.xxdb.DBConnection;
44
import com.xxdb.io.ExtendedDataInput;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57
import java.io.IOException;
68
import java.net.ServerSocket;
79
import java.net.Socket;
@@ -19,6 +21,8 @@ class Daemon implements Runnable {
1921
private Thread runningThread_= null;
2022
private LinkedBlockingQueue<DBConnection> connList = new LinkedBlockingQueue<>();
2123

24+
private static final Logger log = LoggerFactory.getLogger(Daemon.class);
25+
2226
public Daemon(int port, MessageDispatcher dispatcher, LinkedBlockingQueue<DBConnection> connections) {
2327
this.listeningPort = port;
2428
this.dispatcher = dispatcher;
@@ -120,7 +124,7 @@ public void run() {
120124
dispatcher.activeCloseConnection(s);
121125
String lastTopic = "";
122126
for (String topic : dispatcher.getAllTopicsBySite(site)) {
123-
System.out.println("try to reconnect topic " + topic);
127+
log.info("try to reconnect topic " + topic);
124128
dispatcher.tryReconnect(topic);
125129
lastTopic = topic;
126130
}
@@ -132,7 +136,7 @@ public void run() {
132136
AbstractClient.Site s = dispatcher.getSiteByName(site);
133137
dispatcher.activeCloseConnection(s);
134138
for (String topic : dispatcher.getAllTopicsBySite(site)) {
135-
System.out.println("try to reconnect topic " + topic);
139+
log.info("try to reconnect topic " + topic);
136140
dispatcher.tryReconnect(topic);
137141
}
138142
dispatcher.setReconnectTimestamp(site, System.currentTimeMillis());
@@ -186,7 +190,7 @@ public void run() {
186190
continue;
187191

188192
try {
189-
System.out.println("Connection closed!!");
193+
log.info("Connection closed!!");
190194
socket.close();
191195
return;
192196
} catch (Exception e) {

src/com/xxdb/streaming/client/MessageParser.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
import com.xxdb.io.BigEndianDataInputStream;
1414
import com.xxdb.io.ExtendedDataInput;
1515
import com.xxdb.io.LittleEndianDataInputStream;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
class MessageParser implements Runnable {
1820
private final int MAX_FORM_VALUE = Entity.DATA_FORM.values().length - 1;
1921
private final int MAX_TYPE_VALUE = Entity.DATA_TYPE.DT_OBJECT.getValue();
2022

23+
private static final Logger log = LoggerFactory.getLogger(MessageParser.class);
24+
2125
BufferedInputStream bis = null;
2226
Socket socket = null;
2327
DBConnectionAndSocket dBConnectionAndSocket;
@@ -164,13 +168,13 @@ else if (body.isVector()) {
164168
}
165169
dispatcher.setMsgId(topic, msgid);
166170
} else {
167-
System.out.println("message body has an invalid format. Vector or table is expected");
171+
log.error("message body has an invalid format. Vector or table is expected");
168172
}
169173
}
170174
} catch (Exception e) {
171175
e.printStackTrace();
172176
if (dispatcher.isClosed(topic)) {
173-
System.out.println("check " + topic + " is unsubscribed");
177+
log.error("check " + topic + " is unsubscribed");
174178
return;
175179
} else {
176180
dispatcher.setNeedReconnect(topic, 1);

0 commit comments

Comments
 (0)