Search in sources :

Example 6 with ChannelRequest

use of org.fisco.bcos.channel.dto.ChannelRequest 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());
            }
        }
    });
}
Also used : EventLogRequestParams(org.fisco.bcos.channel.event.filter.EventLogRequestParams) ChannelRequest(org.fisco.bcos.channel.dto.ChannelRequest) EventLogPushCallback(org.fisco.bcos.channel.event.filter.EventLogPushCallback) ChannelResponse(org.fisco.bcos.channel.dto.ChannelResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EventLogFilterPushResponse(org.fisco.bcos.channel.event.filter.EventLogFilterPushResponse) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 7 with ChannelRequest

use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.

the class Channel2ClientBin method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.out.println("param: target topic filename of request");
        return;
    }
    String topic = args[0];
    String filename = args[1];
    Integer count = 1;
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    logger.debug("init client");
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    System.out.println("3s ...");
    Thread.sleep(1000);
    System.out.println("2s ...");
    Thread.sleep(1000);
    System.out.println("1s ...");
    Thread.sleep(1000);
    System.out.println("start test");
    System.out.println("===================================================================");
    for (Integer i = 0; i < count; ++i) {
        Thread.sleep(2000);
        ChannelRequest request = new ChannelRequest();
        request.setToTopic(topic);
        request.setMessageID(service.newSeq());
        request.setTimeout(5000);
        /*设置为-128表示为传输二进制*/
        int flag = -128;
        byte[] byteflag = intToByteArray(flag);
        int filelength = filename.length();
        byte[] bytelength = intToByteArray(filelength);
        byte[] bytefilename = filename.getBytes();
        byte[] contentfile = toByteArrFromFile(filename);
        byte[] content = byteCat(byteCat(byteCat(byteflag, bytelength), bytefilename), contentfile);
        request.setContent(content);
        logger.info("msg:" + Arrays.toString(content));
        System.out.println(df.format(LocalDateTime.now()) + " request seq:" + String.valueOf(request.getMessageID()) + " content length:" + content.length);
        ChannelResponse response = service.sendChannelMessage2(request);
        System.out.println(df.format(LocalDateTime.now()) + "response seq:" + String.valueOf(response.getMessageID()) + ", ErrorCode:" + response.getErrorCode() + ", Content:" + response.getContent());
        if (response.getErrorCode() != 0) {
            System.out.println("Error message" + response.getErrorMessage());
        }
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ChannelRequest(org.fisco.bcos.channel.dto.ChannelRequest) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.fisco.bcos.channel.client.Service) ChannelResponse(org.fisco.bcos.channel.dto.ChannelResponse) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 8 with ChannelRequest

use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.

the class Channel2ClientMulti method main.

public static void main(String[] args) throws Exception {
    if (args.length < parameterNum) {
        System.out.println("param: target topic total number of request");
        return;
    }
    String topic = args[0];
    Integer count = Integer.parseInt(args[1]);
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    logger.debug("init client");
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    System.out.println("3s ...");
    Thread.sleep(1000);
    System.out.println("2s ...");
    Thread.sleep(1000);
    System.out.println("1s ...");
    Thread.sleep(1000);
    System.out.println("start test");
    System.out.println("===================================================================");
    for (Integer i = 0; i < count; ++i) {
        Thread.sleep(2000);
        ChannelRequest request = new ChannelRequest();
        request.setToTopic(topic);
        request.setMessageID(service.newSeq());
        request.setTimeout(5000);
        request.setContent("request seq:" + request.getMessageID());
        System.out.println(df.format(LocalDateTime.now()) + " multicast request seq:" + String.valueOf(request.getMessageID()) + ", Content:" + request.getContent());
        service.asyncMulticastChannelMessage2(request);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ChannelRequest(org.fisco.bcos.channel.dto.ChannelRequest) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.fisco.bcos.channel.client.Service) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 9 with ChannelRequest

use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.

the class Channel2ClientMultiBinNeedVerify method main.

public static void main(String[] args) throws Exception {
    if (args.length < parameterNum) {
        System.out.println("param: target topic total number of request");
        return;
    }
    String topic = args[0];
    Integer count = 10;
    String filename = args[1];
    int flag = -128;
    byte[] byteflag = Channel2ClientBin.intToByteArray(flag);
    int filelength = filename.length();
    byte[] bytelength = Channel2ClientBin.intToByteArray(filelength);
    byte[] bytefilename = filename.getBytes();
    byte[] contentfile = Channel2ClientBin.toByteArrFromFile(filename);
    byte[] content = Channel2ClientBin.byteCat(Channel2ClientBin.byteCat(Channel2ClientBin.byteCat(byteflag, bytelength), bytefilename), contentfile);
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    logger.debug("init client");
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    System.out.println("3s ...");
    Thread.sleep(1000);
    System.out.println("2s ...");
    Thread.sleep(1000);
    System.out.println("1s ...");
    Thread.sleep(1000);
    System.out.println("start test");
    System.out.println("===================================================================");
    for (Integer i = 0; i < count; ++i) {
        Thread.sleep(2000);
        ChannelRequest request = new ChannelRequest();
        request.setToTopic(topic);
        request.setMessageID(service.newSeq());
        request.setTimeout(5000);
        request.setContent(content);
        System.out.println(df.format(LocalDateTime.now()) + " multicast request seq:" + String.valueOf(request.getMessageID()) + ", filename:" + filename);
        service.asyncMulticastChannelMessageForVerifyTopic(request);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ChannelRequest(org.fisco.bcos.channel.dto.ChannelRequest) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.fisco.bcos.channel.client.Service) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 10 with ChannelRequest

use of org.fisco.bcos.channel.dto.ChannelRequest in project web3sdk by FISCO-BCOS.

the class Channel2ClientMultiBin method main.

public static void main(String[] args) throws Exception {
    if (args.length < parameterNum) {
        System.out.println("param: target topic total number of request");
        return;
    }
    String topic = args[0];
    Integer count = 1;
    String filename = args[1];
    int flag = -128;
    byte[] byteflag = Channel2ClientBin.intToByteArray(flag);
    int filelength = filename.length();
    byte[] bytelength = Channel2ClientBin.intToByteArray(filelength);
    byte[] bytefilename = filename.getBytes();
    byte[] contentfile = Channel2ClientBin.toByteArrFromFile(filename);
    byte[] content = Channel2ClientBin.byteCat(Channel2ClientBin.byteCat(Channel2ClientBin.byteCat(byteflag, bytelength), bytefilename), contentfile);
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    logger.debug("init client");
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    System.out.println("3s ...");
    Thread.sleep(1000);
    System.out.println("2s ...");
    Thread.sleep(1000);
    System.out.println("1s ...");
    Thread.sleep(1000);
    System.out.println("start test");
    System.out.println("===================================================================");
    for (Integer i = 0; i < count; ++i) {
        Thread.sleep(2000);
        ChannelRequest request = new ChannelRequest();
        request.setToTopic(topic);
        request.setMessageID(service.newSeq());
        request.setTimeout(5000);
        request.setContent(content);
        System.out.println(df.format(LocalDateTime.now()) + " multicast request seq:" + String.valueOf(request.getMessageID()) + ", filename:" + filename);
        service.asyncMulticastChannelMessage2(request);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ChannelRequest(org.fisco.bcos.channel.dto.ChannelRequest) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.fisco.bcos.channel.client.Service) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

ChannelRequest (org.fisco.bcos.channel.dto.ChannelRequest)11 DateTimeFormatter (java.time.format.DateTimeFormatter)8 Service (org.fisco.bcos.channel.client.Service)8 ApplicationContext (org.springframework.context.ApplicationContext)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 ChannelResponse (org.fisco.bcos.channel.dto.ChannelResponse)6 IOException (java.io.IOException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 CertificateException (java.security.cert.CertificateException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 EventLogFilterPushResponse (org.fisco.bcos.channel.event.filter.EventLogFilterPushResponse)1 EventLogPushCallback (org.fisco.bcos.channel.event.filter.EventLogPushCallback)1 EventLogRequestParams (org.fisco.bcos.channel.event.filter.EventLogRequestParams)1 NodeRequestSdkVerifyTopic (org.fisco.bcos.channel.protocol.NodeRequestSdkVerifyTopic)1 SdkRequestNodeUpdateTopicStatus (org.fisco.bcos.channel.protocol.SdkRequestNodeUpdateTopicStatus)1