org.fisco.bcos.channel.dto.ChannelPush Java Examples

The following examples show how to use org.fisco.bcos.channel.dto.ChannelPush. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AMOPSubscription.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
@Override
public void onPush(ChannelPush push) {
    if (!this.subTopics.containsKey(push.getTopic())) {
        log.error("unknown topic on channel, {} -> {}", push.getTopic(), this.subTopics.keySet());
        push.sendResponse(toChannelResponse(ErrorCode.UNKNOWN_ERROR));
        return;
    }
    IConsumer.ConsumerListener consumerListener = this.subTopics.get(push.getTopic());

    WeEvent event;
    try {
        event = JsonHelper.json2Object(push.getContent2(), WeEvent.class);
    } catch (BrokerException e) {
        log.error("invalid WeEvent on channel", e);
        push.sendResponse(toChannelResponse(e));
        return;
    }

    log.info("received WeEvent on channel, {}", event);
    ChannelResponse channelResponse = toChannelResponse(ErrorCode.SUCCESS);

    consumerListener.onEvent(event.getTopic(), event);
    push.sendResponse(channelResponse);
}
 
Example #2
Source File: DBHandler.java    From amdb-proxy with Apache License 2.0 6 votes vote down vote up
@Override
public void onPush(ChannelPush push) {
	Integer resultCode = 0;
	
	String resultData = "";
	
	try {
		resultData = dbService.process(push.getContent());
	} catch (Exception e) {
		resultCode = -1;
		logger.error("Process request error", e);
	}
	
	//construct back to the package
	ChannelResponse response = new ChannelResponse();
	response.setMessageID(push.getMessageID());
	response.setErrorCode(resultCode);
	response.setErrorMessage("");
	response.setContent(resultData);
	
	logger.debug("Send response: {}", response.getContent());
	
	push.sendResponse(response);
}
 
Example #3
Source File: PushCallback2.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void onPush(ChannelPush push) {
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    logger.debug("push:" + push.getContent());
    System.out.println(df.format(LocalDateTime.now()) + "server:push:" + push.getContent());

    ChannelResponse response = new ChannelResponse();
    response.setContent("receive request seq:" + String.valueOf(push.getMessageID()));
    response.setErrorCode(0);

    push.sendResponse(response);
}
 
Example #4
Source File: ChannelPushCallback.java    From web3sdk with Apache License 2.0 votes vote down vote up
public abstract void onPush(ChannelPush push);