use of org.fisco.bcos.channel.event.filter.EventLogRequestParams in project web3sdk by FISCO-BCOS.
the class Service method asyncSendRegisterEventLogFilterMessage.
/**
* @param filter
*/
public void asyncSendRegisterEventLogFilterMessage(EventLogFilter filter) {
ChannelRequest request = new ChannelRequest();
request.setMessageID(newSeq());
request.setToTopic("");
request.setType((short) ChannelMessageType.CLIENT_REGISTER_EVENT_LOG.getType());
EventLogRequestParams params = new EventLogRequestParams(filter.generateNewParams(), String.valueOf(getGroupId()), newSeq());
logger.info(" registerID: {}, filterID: {}, params: {}", filter.getRegisterID(), filter.getFilterID(), params);
try {
request.setContent(params.toJsonString());
} catch (JsonProcessingException e1) {
filter.getCallback().onPushEventLog(EventLogFilterPushStatus.INVALID_PARAMS.getStatus(), null);
eventLogFilterManager.removeFilter(filter.getRegisterID());
return;
}
final String filterID = params.getFilterID();
final String registerID = filter.getRegisterID();
filter.setFilterID(filterID);
final EventLogPushCallback callback0 = filter.getCallback();
// register callback
eventLogFilterManager.addCallback(params.getFilterID(), filter.getCallback());
asyncSendChannelMessage2(request, new ChannelResponseCallback2() {
@Override
public void onResponseMessage(ChannelResponse response) {
logger.info(" event filter callback response, registerID: {}, filterID: {}, seq: {}, error code: {}, content: {}", registerID, filterID, response.getMessageID(), response.getErrorCode(), response.getContent());
try {
if (0 == response.getErrorCode()) {
// receive response successfully
EventLogFilterPushResponse resp = ObjectMapperFactory.getObjectMapper().readValue(response.getContent(), EventLogFilterPushResponse.class);
if (resp.getResult() == 0) {
// node response ok, event log will be pushed soon
eventLogFilterManager.updateEventLogFilter(callback0.getFilter(), EventLogFilterStatus.EVENT_LOG_PUSHING, response.getCtx());
} else {
// node response not ok, callback to client
callback0.onPushEventLog(resp.getResult(), null);
eventLogFilterManager.removeFilterAndCallback(registerID, filterID);
}
} else {
// register request send failed, waiting to be re-sent
eventLogFilterManager.updateEventLogFilter(callback0.getFilter(), EventLogFilterStatus.WAITING_REQUEST, null);
// remove register callback
eventLogFilterManager.removeCallback(filterID);
}
} catch (Exception e) {
callback0.onPushEventLog(EventLogFilterPushStatus.OTHER_ERROR.getStatus(), null);
eventLogFilterManager.removeFilterAndCallback(filter.getRegisterID(), filterID);
logger.error(" event filter response message exception, filterID: {}, registerID: {}, exception message: {}", filterID, registerID, e.getMessage());
}
}
});
}
Aggregations