Package com.alibaba.dubbo.remoting.exchange

Examples of com.alibaba.dubbo.remoting.exchange.ExchangeChannel


    }

    public void connected(Channel channel) throws RemotingException {
        channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
        channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            handler.connected(exchangeChannel);
        } finally {
            HeaderExchangeChannel.removeChannelIfDisconnected(channel);
        }
View Full Code Here


    }

    public void disconnected(Channel channel) throws RemotingException {
        channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
        channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            handler.disconnected(exchangeChannel);
        } finally {
            HeaderExchangeChannel.removeChannelIfDisconnected(channel);
        }
View Full Code Here

    public void sent(Channel channel, Object message) throws RemotingException {
        Throwable exception = null;
        try {
            channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
            ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
            try {
                handler.sent(exchangeChannel, message);
            } finally {
                HeaderExchangeChannel.removeChannelIfDisconnected(channel);
            }
View Full Code Here

                    .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
    }

    public void received(Channel channel, Object message) throws RemotingException {
        channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            if (message instanceof Request) {
                // handle request.
                Request request = (Request) message;
                if (request.isEvent()) {
View Full Code Here

                    channel.send(res);
                    return;
                }
            }
        }
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            handler.caught(exchangeChannel, exception);
        } finally {
            HeaderExchangeChannel.removeChannelIfDisconnected(channel);
        }
View Full Code Here

    @Test
    public void testClientClose() throws Exception {
        List<ExchangeChannel> clients = new ArrayList<ExchangeChannel>(100);
        for (int i = 0; i < 100; i++) {
            ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://localhost:10001?client=netty"));
            Thread.sleep(5);
            clients.add(client);
        }
        for (ExchangeChannel client : clients){
            client.close();
        }
        Thread.sleep(1000);
    }
View Full Code Here

    Exchangers.bind(URL.valueOf("dubbo://localhost:" + port), dispatcher);
  }

  static void dataPackageTest(int port) throws Exception
  {
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
    Random random = new Random();
    for(int i=5;i<100;i++)
    {
      StringBuilder sb = new StringBuilder();
      for(int j=0;j<i*100;j++)
        sb.append("("+random.nextLong()+")");
      Main.Data d = new Main.Data();
      d.setData(sb.toString());
      client.request(d).get();
    }
    System.out.println("send finished.");
  }
View Full Code Here

      });
  }

  private static void test(int port) throws Exception
  {
      ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
    MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get();
    System.out.println("55+25="+result.getResult());

    for(int i=0;i<100;i++)
      client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i}));

    for(int i=0;i<100;i++)
      client.request(new Main.Data());

    System.out.println("=====test invoke=====");
    for(int i=0;i<100;i++){
      ResponseFuture future = client.request(new Main.Data());
      System.out.println("invoke and get");
      System.out.println("invoke result:" + future.get());
    }
    System.out.println("=====the end=====");
  }
View Full Code Here

                server.close();
        } finally {}
    }
   
    public static void main(String[] args) throws RemotingException, InterruptedException {
      ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty&heartbeat=1000"));
      Thread.sleep(60*1000*50);
  }
 
View Full Code Here

    @Override
    public ExchangeChannel getExchangeChannel(InetSocketAddress remoteAddress) {
        String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName();
        int port = remoteAddress.getPort();
        ExchangeChannel channel = super.getExchangeChannel(remoteAddress);
        if (channel == null) {
            for (Map.Entry<URL, ExchangeClient> entry : clients.entrySet()) {
                URL url = entry.getKey();
                if (url.getIp().equals(host) && url.getPort() == port) {
                    return entry.getValue();
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.remoting.exchange.ExchangeChannel

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.