Search in sources :

Example 1 with AbstractChannel

use of com.alipay.sofa.rpc.transport.AbstractChannel in project sofa-rpc by sofastack.

the class ServerConfigTest method testAll.

@Test
public void testAll() {
    ServerConfig config = new ServerConfig();
    config.setProtocol("bolt").setHost("127.0.0.2").setPort(54321).setContextPath("/").setIoThreads(4).setThreadPoolType("fixed").setCoreThreads(20).setMaxThreads(200).setTelnet(false).setQueueType("priority").setQueues(1024).setAliveTime(30000).setPreStartCore(true).setAccepts(30000).setPayload(10 * 1024 * 1024).setSerialization("protobuf").setDispatcher("message").setParameters(Collections.singletonMap("app", "app")).setVirtualHost("192.168.1.1").setVirtualPort(12345).setOnConnect(Arrays.<ChannelListener>asList(new ChannelListener() {

        @Override
        public void onConnected(AbstractChannel channel) {
        }

        @Override
        public void onDisconnected(AbstractChannel channel) {
        }
    })).setEpoll(true).setDaemon(false).setAdaptivePort(true).setTransport("netty").setAutoStart(true).setStopTimeout(10000).setKeepAlive(true);
    Assert.assertEquals("bolt", config.getProtocol());
    Assert.assertEquals("127.0.0.2", config.getHost());
    Assert.assertEquals(54321, config.getPort());
    Assert.assertEquals("/", config.getContextPath());
    Assert.assertEquals(4, config.getIoThreads());
    Assert.assertEquals("fixed", config.getThreadPoolType());
    Assert.assertEquals(20, config.getCoreThreads());
    Assert.assertEquals(200, config.getMaxThreads());
    Assert.assertEquals(false, config.isTelnet());
    Assert.assertEquals("priority", config.getQueueType());
    Assert.assertEquals(1024, config.getQueues());
    Assert.assertEquals(30000, config.getAliveTime());
    Assert.assertEquals(true, config.isPreStartCore());
    Assert.assertEquals(30000, config.getAccepts());
    Assert.assertEquals(10 * 1024 * 1024, config.getPayload());
    Assert.assertEquals("protobuf", config.getSerialization());
    Assert.assertEquals("message", config.getDispatcher());
    Assert.assertEquals(1, config.getParameters().size());
    Assert.assertEquals("app", config.getParameters().get("app"));
    Assert.assertEquals("192.168.1.1", config.getVirtualHost());
    Assert.assertEquals(12345, (int) config.getVirtualPort());
    Assert.assertEquals(1, config.getOnConnect().size());
    Assert.assertEquals(true, config.isEpoll());
    Assert.assertEquals(false, config.isDaemon());
    Assert.assertEquals(true, config.isAdaptivePort());
    Assert.assertEquals("netty", config.getTransport());
    Assert.assertEquals(true, config.isAutoStart());
    Assert.assertEquals(10000, config.getStopTimeout());
    Assert.assertEquals(true, config.isKeepAlive());
    Assert.assertTrue(config.toString().contains("bolt"));
}
Also used : ChannelListener(com.alipay.sofa.rpc.listener.ChannelListener) AbstractChannel(com.alipay.sofa.rpc.transport.AbstractChannel) Test(org.junit.Test)

Example 2 with AbstractChannel

use of com.alipay.sofa.rpc.transport.AbstractChannel in project sofa-rpc by sofastack.

the class NettyHelper method getChannel.

public static AbstractChannel getChannel(ChannelHandlerContext ctx) {
    Attribute<AbstractChannel> attr = ctx.channel().attr(CHANNEL_KEY);
    AbstractChannel sofaChannel = attr.get();
    if (sofaChannel == null) {
        sofaChannel = new NettyChannel(ctx);
        AbstractChannel old = attr.setIfAbsent(sofaChannel);
        if (old != null) {
            sofaChannel = old;
        }
    }
    return sofaChannel;
}
Also used : AbstractChannel(com.alipay.sofa.rpc.transport.AbstractChannel)

Aggregations

AbstractChannel (com.alipay.sofa.rpc.transport.AbstractChannel)2 ChannelListener (com.alipay.sofa.rpc.listener.ChannelListener)1 Test (org.junit.Test)1