Search in sources :

Example 21 with ExchangeChannel

use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class ExchangeServerPeer method getExchangeChannel.

@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();
            }
        }
    }
    return channel;
}
Also used : ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) Map(java.util.Map) URL(org.apache.dubbo.common.URL)

Example 22 with ExchangeChannel

use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class NettyClientTest method main.

public static void main(String[] args) throws RemotingException, InterruptedException {
    ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty3&heartbeat=1000"));
    Thread.sleep(60 * 1000 * 50);
}
Also used : ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel)

Example 23 with ExchangeChannel

use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class ReplierDispatcherTest method testDataPackage.

@Test
public void testDataPackage() throws Exception {
    ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?" + CommonConstants.TIMEOUT_KEY + "=60000"));
    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("(").append(random.nextLong()).append(")");
        Data d = new Data();
        d.setData(sb.toString());
        Assertions.assertEquals(client.request(d).get().toString(), "hello world");
    }
    clients.put(Thread.currentThread().getName(), client);
}
Also used : Random(java.util.Random) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) Test(org.junit.jupiter.api.Test)

Aggregations

ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)23 Test (org.junit.jupiter.api.Test)12 HeaderExchangeHandler (org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)9 ExchangeHandlerAdapter (org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter)8 URL (org.apache.dubbo.common.URL)7 ByteBuf (io.netty.buffer.ByteBuf)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)6 IOException (java.io.IOException)6 Codec2 (org.apache.dubbo.remoting.Codec2)6 Request (org.apache.dubbo.remoting.exchange.Request)6 DecodeHandler (org.apache.dubbo.remoting.transport.DecodeHandler)6 MultiMessageHandler (org.apache.dubbo.remoting.transport.MultiMessageHandler)6 NettyCodecAdapter (org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter)6 Channel (org.apache.dubbo.remoting.Channel)5 RemotingException (org.apache.dubbo.remoting.RemotingException)4 Response (org.apache.dubbo.remoting.exchange.Response)4 ArrayList (java.util.ArrayList)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExchangeHandler (org.apache.dubbo.remoting.exchange.ExchangeHandler)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2