Search in sources :

Example 6 with Web3j

use of org.fisco.bcos.web3j.protocol.Web3j in project web3sdk by FISCO-BCOS.

the class StartGroup method main.

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        Usage();
    }
    int groupID = Integer.valueOf(args[0]);
    System.out.println(" Start Group operation, groupID: " + groupID);
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.setGroupId(1);
    service.run();
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    Web3j web3j = Web3j.build(channelEthereumService, 1);
    org.fisco.bcos.web3j.protocol.core.methods.response.StartGroup startGroup = web3j.startGroup(groupID).send();
    logger.info("  StartGroup result: {}", startGroup);
    System.out.println(" StartGroup result: " + startGroup.getStatus());
    System.exit(0);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)

Example 7 with Web3j

use of org.fisco.bcos.web3j.protocol.Web3j in project web3sdk by FISCO-BCOS.

the class BlockTxReceipts method init.

public Web3j init() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());
    return web3j;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)

Example 8 with Web3j

use of org.fisco.bcos.web3j.protocol.Web3j in project web3sdk by FISCO-BCOS.

the class GroupManager method init.

public Web3j init() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());
    return web3j;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)

Example 9 with Web3j

use of org.fisco.bcos.web3j.protocol.Web3j in project web3sdk by FISCO-BCOS.

the class GenerateGroup method main.

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        Usage();
    }
    int groupID = Integer.valueOf(args[0]);
    long timestamp = Long.valueOf(args[1]);
    List<String> nodes = new ArrayList<>();
    for (int i = 2; i < args.length; ++i) {
        nodes.add(args[i]);
    }
    System.out.println(" Generate Group operation, groupID: " + groupID + " ,timestamp: " + timestamp + " ,nodes: " + nodes);
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.setGroupId(1);
    service.run();
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    Web3j web3j = Web3j.build(channelEthereumService, 1);
    org.fisco.bcos.web3j.protocol.core.methods.response.GenerateGroup generateGroup = web3j.generateGroup(groupID, timestamp, false, nodes).send();
    logger.info("  generateGroup result: {}", generateGroup);
    System.out.println(" generateGroup result: " + generateGroup.getStatus());
    System.exit(0);
}
Also used : ArrayList(java.util.ArrayList) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 10 with Web3j

use of org.fisco.bcos.web3j.protocol.Web3j in project web3sdk by FISCO-BCOS.

the class PerfomanceTableRemove method main.

public static void main(String[] args) throws Exception {
    try {
        String groupId = args[3];
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Service service = context.getBean(Service.class);
        service.setGroupId(Integer.parseInt(groupId));
        service.run();
        System.out.println("Start test...");
        System.out.println("===================================================================");
        ChannelEthereumService channelEthereumService = new ChannelEthereumService();
        channelEthereumService.setChannelService(service);
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
        Web3j web3 = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId));
        Credentials credentials = Credentials.create("b83261efa42895c38c6c2364ca878f43e77f3cddbc922bf57d0d48070f79feb6");
        BigInteger gasPrice = new BigInteger("30000000");
        BigInteger gasLimit = new BigInteger("30000000");
        String command = args[0];
        Integer count = 0;
        Integer qps = 0;
        switch(command) {
            case "trans":
                count = Integer.parseInt(args[1]);
                qps = Integer.parseInt(args[2]);
                break;
            default:
                System.out.println("Args: <trans> <Total> <QPS>");
        }
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(200);
        threadPool.setMaxPoolSize(500);
        threadPool.setQueueCapacity(count);
        threadPool.initialize();
        System.out.println("Deploying contract...");
        TableTest tabletest = TableTest.deploy(web3, credentials, gasPrice, gasLimit).send();
        PerfomanceCollector collector = new PerfomanceCollector();
        collector.setTotal(count);
        RateLimiter limiter = RateLimiter.create(qps);
        Integer area = count / 10;
        final Integer total = count;
        Random random = new Random(System.currentTimeMillis());
        System.out.println("Start test,total:" + count);
        for (Integer i = 0; i < count; ++i) {
            threadPool.execute(new Runnable() {

                @Override
                public void run() {
                    limiter.acquire();
                    PerfomanceTableTestCallback callback = new PerfomanceTableTestCallback();
                    callback.setCollector(collector);
                    try {
                        long _id = getNextID();
                        Random r = new Random();
                        long l1 = r.nextLong();
                        tabletest.remove("fruit" + l1 % TableTestClient.modevalue, BigInteger.valueOf(_id), callback);
                    } catch (Exception e) {
                        TransactionReceipt receipt = new TransactionReceipt();
                        receipt.setStatus("-1");
                        callback.onResponse(receipt);
                        logger.error("Error sending:", e);
                    }
                    int current = sended.incrementAndGet();
                    if (current >= area && ((current % area) == 0)) {
                        System.out.println("Already sended: " + current + "/" + total + " transactions");
                    }
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) RateLimiter(com.google.common.util.concurrent.RateLimiter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) Random(java.util.Random) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Aggregations

Web3j (org.fisco.bcos.web3j.protocol.Web3j)18 Service (org.fisco.bcos.channel.client.Service)17 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)17 ApplicationContext (org.springframework.context.ApplicationContext)17 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)17 BigInteger (java.math.BigInteger)14 Credentials (org.fisco.bcos.web3j.crypto.Credentials)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)10 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 Random (java.util.Random)6 StaticGasProvider (org.fisco.bcos.web3j.tx.gas.StaticGasProvider)4 SecureRandom (java.security.SecureRandom)2 ECKeyPair (org.fisco.bcos.web3j.crypto.ECKeyPair)2 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)2 ContractGasProvider (org.fisco.bcos.web3j.tx.gas.ContractGasProvider)2 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1