use of com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings in project jdchain-core by blockchain-jd-com.
the class GatewayQueryServiceHandler method consensusSettingsDecorator.
private ConsensusViewSettings consensusSettingsDecorator(ConsensusViewSettings consensusSettings) {
if (consensusSettings instanceof BftsmartConsensusViewSettings) {
// bft-smart单独处理
BftsmartConsensusViewSettings bftsmartConsensusSettings = (BftsmartConsensusViewSettings) consensusSettings;
NodeSettings[] nodes = bftsmartConsensusSettings.getNodes();
BftsmartNodeSettings[] bftsmartNodes = null;
if (nodes != null && nodes.length > 0) {
bftsmartNodes = new BftsmartNodeSettings[nodes.length];
for (int i = 0; i < nodes.length; i++) {
NodeSettings node = nodes[i];
if (node instanceof BftsmartNodeSettings) {
BftsmartNodeSettings bftsmartNodeSettings = (BftsmartNodeSettings) node;
bftsmartNodes[i] = new BftsmartNodeConfig(bftsmartNodeSettings.getPubKey(), bftsmartNodeSettings.getId(), bftsmartNodeSettings.getNetworkAddress());
}
}
}
return new BftsmartConsensusConfig(bftsmartNodes, bftsmartConsensusSettings.getSystemConfigs(), 0);
} else if (consensusSettings instanceof RaftConsensusSettings) {
RaftConsensusSettings raftConsensusSettings = (RaftConsensusSettings) consensusSettings;
NodeSettings[] nodes = raftConsensusSettings.getNodes();
RaftNodeSettings[] raftNodeSettings = new RaftNodeSettings[0];
if (nodes != null && nodes.length > 0) {
raftNodeSettings = new RaftNodeSettings[nodes.length];
for (int i = 0; i < nodes.length; i++) {
NodeSettings node = nodes[i];
if (node instanceof RaftNodeSettings) {
RaftNodeSettings raftNodeSetting = (RaftNodeSettings) node;
raftNodeSettings[i] = new RaftNodeConfig(raftNodeSetting.getId(), raftNodeSetting.getAddress(), raftNodeSetting.getPubKey(), raftNodeSetting.getNetworkAddress());
}
}
}
RaftConsensusConfig raftConsensusConfig = new RaftConsensusConfig();
RaftConfig raftConfig = new RaftConfig();
RaftNetworkConfig raftNetworkConfig = new RaftNetworkConfig();
BeanUtils.copyProperties(raftConsensusSettings, raftConsensusConfig);
BeanUtils.copyProperties(raftConsensusSettings.getRaftSettings(), raftConfig);
BeanUtils.copyProperties(raftConsensusSettings.getNetworkSettings(), raftNetworkConfig);
raftConsensusConfig.setNodeSettingsList(Arrays.asList(raftNodeSettings));
raftConsensusConfig.setRaftSettings(raftConfig);
raftConsensusConfig.setNetworkSettings(raftNetworkConfig);
return raftConsensusConfig;
} else if (consensusSettings instanceof MsgQueueConsensusSettings) {
MsgQueueConsensusSettings mqConsensusSettings = (MsgQueueConsensusSettings) consensusSettings;
MsgQueueConsensusConfig mqConsensusConfig = new MsgQueueConsensusConfig();
MsgQueueBlockSettings blockSettings = mqConsensusSettings.getBlockSettings();
MsgQueueBlockConfig mqQueueBlockConfig = new MsgQueueBlockConfig();
mqQueueBlockConfig.setMaxDelayMilliSecondsPerBlock(blockSettings.getMaxDelayMilliSecondsPerBlock());
mqQueueBlockConfig.setTxSizePerBlock(blockSettings.getTxSizePerBlock());
mqConsensusConfig.setBlockSettings(mqQueueBlockConfig);
MsgQueueNetworkSettings networkSettings = mqConsensusSettings.getNetworkSettings();
MsgQueueNetworkConfig mqQueueNetworkConfig = new MsgQueueNetworkConfig();
mqQueueNetworkConfig.setBlockTopic(networkSettings.getBlockTopic());
mqQueueNetworkConfig.setMsgResultTopic(networkSettings.getMsgResultTopic());
mqQueueNetworkConfig.setMsgTopic(networkSettings.getMsgTopic());
mqQueueNetworkConfig.setServer(networkSettings.getServer());
mqQueueNetworkConfig.setTxTopic(networkSettings.getTxTopic());
mqQueueNetworkConfig.setTxResultTopic(networkSettings.getTxResultTopic());
mqConsensusConfig.setNetworkSettings(mqQueueNetworkConfig);
for (int i = 0; i < mqConsensusSettings.getNodes().length; i++) {
MsgQueueNodeSettings nodeSettings = (MsgQueueNodeSettings) mqConsensusSettings.getNodes()[i];
MsgQueueNodeConfig msgQueueNodeConfig = new MsgQueueNodeConfig();
msgQueueNodeConfig.setAddress(nodeSettings.getAddress());
msgQueueNodeConfig.setPubKey(nodeSettings.getPubKey());
msgQueueNodeConfig.setId(nodeSettings.getId());
mqConsensusConfig.addNodeSettings(msgQueueNodeConfig);
}
return mqConsensusConfig;
}
return consensusSettings;
}
use of com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings in project jdchain-core by blockchain-jd-com.
the class MsgQueueConsensusConfig method getSystemConfigs.
@Override
public Property[] getSystemConfigs() {
MsgQueueNetworkSettings networkSettings = getNetworkSettings();
MsgQueueBlockSettings blockSettings = getBlockSettings();
Property[] properties = new Property[8];
properties[0] = new Property("system.msg.queue.server", networkSettings.getServer());
properties[1] = new Property("system.msg.queue.topic.tx", networkSettings.getTxTopic());
properties[2] = new Property("system.msg.queue.topic.tx-result", networkSettings.getTxResultTopic());
properties[3] = new Property("system.msg.queue.topic.msg", networkSettings.getMsgTopic());
properties[4] = new Property("system.msg.queue.topic.msg-result", networkSettings.getMsgResultTopic());
properties[5] = new Property("system.msg.queue.topic.block", networkSettings.getBlockTopic());
properties[6] = new Property("system.msg.queue.block.txsize", String.valueOf(blockSettings.getTxSizePerBlock()));
properties[7] = new Property("system.msg.queue.block.maxdelay", String.valueOf(blockSettings.getMaxDelayMilliSecondsPerBlock()));
return properties;
}
use of com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings in project jdchain-core by blockchain-jd-com.
the class MsgQueueConsensusSettingsBuilder method convertToProperties.
@Override
public Properties convertToProperties(ConsensusViewSettings settings) {
Properties props = new Properties();
if (!(settings instanceof MsgQueueConsensusSettings)) {
throw new IllegalArgumentException("ConsensusSettings data isn't supported! Accept MsgQueueConsensusSettings only!");
}
MsgQueueConsensusSettings consensusSettings = (MsgQueueConsensusSettings) settings;
MsgQueueNetworkSettings networkSettings = consensusSettings.getNetworkSettings();
if (networkSettings == null || networkSettings.getServer() == null || networkSettings.getServer().length() <= 0) {
throw new IllegalArgumentException("MsgQueue Consensus server is empty!");
}
String server = networkSettings.getServer();
props.setProperty(MSG_QUEUE_SERVER, server);
String txTopic = networkSettings.getTxTopic();
if (txTopic == null || txTopic.length() <= 0) {
txTopic = DEFAULT_TOPIC_TX;
}
props.setProperty(MSG_QUEUE_TOPIC_TX, txTopic);
String txResultTopic = networkSettings.getTxResultTopic();
if (txResultTopic == null || txResultTopic.length() <= 0) {
txResultTopic = DEFAULT_TOPIC_TX_RESULT;
}
props.setProperty(MSG_QUEUE_TOPIC_TX_RESULT, txResultTopic);
String blockTopic = networkSettings.getBlockTopic();
if (blockTopic == null || blockTopic.length() <= 0) {
blockTopic = DEFAULT_TOPIC_BLOCK;
}
props.setProperty(MSG_QUEUE_TOPIC_BLOCK, blockTopic);
String msgTopic = networkSettings.getMsgTopic();
if (msgTopic == null || msgTopic.length() <= 0) {
msgTopic = DEFAULT_TOPIC_MSG;
}
props.setProperty(MSG_QUEUE_TOPIC_MSG, msgTopic);
String msgResultTopic = networkSettings.getMsgResultTopic();
if (msgResultTopic == null || msgResultTopic.length() <= 0) {
msgResultTopic = DEFAULT_TOPIC_MSG_RESULT;
}
props.setProperty(MSG_QUEUE_TOPIC_MSG_RESULT, msgResultTopic);
MsgQueueBlockSettings blockSettings = consensusSettings.getBlockSettings();
if (blockSettings == null) {
props.setProperty(MSG_QUEUE_BLOCK_TXSIZE, DEFAULT_TXSIZE + "");
props.setProperty(MSG_QUEUE_BLOCK_MAXDELAY, DEFAULT_MAXDELAY + "");
} else {
int txSize = blockSettings.getTxSizePerBlock();
long maxDelay = blockSettings.getMaxDelayMilliSecondsPerBlock();
props.setProperty(MSG_QUEUE_BLOCK_TXSIZE, txSize + "");
props.setProperty(MSG_QUEUE_BLOCK_MAXDELAY, maxDelay + "");
}
NodeSettings[] nodes = consensusSettings.getNodes();
props.setProperty(SERVER_NUM_KEY, nodes.length + "");
for (int i = 0; i < nodes.length; i++) {
props.setProperty(nodeKey(PUBKEY_PATTERN, i), nodes[i].getPubKey().toString());
}
return props;
}
Aggregations