use of org.fisco.bcos.channel.dto.ChannelPush2 in project web3sdk by FISCO-BCOS.
the class Service method onReceiveChannelMessage2.
public void onReceiveChannelMessage2(ChannelHandlerContext ctx, ChannelMessage2 message) {
ChannelResponseCallback2 callback = (ChannelResponseCallback2) seq2Callback.get(message.getSeq());
if (message.getType() == ChannelMessageType.AMOP_REQUEST.getType() || message.getType() == ChannelMessageType.AMOP_MULBROADCAST.getType()) {
logger.debug("channel PUSH");
if (callback != null) {
logger.debug("seq already existed,clear:{}", message.getSeq());
seq2Callback.remove(message.getSeq());
}
if (message.getTopic().length() > verifyChannelPrefix.length() && verifyChannelPrefix.equals(message.getTopic().substring(0, verifyChannelPrefix.length()))) {
try {
signForAmop(ctx, message);
} catch (IOException e) {
logger.error("sign for amop failed:{}", e);
}
} else {
try {
ChannelPush2 push = new ChannelPush2();
if (pushCallback != null) {
// pushCallback.setInfo(info);
push.setSeq(message.getSeq());
push.setService(this);
push.setCtx(ctx);
push.setTopic(message.getTopic());
push.setSeq(message.getSeq());
push.setMessageID(message.getSeq());
logger.debug("msg:{}", Arrays.toString(message.getData()));
push.setContent(message.getData());
pushCallback.onPush(push);
} else {
logger.error("can not push,unset push callback");
}
} catch (Exception e) {
logger.error("push error:{}", e);
}
}
} else if (message.getType() == ChannelMessageType.AMOP_RESPONSE.getType()) {
logger.debug("channel message:{}", message.getSeq());
if (callback != null) {
logger.debug("found callback response");
ChannelResponse response = new ChannelResponse();
if (message.getResult() != 0) {
response.setErrorMessage("response errors");
}
// over bandwidth limit
if (message.getResult() == ChannelMessageError.REJECT_AMOP_REQ_FOR_OVER_BANDWIDTHLIMIT.getError()) {
logger.error("AMOP request was rejected due to over bandwidth limit, message: {}", message.getSeq());
response.setErrorMessage("AMOP request was rejected due to over bandwidth limit");
}
response.setErrorCode(message.getResult());
response.setMessageID(message.getSeq());
if (message.getData() != null) {
response.setContent(message.getData());
}
callback.onResponse(response);
} else {
logger.error("can not found response callback,timeout:{}", message.getData());
return;
}
}
}
Aggregations