Search in sources :

Example 26 with Service

use of org.fisco.bcos.channel.client.Service 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 27 with Service

use of org.fisco.bcos.channel.client.Service 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 28 with Service

use of org.fisco.bcos.channel.client.Service 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 29 with Service

use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.

the class Channel2Server method main.

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Param: topic");
        return;
    }
    String topic = args[0];
    logger.debug("init Server");
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    Set<String> topics = new HashSet<String>();
    topics.add(topic);
    service.setTopics(topics);
    PushCallback cb = new PushCallback();
    service.setPushCallback(cb);
    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("===================================================================");
    service.run();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.fisco.bcos.channel.client.Service) HashSet(java.util.HashSet)

Example 30 with Service

use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.

the class Channel2ServerUpdateTopics method main.

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Param: topic");
        return;
    }
    String topic = args[0];
    logger.debug("init Server");
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    PushCallback cb = new PushCallback();
    service.setPushCallback(cb);
    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("===================================================================");
    service.run();
    Thread.sleep(10000);
    System.out.println("set topics");
    System.out.println("===================================================================");
    Set<String> topics = new HashSet<String>();
    topics.add(topic);
    service.setTopics(topics);
    service.updateTopicsToNode();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.fisco.bcos.channel.client.Service) HashSet(java.util.HashSet)

Aggregations

Service (org.fisco.bcos.channel.client.Service)34 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)34 ApplicationContext (org.springframework.context.ApplicationContext)33 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)23 Web3j (org.fisco.bcos.web3j.protocol.Web3j)17 BigInteger (java.math.BigInteger)13 Credentials (org.fisco.bcos.web3j.crypto.Credentials)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)10 RateLimiter (com.google.common.util.concurrent.RateLimiter)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)9 DateTimeFormatter (java.time.format.DateTimeFormatter)8 ChannelRequest (org.fisco.bcos.channel.dto.ChannelRequest)8 Random (java.util.Random)6 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)5 ChannelResponse (org.fisco.bcos.channel.dto.ChannelResponse)4 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)4 SecureRandom (java.security.SecureRandom)2 HashSet (java.util.HashSet)2