Search in sources :

Example 1 with ExtendMessage

use of com.jd.blockchain.consensus.mq.event.ExtendMessage in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4MQ method submitNodeStateChangeTx.

@Override
public TransactionResponse submitNodeStateChangeTx(ParticipantContext context, int activeID, TransactionRequest txRequest, List<NodeSettings> origConsensusNodes) {
    TxResponseMessage responseMessage = new TxResponseMessage();
    DefaultMessageTransmitter mqClient = null;
    try {
        // 初始化区块队列
        initBlockQueue(context, activeID);
        // 发送拓扑变更消息,通知领导者推送落块消息
        mqClient = createMQClient(context);
        ExtendMessage extendMessage = new ExtendMessage(MessageType.RECONFIGURE, null);
        AsyncFuture<byte[]> msgFuture = mqClient.sendUnordered(MessageConvertor.serializeExtendMessage(extendMessage));
        byte[] result = msgFuture.get(MQ_INVOKE_TIMEOUT, TimeUnit.MILLISECONDS);
        if (result == null) {
            responseMessage.setExecutionState(TransactionState.TIMEOUT);
        } else {
            ExtendMessageResult messageResult = MessageConvertor.convertBytesExtendMessageResult(result);
            if (!messageResult.isSuccess()) {
                LOGGER.error("extend message execute error: {}", messageResult.getError());
                responseMessage.setExecutionState(TransactionState.CONSENSUS_ERROR);
            } else {
                // 发送激活交易
                AsyncFuture<byte[]> txFuture = mqClient.sendOrdered(BinaryProtocol.encode(txRequest, TransactionRequest.class));
                result = txFuture.get(MQ_INVOKE_TIMEOUT, TimeUnit.MILLISECONDS);
                if (result == null) {
                    responseMessage.setExecutionState(TransactionState.TIMEOUT);
                    return responseMessage;
                }
                return BinaryProtocol.decode(result);
            }
        }
    } catch (Exception e) {
        LOGGER.error("message or tx execute error", e);
        responseMessage.setExecutionState(TransactionState.CONSENSUS_ERROR);
    } finally {
        if (null != mqClient) {
            mqClient.close();
        }
    }
    return responseMessage;
}
Also used : DefaultMessageTransmitter(com.jd.blockchain.consensus.mq.client.DefaultMessageTransmitter) TxResponseMessage(com.jd.blockchain.transaction.TxResponseMessage) ExtendMessage(com.jd.blockchain.consensus.mq.event.ExtendMessage) ExtendMessageResult(com.jd.blockchain.consensus.mq.event.ExtendMessageResult)

Aggregations

DefaultMessageTransmitter (com.jd.blockchain.consensus.mq.client.DefaultMessageTransmitter)1 ExtendMessage (com.jd.blockchain.consensus.mq.event.ExtendMessage)1 ExtendMessageResult (com.jd.blockchain.consensus.mq.event.ExtendMessageResult)1 TxResponseMessage (com.jd.blockchain.transaction.TxResponseMessage)1