Search in sources :

Example 1 with BftsmartServiceProxyPool

use of com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool 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;
}
Also used : ReconfigureReply(bftsmart.reconfiguration.ReconfigureReply) BftsmartServiceProxyPool(com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool) BftsmartReplica(com.jd.blockchain.consensus.bftsmart.BftsmartReplica) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) Reconfiguration(bftsmart.reconfiguration.Reconfiguration)

Example 2 with BftsmartServiceProxyPool

use of com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool in project jdchain-core by blockchain-jd-com.

the class BftsmartConsensusManageService method removeNode.

@Override
public AsyncFuture<ConsensusView> removeNode(Replica replica) {
    BftsmartServiceProxyPool serviceProxyPool = getServiceProxyPool();
    CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
    AsynchServiceProxy serviceProxy = null;
    try {
        serviceProxy = serviceProxyPool.borrowObject();
        Reconfiguration reconfiguration = new Reconfiguration(serviceProxy.getProcessId(), serviceProxy);
        reconfiguration.removeServer(replica.getId());
        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;
}
Also used : ReconfigureReply(bftsmart.reconfiguration.ReconfigureReply) BftsmartServiceProxyPool(com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) Reconfiguration(bftsmart.reconfiguration.Reconfiguration)

Aggregations

Reconfiguration (bftsmart.reconfiguration.Reconfiguration)2 ReconfigureReply (bftsmart.reconfiguration.ReconfigureReply)2 AsynchServiceProxy (bftsmart.tom.AsynchServiceProxy)2 BftsmartServiceProxyPool (com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool)2 ConsensusView (com.jd.blockchain.consensus.manage.ConsensusView)2 CompletableAsyncFuture (utils.concurrent.CompletableAsyncFuture)2 BftsmartReplica (com.jd.blockchain.consensus.bftsmart.BftsmartReplica)1