Search in sources :

Example 76 with Channel

use of io.netty.channel.Channel in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClientManageProcessorTest method processRequest_UnRegisterProducer.

@Test
public void processRequest_UnRegisterProducer() throws Exception {
    brokerController.getProducerManager().registerProducer(group, clientChannelInfo);
    HashMap<Channel, ClientChannelInfo> channelMap = brokerController.getProducerManager().getGroupChannelTable().get(group);
    assertThat(channelMap).isNotNull();
    assertThat(channelMap.get(channel)).isEqualTo(clientChannelInfo);
    RemotingCommand request = createUnRegisterProducerCommand();
    RemotingCommand response = clientManageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    channelMap = brokerController.getProducerManager().getGroupChannelTable().get(group);
    assertThat(channelMap).isNull();
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) Channel(io.netty.channel.Channel) Test(org.junit.Test)

Example 77 with Channel

use of io.netty.channel.Channel in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PullMessageProcessorTest method init.

@Before
public void init() {
    brokerController.setMessageStore(messageStore);
    pullMessageProcessor = new PullMessageProcessor(brokerController);
    Channel mockChannel = mock(Channel.class);
    when(mockChannel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(handlerContext.channel()).thenReturn(mockChannel);
    brokerController.getTopicConfigManager().getTopicConfigTable().put(topic, new TopicConfig());
    clientChannelInfo = new ClientChannelInfo(mockChannel);
    ConsumerData consumerData = createConsumerData(group, topic);
    brokerController.getConsumerManager().registerConsumer(consumerData.getGroupName(), clientChannelInfo, consumerData.getConsumeType(), consumerData.getMessageModel(), consumerData.getConsumeFromWhere(), consumerData.getSubscriptionDataSet(), false);
}
Also used : ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) ConsumerData(org.apache.rocketmq.common.protocol.heartbeat.ConsumerData) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) TopicConfig(org.apache.rocketmq.common.TopicConfig) Before(org.junit.Before)

Example 78 with Channel

use of io.netty.channel.Channel in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class SendMessageProcessorTest method init.

@Before
public void init() {
    brokerController.setMessageStore(messageStore);
    when(messageStore.now()).thenReturn(System.currentTimeMillis());
    Channel mockChannel = mock(Channel.class);
    when(mockChannel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(handlerContext.channel()).thenReturn(mockChannel);
    when(messageStore.lookMessageByOffset(anyLong())).thenReturn(new MessageExt());
    sendMessageProcessor = new SendMessageProcessor(brokerController);
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) Before(org.junit.Before)

Example 79 with Channel

use of io.netty.channel.Channel in project java-in-action by xinghalo.

the class LogEventBroadcaster method run.

public void run() throws Exception {
    Channel ch = bootstrap.bind(0).sync().channel();
    long pointer = 0;
    for (; ; ) {
        long len = file.length();
        if (len < pointer) {
            pointer = len;
        } else if (len > pointer) {
            RandomAccessFile raf = new RandomAccessFile(file, "r");
            raf.seek(pointer);
            String line;
            while ((line = raf.readLine()) != null) {
                ch.writeAndFlush(new LogEvent(null, line, file.getAbsolutePath(), -1));
            }
            pointer = raf.getFilePointer();
            raf.close();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.interrupted();
            break;
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) Channel(io.netty.channel.Channel) NioDatagramChannel(io.netty.channel.socket.nio.NioDatagramChannel)

Example 80 with Channel

use of io.netty.channel.Channel in project async-http-client by AsyncHttpClient.

the class FailingReactiveStreamsTest method getChannel.

private Channel getChannel(StreamedResponsePublisher publisher) throws Exception {
    Field field = publisher.getClass().getDeclaredField("channel");
    field.setAccessible(true);
    return (Channel) field.get(publisher);
}
Also used : Field(java.lang.reflect.Field) Channel(io.netty.channel.Channel)

Aggregations

Channel (io.netty.channel.Channel)884 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)226 ChannelFuture (io.netty.channel.ChannelFuture)204 Test (org.junit.Test)203 Bootstrap (io.netty.bootstrap.Bootstrap)199 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)191 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)177 InetSocketAddress (java.net.InetSocketAddress)165 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)151 EventLoopGroup (io.netty.channel.EventLoopGroup)142 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)138 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)132 IOException (java.io.IOException)126 ByteBuf (io.netty.buffer.ByteBuf)112 SocketChannel (io.netty.channel.socket.SocketChannel)106 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)99 ChannelPipeline (io.netty.channel.ChannelPipeline)98 CountDownLatch (java.util.concurrent.CountDownLatch)96 LocalChannel (io.netty.channel.local.LocalChannel)93 LocalServerChannel (io.netty.channel.local.LocalServerChannel)89