Skip to content

Commit d2c0085

Browse files
author
belbix
committed
v 1.0.0
first release
1 parent 4620cf9 commit d2c0085

File tree

8 files changed

+69
-8
lines changed

8 files changed

+69
-8
lines changed

checker.cfg

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dbClassName: com.mysql.cj.jdbc.Driver
2+
dbUrl: jdbc:mysql://localhost:3306/tim?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
3+
dbUser: belbix
4+
dbPassword: 111111
5+
loopTime: 10
6+
dateSelect: select t.date from ticks as t order by t.date desc limit 1
7+
maxDiff: 100

src/main/resources/logback.xml renamed to logback.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<configuration debug="true">
2+
<configuration>
33

44
<property name="LOGS" value="./logs" />
55

@@ -33,7 +33,7 @@
3333
<smtpHost>smtp.gmail.com</smtpHost>
3434
<smtpPort>587</smtpPort>
3535
<username>klan.kapkan@gmail.com</username>
36-
<password>br00tha7</password>
36+
<password>123</password>
3737
<to>7453635@gmail.com</to>
3838
<from>klan.kapkan@gmail.com</from>
3939
<subject>CHECKER: %logger{20} - %m</subject>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</dependencies>
3636

3737
<build>
38-
<finalName>tim</finalName>
38+
<finalName>dbchecker</finalName>
3939
<plugins>
4040
<plugin>
4141
<groupId>org.apache.maven.plugins</groupId>

sh/shutdown.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
AppPID=`cat ./pid`
3+
kill $AppPID
4+
echo Stop app with PID: $AppPID
5+
rm ./pid

sh/start.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'/C/Program Files/Java/jdk-11.0.1/bin/java' -Xmx256m -Dlogback.configurationFile=logback.xml -cp dbchecker.jar pro.belbix.dbchecker.Main checker.cfg

sh/startup.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
nohup java -Xmx128m -Dlogback.configurationFile=logback.xml -cp dbchecker.jar pro.belbix.dbchecker.Main checker.cfg > /dev/null 2>&1 &
3+
MyPID=$!
4+
echo Start DB Checker with PID: $MyPID
5+
echo $MyPID > ./pid

src/main/java/pro/belbix/dbchecker/Config.java

+47-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
package pro.belbix.dbchecker;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.io.BufferedReader;
7+
import java.io.FileReader;
8+
import java.io.IOException;
9+
import java.lang.reflect.Field;
10+
311
public class Config {
12+
private final static Logger log = LoggerFactory.getLogger(Config.class);
413
private static String path;
514
private static Config instance;
615

@@ -18,20 +27,54 @@ public static Config getInstance() {
1827
}
1928

2029
private void init() {
21-
if(path == null) return;
30+
if (path == null) return;
31+
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
32+
String s;
33+
while ((s = br.readLine()) != null) {
34+
readLine(s);
35+
}
36+
} catch (IOException e) {
37+
log.error(e.getMessage(), e);
38+
}
39+
40+
}
41+
42+
private void readLine(String s) {
43+
String[] splt = s.split(":", 2);
44+
if (splt.length < 2) throw new IllegalStateException("Wrong config: " + s);
45+
String name = splt[0].trim();
46+
String value = splt[1].trim();
47+
48+
try {
49+
Field field = this.getClass().getDeclaredField(name);
50+
field.setAccessible(true);
51+
switch (field.getType().getSimpleName()) {
52+
case "String":
53+
field.set(this, value);
54+
break;
55+
case "Integer":
56+
field.set(this, Integer.valueOf(value));
57+
break;
58+
default:
59+
throw new UnsupportedOperationException("Type not supported: " + field.getType().getSimpleName());
60+
}
61+
62+
} catch (NoSuchFieldException | IllegalAccessException e) {
63+
log.error(e.getMessage(), e);
64+
}
2265
}
2366

24-
public static void setPath(String path){
67+
public static void setPath(String path) {
2568
Config.path = path;
2669
}
2770

2871
private String dbClassName = "com.mysql.cj.jdbc.Driver";
2972
private String dbUrl = "jdbc:mysql://localhost:3306/tim?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true";
3073
private String dbUser = "belbix";
3174
private String dbPassword = "111111";
32-
private int loopTime = 10;
75+
private Integer loopTime = 10;
3376
private String dateSelect = "select t.date from ticks as t order by t.date desc limit 1";
34-
private int maxDiff = 100;
77+
private Integer maxDiff = 100;
3578

3679
public String getDbClassName() {
3780
return dbClassName;

src/main/java/pro/belbix/dbchecker/DBService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private void init() {
3636
} catch (ClassNotFoundException e) {
3737
log.error(e.getMessage(), e);
3838
}
39-
39+
log.info("Connect to " + config.getDbUrl());
4040
try {
4141
conn = DriverManager.getConnection(config.getDbUrl(), config.getDbUser(), config.getDbPassword());
4242
} catch (SQLException e) {

0 commit comments

Comments
 (0)