check修改
This commit is contained in:
parent
d6003c4d76
commit
1806fa8153
@ -5,6 +5,7 @@ import com.sunyard.proto.Util;
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import com.sunyard.util.SYMUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.codehaus.groovy.util.LockableObject;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -18,8 +19,8 @@ public class SydApi4Database implements SydApi {
|
||||
static {
|
||||
SydApi.SYD_SetLogConfig("./logs/", 0);
|
||||
}
|
||||
|
||||
private SydApi4j[] hsms = null;
|
||||
|
||||
private boolean isShortLinkMode = false;
|
||||
|
||||
public SydApi4Database() {
|
||||
@ -27,8 +28,10 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
public SydApi4Database(SydApi4j[] hsms) {
|
||||
synchronized (this){
|
||||
this.hsms = hsms;
|
||||
}
|
||||
}
|
||||
|
||||
public SydApi4j[] getHsms() {
|
||||
return hsms;
|
||||
@ -44,7 +47,6 @@ public class SydApi4Database implements SydApi {
|
||||
if (pcIpList.length != iPortList.length) {
|
||||
throw new IllegalArgumentException("ip与端口数量不一致");
|
||||
}
|
||||
|
||||
SydApi4j[] apis = new SydApi4j[pcIpList.length];
|
||||
int iDealTimeOut = allDealTimeOut / pcIpList.length;
|
||||
boolean connected = false;
|
||||
@ -73,11 +75,14 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public void SYD_Disconnect_Ex() {
|
||||
|
||||
if (isShortLinkMode) {
|
||||
if (null == hsms) {
|
||||
return;
|
||||
}
|
||||
|
||||
LockableObject lockableObject = new LockableObject();
|
||||
try {
|
||||
lockableObject.lock();
|
||||
for (int i = 0; i < hsms.length; i++) {
|
||||
SydApi4j api = hsms[i];
|
||||
if (null != api) {
|
||||
@ -89,6 +94,13 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
|
||||
}
|
||||
finally {
|
||||
lockableObject.unlock();
|
||||
}
|
||||
}
|
||||
// 配合链接池,不再需要释放。
|
||||
|
||||
|
||||
@ -105,6 +117,10 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
SydApiException le = null;
|
||||
//加锁
|
||||
LockableObject lockableObject = new LockableObject();
|
||||
lockableObject.lock();
|
||||
try {
|
||||
for (SydApi4j api : this.hsms) {
|
||||
|
||||
if (null == api) {
|
||||
@ -124,6 +140,14 @@ public class SydApi4Database implements SydApi {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
|
||||
}
|
||||
finally {
|
||||
lockableObject.unlock();
|
||||
}
|
||||
|
||||
throw le;
|
||||
}
|
||||
|
||||
|
||||
@ -58,28 +58,38 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
||||
}
|
||||
|
||||
// 保活接口
|
||||
protected boolean check(SydApi4Database o) {
|
||||
// if (null == o) {
|
||||
// return false;
|
||||
// }
|
||||
public boolean check(SydApi s) {
|
||||
SydApi4Database o=(SydApi4Database)s;
|
||||
Lock l = new ReentrantLock();
|
||||
try {
|
||||
l.lock();
|
||||
SydApi4j[] hsms = o.getHsms();
|
||||
l.unlock();
|
||||
boolean ifBoolean = false;
|
||||
int length = hsms.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (null != hsms[i]) {
|
||||
try {
|
||||
l.lock();
|
||||
o.SYD_SM3_Hash_ShortData(new byte[8]);
|
||||
ifBoolean = true;
|
||||
} catch (Exception e) {
|
||||
// 忽略
|
||||
hsms[i] = null;
|
||||
}
|
||||
finally {
|
||||
l.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ifBoolean;
|
||||
|
||||
}
|
||||
catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
l.unlock();
|
||||
}
|
||||
}
|
||||
// 释放
|
||||
protected void free(SydApi o) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user