This commit is contained in:
cheney 2022-07-22 21:11:23 +08:00
parent cb0d4e6e9f
commit 63c663a88f
12 changed files with 77 additions and 25 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
/.idea/
/target/
/pack/
/logs/
/test-log/

View File

@ -5,7 +5,7 @@
},
"clear": [
{
"func": "rmdir",
"func": "rm",
"path": "%out_path%"
}
],
@ -31,6 +31,12 @@
"cmd" : "dproto"
}],
"build": [
{
"cmd": "clear"
},
{
"cmd": "init"
},
{
"shell": "mvn package -DskipTests",
"check": "BUILD SUCCESS"
@ -49,9 +55,19 @@
"from": "./doc",
"to": "%out_path%/doc"
},
{
"func": "cp",
"from": "./src/test/java/sample",
"to": "%out_path%/sample"
},
{
"func": "zip",
"from": "./%out_path%/*",
"from": "%out_path%/*",
"to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip"
},
{
"func": "open",
"path": "%out_path%/",
"to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip"
}
]

View File

@ -28,7 +28,7 @@
<dependency>
<groupId>com.sunyard</groupId>
<artifactId>sydapi4j</artifactId>
<version>1.0.20220712</version>
<version>1.0.20220722</version>
</dependency>
<dependency>
@ -46,11 +46,6 @@
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log.version}</version>
</dependency>
<dependency> <!-- 桥接告诉commons logging使用Log4j2 -->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log.version}</version>
</dependency>
</dependencies>

View File

@ -5,6 +5,12 @@ public class Consts {
public static final int ECB_ENC = 1;
public static final int LogLevelOFF = 0;
public static final int LogLevelError = 1;
public static final int LogLevelInfo = 2;
public static final int LogLevelDebug = 3;
// 唯一包
public static final int PkgNumAll = 0;

View File

@ -1,5 +1,9 @@
package com.sunyard.sge.database;
import com.sunyard.sge.log.LogFactory;
import org.slf4j.Logger;
import racal.sunyard.main.SydApi4j;
import java.util.List;
/**
@ -23,6 +27,8 @@ public interface SydApi {
String pcLogPath,
int iLogLevel) {
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
SydApi4j.setLogger( logger );
}
/**

View File

@ -14,6 +14,14 @@ public class SydApi4Database implements SydApi {
private SydApi4j[] hsms = null;
@Deprecated
public SydApi4Database() {
}
public SydApi4Database(SydApi4j[] hsms) {
this.hsms = hsms;
}
@Override
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
SydApi4j api = (SydApi4j) new SydApi4j().connect(pcIpList[0], iPortList[0], null, iConnectTimeOut);

View File

@ -1,6 +1,7 @@
package com.sunyard.sge.database.pool;
import com.sunyard.sge.database.SydApi;
import com.sunyard.sge.database.SydApi4Database;
import com.sunyard.sge.pool.ThreadBasedConnectPool;
import racal.sunyard.main.SydApi4j;
@ -36,7 +37,7 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
}
}
return null;
return new SydApi4Database( apis );
}
// 保活接口

View File

@ -1,5 +1,6 @@
package com.sunyard.sge.log;
import com.sunyard.sge.database.Consts;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
@ -27,11 +28,7 @@ public class LogFactory {
public static final String logName = "sge-hsm-sydapi-log";
// 日志级别
public static final int LogLevelOFF = 0;
public static final int LogLevelError = 1;
public static final int LogLevelInfo = 2;
public static final int LogLevelDebug = 3;
public static int iLogLevel = LogLevelDebug;
public static int iLogLevel = Consts.LogLevelOFF;
// Levels
public static final Level[] levels = new Level[]{ Level.OFF, Level.ERROR, Level.INFO, Level.DEBUG };
@ -100,7 +97,9 @@ public class LogFactory {
* 创建 Logger
* @return Logger
*/
public static Logger createLogger() {
public static Logger createLogger(String pcLogPath, int iLogLevel) {
LogFactory.pcLogPath = pcLogPath;
LogFactory.iLogLevel = iLogLevel;
start();
return LoggerFactory.getLogger( logName );
}

View File

@ -3,7 +3,9 @@ package sample;
import com.sunyard.proto.Util;
import com.sunyard.sge.database.*;
import com.sunyard.sge.database.Consts;
import com.sunyard.sge.log.LogFactory;
import org.junit.Assert;
import org.slf4j.Logger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@ -13,16 +15,30 @@ public class Sample
{
public static void main(String[] args) {
System.setProperty("com.sunyard.sydapi4j.debug", "true");
// 路径要以 / \\ 结尾表示目录
SydApi.SYD_SetLogConfig("./logs/", Consts.LogLevelDebug );
SydApi api = new SydApi4Database();
Logger log = LogFactory.getLogger();
log.info("start");
// 通常单例就够了
SydApiBuilder builder = new SydApiBuilder(
new String[]{ "192.168.0.200" },
new int[]{ 8889 },
10,
15
);
// 每个工作线程中调用
SydApi api = builder.build();
try {
api = api.SYD_Connect_Ex(
new String[]{ "192.168.0.200" },
new int[]{ 8889 },
10,
15
);
// 不建议使用了
// api = api.SYD_Connect_Ex(
// new String[]{ "192.168.0.200" },
// new int[]{ 8889 },
// 10,
// 15
// );
// 短数据加密解密
@ -54,6 +70,8 @@ public class Sample
if ( null != api ) {
api.SYD_Disconnect_Ex();
}
System.out.println("all over");
log.info("all over");
}
}

View File

@ -6,7 +6,7 @@ import org.slf4j.Logger;
public class LogTest {
public static void main(String[] args) {
Logger log = LogFactory.createLogger();
Logger log = LogFactory.createLogger("./test-log/", 2);
log.error("error");
log.info("info");
log.debug("debug");

View File

@ -6,4 +6,5 @@
- groovy-all-2.3.2 通信协议支持
- proto-1.0-20220412 通信协议支持
- slf4j-api-1.7.10 日志接口
- sydapi-1.12.dd63df.jar 加密机通信包
- sydapi4j-1.0.20220722.jar 加密机通信包
-