修改连接逻辑

This commit is contained in:
junj2.liang
2022-09-09 17:16:22 +08:00
parent bc886998c7
commit 3ed721b788
4 changed files with 64 additions and 24 deletions
@@ -166,6 +166,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -230,7 +233,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -304,6 +309,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -371,6 +379,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -453,7 +464,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -521,6 +534,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -589,6 +605,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -676,6 +695,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -746,6 +768,9 @@ public class SydApiBaseFunction implements SydApi {
}
}
}
if ( ! this.isShortLinkMode ) {
this.oip.setError();
}
throw le;
}
@@ -11,11 +11,12 @@ import org.apache.logging.log4j.Logger;
import racal.sunyard.main.SydApi4j;
public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
private HsmLinkInfo[] linkInfos;
static {
LogFactory.createLogger("./logs", 0);
}
public SydApiPool(HsmLinkInfo[] linkInfos) {
super();
this.linkInfos = linkInfos;
@@ -23,7 +24,7 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
// 继承 初始化
protected SydApi initialValue() {
Logger log = LogFactory.getLogger();
// 所有加密机一次性链接
SydApi4j[] apis = new SydApi4j[linkInfos.length];
@@ -40,15 +41,12 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
);
connected = true;
} catch (Exception e) {
Logger log = LogFactory.getLogger();
// 忽略单个错误
log.error("网络连接错误 {} {} - 忽略", info.getPcIp(), info.getiPort());
}
}
if (!connected) {
throw new SydApiException("连接错误", -1);
}
if (!connected) { throw new SydApiException("连接错误", -1); }
return new SydApiBaseFunction(apis, linkInfos);
@@ -56,7 +54,7 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
// 保活接口
public boolean check(SydApi s) {
if( !(s instanceof SydApi4Database) ) {
if (!(s instanceof SydApi4Database)) {
return false;
}
@@ -84,7 +82,7 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
try {
hsms[i] = (SydApi4j) new SydApi4j().connect(info.getPcIp(), info.getiPort(), null, info.getiConnectTimeOut(), info.getiDealTimeOut());
canUse = true;
} catch ( Exception e ) {
} catch (Exception e) {
}
}
@@ -99,19 +97,19 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
// 释放
protected void free(SydApi o) {
if (null != o) {
if (o instanceof SydApi4Database) {
((SydApi4Database) o).SYD_Disconnect();
if (o instanceof SydApiBaseFunction) {
((SydApiBaseFunction) o).SYD_Disconnect();
}
}
}
protected void afterInit(ObjectInPool oip, SydApi value ){
if ( !( value instanceof SydApi4Database ) ) {
protected void afterInit(ObjectInPool oip, SydApi value) {
if (!(value instanceof SydApiBaseFunction)) {
return;
}
SydApi4Database api = (SydApi4Database) value;
api.setOip( oip );
SydApiBaseFunction api = (SydApiBaseFunction) value;
api.setOip(oip);
}
}