use of bftsmart.tom.AsynchServiceProxy in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method createClient.
/**
* 准备共识客户端
*/
public void createClient(int nodeNum) {
TOMConfiguration config = loadClientConfig(nodeNum);
latestView = new View(0, config.getInitialView(), config.getF(), addresses.toArray(new NodeNetwork[addresses.size()]));
ViewStorage viewStorage = new MemoryBasedViewStorage(latestView);
clientProxy = new AsynchServiceProxy(config, viewStorage);
Random random = new Random();
bytes = new byte[4];
random.nextBytes(bytes);
}
use of bftsmart.tom.AsynchServiceProxy in project jdchain-core by blockchain-jd-com.
the class BftsmartPeerProxyFactory method create.
@Override
public AsynchServiceProxy create() throws Exception {
BftsmartTopology topology = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTopology());
View view = topology.getView();
if (view == null) {
throw new IllegalStateException("No topology view in the bftsmart client settings!");
}
MemoryBasedViewStorage viewStorage = new MemoryBasedViewStorage(view);
TOMConfiguration tomConfiguration = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTomConfig());
// every proxy client has unique id;
int processId = allocateId();
tomConfiguration.setProcessId(processId);
AsynchServiceProxy peerProxy = new AsynchServiceProxy(tomConfiguration, viewStorage, bftsmartClientSettings.getSSLSecurity());
if (LOGGER.isInfoEnabled()) {
// 打印view
int[] processes = view.getProcesses();
NodeNetwork[] addresses = new NodeNetwork[processes.length];
for (int i = 0; i < addresses.length; i++) {
addresses[i] = view.getAddress(processes[i]);
}
LOGGER.info("Creating pooled bftsmart client ... [PooledClientID={}] [ViewID={}] [ViewTopology={}] [Peers={}]", processId, view.getId(), Arrays.toString(processes), Arrays.toString(addresses));
}
return peerProxy;
}
use of bftsmart.tom.AsynchServiceProxy in project jdchain-core by blockchain-jd-com.
the class BftsmartPeerProxyFactory method destroyObject.
// when close pool, destroy its object
@Override
public void destroyObject(PooledObject<AsynchServiceProxy> p) throws Exception {
super.destroyObject(p);
AsynchServiceProxy serviceProxy = p.getObject();
if (serviceProxy != null) {
recycleId(serviceProxy.getProcessId());
serviceProxy.close();
}
}
use of bftsmart.tom.AsynchServiceProxy in project jdchain-core by blockchain-jd-com.
the class BftsmartConsensusManageService method addNode.
@Override
public AsyncFuture<ConsensusView> addNode(Replica replica) {
BftsmartServiceProxyPool serviceProxyPool = getServiceProxyPool();
BftsmartReplica bftsmartReplica = (BftsmartReplica) replica;
CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
AsynchServiceProxy serviceProxy = null;
try {
serviceProxy = serviceProxyPool.borrowObject();
Reconfiguration reconfiguration = new Reconfiguration(serviceProxy.getProcessId(), serviceProxy);
reconfiguration.addServer(bftsmartReplica.getId(), bftsmartReplica.getNetworkAddress());
ReconfigureReply reply = reconfiguration.execute();
asyncFuture.complete(new BftsmartView(reply.getView()));
} catch (Exception e) {
asyncFuture.error(e);
} finally {
if (serviceProxy != null) {
serviceProxyPool.returnObject(serviceProxy);
}
}
return asyncFuture;
}
use of bftsmart.tom.AsynchServiceProxy in project jdchain-core by blockchain-jd-com.
the class BftsmartMessageService method sendOrderedMessage.
private AsyncFuture<byte[]> sendOrderedMessage(byte[] message) {
BftsmartServiceProxyPool asyncPeerProxyPool = getServiceProxyPool();
CompletableAsyncFuture<byte[]> asyncFuture = new CompletableAsyncFuture<>();
AsynchServiceProxy asynchServiceProxy = null;
try {
asynchServiceProxy = asyncPeerProxyPool.borrowObject();
byte[] result = asynchServiceProxy.invokeOrdered(message);
asyncFuture.complete(result);
} catch (ViewObsoleteException voe) {
throw voe;
} catch (Exception e) {
asyncFuture.error(e);
throw new RuntimeException(e);
} finally {
if (asynchServiceProxy != null) {
asyncPeerProxyPool.returnObject(asynchServiceProxy);
}
}
return asyncFuture;
}
Aggregations