Java Code Examples for org.fisco.bcos.channel.client.Service#asyncMulticastChannelMessage2()

The following examples show how to use org.fisco.bcos.channel.client.Service#asyncMulticastChannelMessage2() . 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: Channel2ClientMulti.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example 2
Source File: Channel2ClientMultiBin.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
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);
    }
}