Examples of RpcClient


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

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

        // 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

Examples of com.chenshuo.muduo.protorpc.RpcClient

import com.google.protobuf.RpcCallback;

public class Client {

    private static void blockingConnect(InetSocketAddress addr) throws Exception {
        RpcClient client = new RpcClient();
        RpcChannel channel = client.blockingConnect(addr);
        //sendRequest(channel, client);
        SudokuService.BlockingInterface remoteService = SudokuProto.SudokuService.newBlockingStub(channel);
        SudokuRequest request = SudokuRequest.newBuilder().setCheckerboard("001010").build();
        SudokuResponse response = remoteService.solve(null, request);
        System.out.println(response);
        channel.disconnect();
        client.stop();
    }
View Full Code Here

Examples of com.rabbitmq.client.RpcClient

            ConnectionFactory cfconn = new ConnectionFactory();
            cfconn.setUri(uri);
            Connection conn = cfconn.newConnection();
            Channel ch = conn.createChannel();
            RpcClient service = new RpcClient(ch, "", "Hello");

            System.out.println(service.stringCall(request));
            conn.close();
        } catch (Exception e) {
            System.err.println("Main thread caught exception: " + e);
            e.printStackTrace();
            System.exit(1);
View Full Code Here

Examples of com.youtube.vitess.vtgate.rpcclient.RpcClient

   * @throws ConnectionException
   */
  public static VtGate connect(String addresses, int timeoutMs) throws ConnectionException {
    List<String> addressList = Arrays.asList(addresses.split(","));
    int index = new Random().nextInt(addressList.size());
    RpcClient client = RpcClientFactory.get(addressList.get(index), timeoutMs);
    return new VtGate(client);
  }
View Full Code Here

Examples of muduo.rpc.RpcClient

import com.google.protobuf.RpcCallback;

public class Client {

    private static void blockingConnect(InetSocketAddress addr) throws Exception {
        RpcClient client = new RpcClient();
        RpcChannel channel = client.blockingConnect(addr);
        //sendRequest(channel, client);
        BlockingInterface remoteService = Sudoku.SudokuService.newBlockingStub(channel);
        SudokuRequest request = SudokuRequest.newBuilder().setCheckerboard("001010").build();
        SudokuResponse response = remoteService.solve(null, request);
        System.out.println(response);
        channel.disconnect();
        client.stop();
    }
View Full Code Here

Examples of muduo.rpc.RpcClient

        client.stop();
    }

    @SuppressWarnings("unused")
    private static void asyncConnect(InetSocketAddress addr) {
        final RpcClient client = new RpcClient();
        client.registerService(Sudoku.SudokuService.newReflectiveService(new SudokuImpl()));
        client.startConnect(addr, new NewChannelCallback() {
            @Override
            public void run(RpcChannel channel) {
                sendAsyncRequest(channel, client);
            }
        });
View Full Code Here

Examples of muduo.rpc.RpcClient

        }

        @Override
        public void run() {
            System.out.println(Thread.currentThread());
            RpcClient client = new RpcClient(channelFactory);
            RpcChannel channel = client.blockingConnect(serverAddr);
            BlockingInterface remoteService = EchoService.newBlockingStub(channel);
            String payload = new String(new byte[100]);
            payload = "Hello";
            EchoRequest request = EchoRequest.newBuilder().setPayload(payload).build();
View Full Code Here

Examples of muduo.rpc.RpcClient

        private String payload;
        private int nPipelines = 1;
        private int count = 0;

        public AsyncClient(ChannelFactory channelFactory, SocketAddress server) {
            this.client = new RpcClient(channelFactory);
            this.serverAddr = server;

            payload = new String(new byte[100]);
            // payload = "Hello";
            request = EchoRequest.newBuilder().setPayload(payload).build();
View Full Code Here

Examples of org.apache.flume.api.RpcClient

  private void run() throws IOException, FlumeException,
      EventDeliveryException {

    LineReader reader = null;

    RpcClient rpcClient = RpcClientFactory.getDefaultInstance(hostname, port,
        BATCH_SIZE);
    try {
      if (fileName != null) {
        reader = new BufferedLineReader(new FileReader(new File(fileName)));
      } else if (dirName != null) {
        reader = new SpoolingFileLineReader(new File(dirName), ".COMPLETED",
            BATCH_SIZE, MAX_LINE_LENGTH);
      }
      else {
        reader = new BufferedLineReader(new InputStreamReader(System.in));
      }


      long lastCheck = System.currentTimeMillis();
      long sentBytes = 0;

      int batchSize = rpcClient.getBatchSize();
      List<String> lines = Lists.newLinkedList();
      while (!(lines = reader.readLines(batchSize)).isEmpty()) {
        List<Event> eventBuffer = Lists.newArrayList();
        for (String line : lines) {
          Event event = EventBuilder.withBody(line, Charsets.UTF_8);
          setHeaders(event);
          eventBuffer.add(event);
          sentBytes += event.getBody().length;
          sent++;

          long now = System.currentTimeMillis();
          if (now >= lastCheck + 5000) {
            logger.debug("Packed {} bytes, {} events", sentBytes, sent);
            lastCheck = now;
          }
        }
        rpcClient.appendBatch(eventBuffer);
      }
      logger.debug("Finished");
    } finally {
      if (reader != null) {
        logger.debug("Closing reader");
        reader.close();
      }

      logger.debug("Closing RPC client");
      rpcClient.close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.