check修改
This commit is contained in:
parent
22efd4b5b4
commit
0349025ef0
@ -3,7 +3,9 @@ package com.sunyard.sge.database;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.sge.database.pool.HsmLinkInfo;
|
||||
import com.sunyard.sge.database.pool.SydApiPool;
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import com.sunyard.sge.pool.ObjectInPool;
|
||||
import com.sunyard.util.SYMUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
@ -22,6 +24,7 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
private SydApi4j[] hsms = null;
|
||||
private HsmLinkInfo[] linkInfos = null;
|
||||
private ObjectInPool oip = null;
|
||||
|
||||
private boolean isShortLinkMode = false;
|
||||
|
||||
@ -42,6 +45,16 @@ public class SydApi4Database implements SydApi {
|
||||
return linkInfos;
|
||||
}
|
||||
|
||||
public void setOip(ObjectInPool oip) {
|
||||
this.oip = oip;
|
||||
}
|
||||
|
||||
private void updateLastUseTime(){
|
||||
if ( null != this.oip ) {
|
||||
this.oip.updateLastUseTime();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SydApi SYD_Short_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int allDealTimeOut) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
@ -121,7 +134,7 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
SydApiException le = null;
|
||||
|
||||
|
||||
updateLastUseTime();
|
||||
for (SydApi4j api : this.hsms) {
|
||||
|
||||
if (null == api) {
|
||||
@ -178,6 +191,7 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
}
|
||||
SydApiException le = null;
|
||||
updateLastUseTime();
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
@ -236,6 +250,7 @@ public class SydApi4Database implements SydApi {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
|
||||
updateLastUseTime();
|
||||
String keyIndex = String.format("%08d", iKeyIndex);
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
@ -313,6 +328,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
String[] keys = new String[iKeyIndex.length];
|
||||
updateLastUseTime();
|
||||
for (int i = 0; i < iKeyIndex.length; i++) {
|
||||
keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i]));
|
||||
}
|
||||
@ -373,6 +389,7 @@ public class SydApi4Database implements SydApi {
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
updateLastUseTime();
|
||||
String keyIndex = String.format("%08d", iKeyIndex);
|
||||
|
||||
SydApiException le = null;
|
||||
@ -450,6 +467,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
String[] keys = new String[iKeyIndex.length];
|
||||
updateLastUseTime();
|
||||
for (int i = 0; i < iKeyIndex.length; i++) {
|
||||
keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i]));
|
||||
}
|
||||
@ -516,6 +534,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
String[] keys = new String[iKeyIndex.length];
|
||||
updateLastUseTime();
|
||||
for (int i = 0; i < iKeyIndex.length; i++) {
|
||||
keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i]));
|
||||
}
|
||||
@ -591,6 +610,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
SydApiException le = null;
|
||||
updateLastUseTime();
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
@ -664,6 +684,7 @@ public class SydApi4Database implements SydApi {
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData, pcMac);
|
||||
}
|
||||
updateLastUseTime();
|
||||
LongDataReturn<String, String> ret = SYD_SM4Mac_LongData(iKeyIndex, pcData, iPkgNum, pcProcData);
|
||||
|
||||
// 仅一包 和 尾包 返回最终结果
|
||||
@ -684,10 +705,10 @@ public class SydApi4Database implements SydApi {
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
|
||||
String keyIndex = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex));
|
||||
log.debug("\"SK\" + SYMUtil.genPrivateKeyMark方法返回值:{}", keyIndex);
|
||||
SydApiException le = null;
|
||||
updateLastUseTime();
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
@ -739,7 +760,7 @@ public class SydApi4Database implements SydApi {
|
||||
if (null == pcMac) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
updateLastUseTime();
|
||||
String mac = this.SYD_SM4Mac_ShortData(iKeyIndex, pcData);
|
||||
log.debug(this + ".SYD_SM4Mac_ShortData方法返回值:{}", mac);
|
||||
return pcMac.equals(mac);
|
||||
|
||||
@ -4,6 +4,7 @@ import com.sunyard.SydApiException;
|
||||
import com.sunyard.sge.database.SydApi;
|
||||
import com.sunyard.sge.database.SydApi4Database;
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import com.sunyard.sge.pool.ObjectInPool;
|
||||
import com.sunyard.sge.pool.ThreadBasedConnectPool;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
@ -46,7 +47,6 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
// TODO
|
||||
throw new SydApiException("连接错误", -1);
|
||||
}
|
||||
|
||||
@ -106,4 +106,12 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
||||
}
|
||||
}
|
||||
|
||||
protected void afterInit(ObjectInPool oip, SydApi value ){
|
||||
if ( !( value instanceof SydApi4Database ) ) {
|
||||
return;
|
||||
}
|
||||
SydApi4Database api = (SydApi4Database) value;
|
||||
api.setOip( oip );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,6 +13,10 @@ public class ObjectInPool<T> {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void updateLastUseTime(){
|
||||
this.lasUseAt = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public T getObject() {
|
||||
this.lasUseAt = System.currentTimeMillis();
|
||||
return object;
|
||||
|
||||
@ -3,10 +3,10 @@ package com.sunyard.sge.pool;
|
||||
public class PoolConfig {
|
||||
|
||||
// 最大空闲时间
|
||||
private long maxIdle = 5 * 60 * 1000; // 5 分钟
|
||||
private long maxIdle = 5 * 60 ; // 5 分钟
|
||||
|
||||
// 最大无用时间
|
||||
private long maxUseless = 30 * 60 * 1000; // 30 分钟
|
||||
private long maxUseless = 30 * 60 ; // 30 分钟
|
||||
|
||||
public long getMaxIdle() {
|
||||
return maxIdle;
|
||||
|
||||
@ -129,10 +129,15 @@ public class ThreadBasedConnectPool<T> {
|
||||
map.remove(Thread.currentThread());
|
||||
}
|
||||
|
||||
protected void afterInit(ObjectInPool oip, T value ){
|
||||
|
||||
}
|
||||
|
||||
private T setInitialValue() {
|
||||
T value = initialValue();
|
||||
map.put(Thread.currentThread(), new ObjectInPool<>(value));
|
||||
ObjectInPool opi = new ObjectInPool<>(value);
|
||||
map.put(Thread.currentThread(), opi);
|
||||
afterInit( opi , value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user