Search in sources :

Example 16 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class AbstractClient method removeAttribute.

@Override
public void removeAttribute(String key) {
    Channel channel = getChannel();
    if (channel == null) {
        return;
    }
    channel.removeAttribute(key);
}
Also used : Channel(org.apache.dubbo.remoting.Channel)

Example 17 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class AbstractTimerTask method run.

@Override
public void run(Timeout timeout) throws Exception {
    Collection<Channel> c = channelProvider.getChannels();
    for (Channel channel : c) {
        if (channel.isClosed()) {
            continue;
        }
        doTask(channel);
    }
    reput(timeout, tick);
}
Also used : Channel(org.apache.dubbo.remoting.Channel)

Example 18 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class TraceTelnetHandlerTest method testTraceTelnetAddTracer.

@Test
public void testTraceTelnetAddTracer() throws Exception {
    String method = "sayHello";
    String message = "org.apache.dubbo.qos.legacy.service.DemoService sayHello 1";
    Class<?> type = DemoService.class;
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    handler.telnet(mockChannel, message);
    String key = type.getName() + "." + method;
    Field tracers = TraceFilter.class.getDeclaredField("TRACERS");
    tracers.setAccessible(true);
    ConcurrentHashMap<String, Set<Channel>> map = (ConcurrentHashMap<String, Set<Channel>>) tracers.get(new ConcurrentHashMap<String, Set<Channel>>());
    Set<Channel> channels = map.getOrDefault(key, null);
    Assertions.assertNotNull(channels);
    Assertions.assertTrue(channels.contains(mockChannel));
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) Channel(org.apache.dubbo.remoting.Channel) DemoService(org.apache.dubbo.qos.legacy.service.DemoService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.jupiter.api.Test)

Example 19 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class ServerPeer method getChannel.

@Override
public Channel getChannel(InetSocketAddress remoteAddress) {
    String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName();
    int port = remoteAddress.getPort();
    Channel channel = super.getChannel(remoteAddress);
    if (channel == null) {
        for (Map.Entry<URL, Client> entry : clients.entrySet()) {
            URL url = entry.getKey();
            if (url.getIp().equals(host) && url.getPort() == port) {
                return entry.getValue();
            }
        }
    }
    return channel;
}
Also used : Channel(org.apache.dubbo.remoting.Channel) Client(org.apache.dubbo.remoting.Client) Map(java.util.Map) URL(org.apache.dubbo.common.URL)

Example 20 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class NettyTransporterTest method shouldConnectToNetty4Server.

@Test
public void shouldConnectToNetty4Server() throws Exception {
    final CountDownLatch lock = new CountDownLatch(1);
    int port = NetUtils.getAvailablePort();
    URL url = new URL("telnet", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
    new NettyTransporter().bind(url, new ChannelHandlerAdapter() {

        @Override
        public void connected(Channel channel) {
            lock.countDown();
        }
    });
    new NettyTransporter().connect(url, new ChannelHandlerAdapter() {

        @Override
        public void sent(Channel channel, Object message) throws RemotingException {
            channel.send(message);
            channel.close();
        }
    });
    lock.await();
}
Also used : ChannelHandlerAdapter(org.apache.dubbo.remoting.transport.ChannelHandlerAdapter) Channel(org.apache.dubbo.remoting.Channel) RemotingException(org.apache.dubbo.remoting.RemotingException) CountDownLatch(java.util.concurrent.CountDownLatch) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

Channel (org.apache.dubbo.remoting.Channel)53 Test (org.junit.jupiter.api.Test)32 Request (org.apache.dubbo.remoting.exchange.Request)18 ChannelBuffer (org.apache.dubbo.remoting.buffer.ChannelBuffer)16 Response (org.apache.dubbo.remoting.exchange.Response)12 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)9 URL (org.apache.dubbo.common.URL)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 HeaderExchangeHandler (org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)6 RemotingException (org.apache.dubbo.remoting.RemotingException)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ExchangeHandler (org.apache.dubbo.remoting.exchange.ExchangeHandler)4 MockedChannel (org.apache.dubbo.remoting.handler.MockedChannel)4 AppResponse (org.apache.dubbo.rpc.AppResponse)4 Demo (org.apache.dubbo.rpc.gen.thrift.Demo)4 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)4 TMessage (org.apache.thrift.protocol.TMessage)4 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)4 IOException (java.io.IOException)3