Package com.alibaba.rocketmq.research.rpc

Examples of com.alibaba.rocketmq.research.rpc.RPCClient


*
* @author shijia.wxr<vintage.wang@gmail.com>
*/
public class Client {
    public static void main(String[] args) {
        RPCClient rpcClient = new DefaultRPCClient();
        boolean connectOK = rpcClient.connect(new InetSocketAddress("127.0.0.1", 2012), 1);
        System.out.println("connect server " + (connectOK ? "OK" : "Failed"));
        rpcClient.start();

        for (long i = 0;; i++) {
            try {
                String reqstr = "nice" + i;
                ByteBuffer repdata = rpcClient.call(reqstr.getBytes());
                if (repdata != null) {
                    String repstr =
                            new String(repdata.array(), repdata.position(), repdata.limit()
                                    - repdata.position());
                    System.out.println("call result, " + repstr);
View Full Code Here


        // thread pool
        final ThreadPoolExecutor executorSend = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadCnt);

        // rpcclient
        final RPCClient rpcClient = new DefaultRPCClient();
        final boolean connectOK =
                rpcClient.connect(new InetSocketAddress(remoteHost, remotePort), connectionCnt);
        System.out.println("connect server " + remoteHost + (connectOK ? " OK" : " Failed"));
        rpcClient.start();

        // status
        final byte[] message = buildMessage(messageSize);
        final AtomicLong callTimesOK = new AtomicLong(0);
        final AtomicLong callTimesFailed = new AtomicLong(0);

        // multi thread call
        for (int i = 0; i < threadCnt; i++) {
            executorSend.execute(new Runnable() {
                @Override
                public void run() {
                    while (true) {
                        try {
                            ByteBuffer repdata = rpcClient.call(message);
                            if (repdata != null) {
                                callTimesOK.incrementAndGet();
                            }
                            else {
                                callTimesFailed.incrementAndGet();
View Full Code Here

TOP

Related Classes of com.alibaba.rocketmq.research.rpc.RPCClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.