连接池
This commit is contained in:
parent
24161e2ad5
commit
fdadf11c93
@ -1,6 +1,6 @@
|
||||
package com.sunyard;
|
||||
|
||||
|
||||
import com.sunyard.inf.cryption.*;
|
||||
import com.sunyard.inf.*;
|
||||
import com.sunyard.inf.customize.Syd4DigitalEnvelope;
|
||||
import com.sunyard.inf.customize.SydHAApi;
|
||||
@ -13,7 +13,7 @@ import racal.sunyard.main.SydApiBuilder;
|
||||
* 程序调用接口
|
||||
*/
|
||||
public interface SydApi extends
|
||||
SydRawApi, SydCertApi, SydCryptionApi, SydGenApi,
|
||||
SydRawApi, SydCertApi, SydGenApi, SydSYMApi, SydASYMApi, SydHashApi,
|
||||
SydSVApi, SydHAApi, SydQNUCApi, SydPledge, SydPINOpt,
|
||||
SydManufactureApi, SydZYOption, SydUnionPayApi ,Syd4DigitalEnvelope{
|
||||
|
||||
|
||||
@ -126,14 +126,6 @@ public interface SydCertApi {
|
||||
RetWrap importCert(byte[] certData, byte[] organizationId);
|
||||
|
||||
|
||||
/**
|
||||
* 从加密设备中删除指定 DN 的公钥证书
|
||||
* @param dn:传入的证书
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean deleteCert(String dn);
|
||||
|
||||
/**
|
||||
* 从加密设备中删除指定 DN 的公钥证书
|
||||
* @param dn:传入的证书
|
||||
|
||||
@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class ThreadBasedConnectPool<T> {
|
||||
|
||||
// ThreadLocal
|
||||
private final Map<Thread, ObjectInPool<T>> map = new HashMap<>();
|
||||
private final Map<Thread, ObjectInPool<T>> map = new HashMap<Thread, ObjectInPool<T>>();
|
||||
|
||||
// 守护
|
||||
private final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(1);
|
||||
@ -18,7 +18,7 @@ public class ThreadBasedConnectPool<T> {
|
||||
// 配置
|
||||
private PoolConfig config;
|
||||
|
||||
public ThreadBasedConnectPool(PoolConfig config) {
|
||||
public ThreadBasedConnectPool(final PoolConfig config) {
|
||||
this.config = config;
|
||||
threadPool.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
@ -103,7 +103,7 @@ public class ThreadBasedConnectPool<T> {
|
||||
|
||||
// 设置
|
||||
public void set(T o) {
|
||||
map.put(Thread.currentThread(), new ObjectInPool<>(o));
|
||||
map.put(Thread.currentThread(), new ObjectInPool<T>(o));
|
||||
}
|
||||
|
||||
// 清除
|
||||
@ -117,7 +117,7 @@ public class ThreadBasedConnectPool<T> {
|
||||
|
||||
private T setInitialValue() {
|
||||
T value = initialValue();
|
||||
ObjectInPool opi = new ObjectInPool<>(value);
|
||||
ObjectInPool opi = new ObjectInPool<T>(value);
|
||||
map.put(Thread.currentThread(), opi);
|
||||
afterInit( opi , value);
|
||||
return value;
|
||||
|
||||
@ -2,6 +2,8 @@ package com.sunyard.proxy;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.log.ILogFactory;
|
||||
import com.sunyard.log.ILogger;
|
||||
import com.sunyard.pool.HsmLinkInfo;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiMuti;
|
||||
@ -144,6 +146,13 @@ public class ProxyInvocationHandler implements InvocationHandler {
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
} catch ( Exception e ) {
|
||||
ILogFactory factory = SydApi4j.getLogFactory();
|
||||
if ( null != factory ) {
|
||||
ILogger logger = factory.getLogger(ProxyInvocationHandler.class);
|
||||
logger.error( "调用方法 {} 失败", method.getName() );
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,8 @@ public class SydApi4j implements SydApi {
|
||||
private int readTimeout;
|
||||
private int retryWhenNetError = 0;
|
||||
|
||||
private Object bindObject = null;
|
||||
|
||||
//初始化变量
|
||||
static {
|
||||
|
||||
@ -10473,6 +10475,16 @@ public class SydApi4j implements SydApi {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBindObject() {
|
||||
return bindObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBindObject(Object bindObject) {
|
||||
this.bindObject = bindObject;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String SYMEncrytByKeyIndex(String index, String intPutData) {
|
||||
|
||||
@ -2,11 +2,8 @@ package sample;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.Assert;
|
||||
import racal.sunyard.main.SydApiPoolBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
||||
/**
|
||||
* 集群模式 - 长连接
|
||||
@ -19,29 +16,31 @@ public class HSMPoolLongLink {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接
|
||||
String[] pcipList = {"172.16.18.59","192.168.0.200"};
|
||||
int[] iportList = {8889,8889};
|
||||
final String[] pcipList = {"172.16.18.59", "192.168.0.200"};
|
||||
final int[] iportList = {8889, 8889};
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int tmp = i;
|
||||
new Thread(() -> {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SydApiPoolBuilder builder = new SydApiPoolBuilder(pcipList, iportList, 10, 1000);
|
||||
SydApi api = builder.build();
|
||||
try {
|
||||
for (int j = 0; j < 20; j++) {
|
||||
byte[] data = api.SM3Hash("test".getBytes(StandardCharsets.UTF_8));
|
||||
byte[] data = api.SM3Hash("test".getBytes());
|
||||
System.out.println("hex=" + Util.bytes2HexString(data));
|
||||
// boolean sign = api.deleteCert("C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1");
|
||||
// System.out.println(sign);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (null != api) {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, i + "t").start();
|
||||
}
|
||||
System.out.println(1);
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApiClusterBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
||||
/**
|
||||
* 集群模式 - 短连接
|
||||
@ -19,13 +16,15 @@ public class HSMPoolShortLink {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接
|
||||
String[] pcipList = {"172.16.18.59", "192.168.0.200"};
|
||||
int[] iportList = {8889, 8889};
|
||||
final String[] pcipList = {"172.16.18.59", "192.168.0.200"};
|
||||
final int[] iportList = {8889, 8889};
|
||||
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int tmp = i;
|
||||
new Thread(() -> {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SydApi api = SydApiClusterBuilder.SYD_Short_Connect_Ex(
|
||||
pcipList,
|
||||
iportList,
|
||||
@ -33,7 +32,7 @@ public class HSMPoolShortLink {
|
||||
1000);
|
||||
try {
|
||||
for (int j = 0; j < 20; j++) {
|
||||
byte[] data = api.SM3Hash("test".getBytes(StandardCharsets.UTF_8));
|
||||
byte[] data = api.SM3Hash("test".getBytes());
|
||||
System.out.println("hex=" + Util.bytes2HexString(data));
|
||||
// boolean sign = api.deleteCert("C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1");
|
||||
// System.out.println(sign);
|
||||
@ -46,7 +45,8 @@ public class HSMPoolShortLink {
|
||||
api.disconnect();
|
||||
}
|
||||
}
|
||||
}, i + "t").start();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user