Search in sources :

Example 6 with ExchangeChannel

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

the class HeaderExchangeHandler method connected.

@Override
public void connected(Channel channel) throws RemotingException {
    ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
    handler.connected(exchangeChannel);
}
Also used : ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel)

Example 7 with ExchangeChannel

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

the class HeaderExchangeHandler method disconnected.

@Override
public void disconnected(Channel channel) throws RemotingException {
    ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
    try {
        handler.disconnected(exchangeChannel);
    } finally {
        DefaultFuture.closeChannel(channel);
        HeaderExchangeChannel.removeChannel(channel);
    }
}
Also used : ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel)

Example 8 with ExchangeChannel

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

the class HeaderExchangeHandler method sent.

@Override
public void sent(Channel channel, Object message) throws RemotingException {
    Throwable exception = null;
    try {
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        handler.sent(exchangeChannel, message);
    } catch (Throwable t) {
        exception = t;
        HeaderExchangeChannel.removeChannelIfDisconnected(channel);
    }
    if (message instanceof Request) {
        Request request = (Request) message;
        DefaultFuture.sent(channel, request);
    }
    if (exception != null) {
        if (exception instanceof RuntimeException) {
            throw (RuntimeException) exception;
        } else if (exception instanceof RemotingException) {
            throw (RemotingException) exception;
        } else {
            throw new RemotingException(channel.getLocalAddress(), channel.getRemoteAddress(), exception.getMessage(), exception);
        }
    }
}
Also used : RemotingException(org.apache.dubbo.remoting.RemotingException) Request(org.apache.dubbo.remoting.exchange.Request) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel)

Example 9 with ExchangeChannel

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

the class PortTelnetHandler method telnet.

@Override
public String telnet(Channel channel, String message) {
    StringBuilder buf = new StringBuilder();
    String port = null;
    boolean detail = false;
    if (message.length() > 0) {
        String[] parts = message.split("\\s+");
        for (String part : parts) {
            if ("-l".equals(part)) {
                detail = true;
            } else {
                if (!StringUtils.isInteger(part)) {
                    return "Illegal port " + part + ", must be integer.";
                }
                port = part;
            }
        }
    }
    if (port == null || port.length() == 0) {
        for (ProtocolServer server : DubboProtocol.getDubboProtocol().getServers()) {
            if (buf.length() > 0) {
                buf.append("\r\n");
            }
            if (detail) {
                buf.append(server.getUrl().getProtocol()).append("://").append(server.getUrl().getAddress());
            } else {
                buf.append(server.getUrl().getPort());
            }
        }
    } else {
        int p = Integer.parseInt(port);
        ProtocolServer protocolServer = null;
        for (ProtocolServer s : DubboProtocol.getDubboProtocol().getServers()) {
            if (p == s.getUrl().getPort()) {
                protocolServer = s;
                break;
            }
        }
        if (protocolServer != null) {
            ExchangeServer server = (ExchangeServer) protocolServer.getRemotingServer();
            Collection<ExchangeChannel> channels = server.getExchangeChannels();
            for (ExchangeChannel c : channels) {
                if (buf.length() > 0) {
                    buf.append("\r\n");
                }
                if (detail) {
                    buf.append(c.getRemoteAddress()).append(" -> ").append(c.getLocalAddress());
                } else {
                    buf.append(c.getRemoteAddress());
                }
            }
        } else {
            buf.append("No such port ").append(port);
        }
    }
    return buf.toString();
}
Also used : ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel)

Example 10 with ExchangeChannel

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

the class NettyClientTest method testClientClose.

@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:" + port + "?client=netty3"));
        Thread.sleep(5);
        clients.add(client);
    }
    for (ExchangeChannel client : clients) {
        client.close();
    }
    Thread.sleep(1000);
}
Also used : ArrayList(java.util.ArrayList) 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