Search in sources :

Example 1 with AsynchServiceProxy

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);
}
Also used : ViewStorage(bftsmart.reconfiguration.views.ViewStorage) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) Random(java.util.Random) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) View(bftsmart.reconfiguration.views.View) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

Example 2 with AsynchServiceProxy

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;
}
Also used : BftsmartTopology(com.jd.blockchain.consensus.bftsmart.BftsmartTopology) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) View(bftsmart.reconfiguration.views.View) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork)

Example 3 with AsynchServiceProxy

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();
    }
}
Also used : AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy)

Example 4 with AsynchServiceProxy

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;
}
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 5 with AsynchServiceProxy

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;
}
Also used : ViewObsoleteException(utils.exception.ViewObsoleteException) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) ViewObsoleteException(utils.exception.ViewObsoleteException)

Aggregations

AsynchServiceProxy (bftsmart.tom.AsynchServiceProxy)7 CompletableAsyncFuture (utils.concurrent.CompletableAsyncFuture)4 Reconfiguration (bftsmart.reconfiguration.Reconfiguration)2 ReconfigureReply (bftsmart.reconfiguration.ReconfigureReply)2 TOMConfiguration (bftsmart.reconfiguration.util.TOMConfiguration)2 MemoryBasedViewStorage (bftsmart.reconfiguration.views.MemoryBasedViewStorage)2 View (bftsmart.reconfiguration.views.View)2 BftsmartServiceProxyPool (com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool)2 ConsensusView (com.jd.blockchain.consensus.manage.ConsensusView)2 ViewObsoleteException (utils.exception.ViewObsoleteException)2 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)1 ViewStorage (bftsmart.reconfiguration.views.ViewStorage)1 BftsmartReplica (com.jd.blockchain.consensus.bftsmart.BftsmartReplica)1 BftsmartTopology (com.jd.blockchain.consensus.bftsmart.BftsmartTopology)1 Random (java.util.Random)1