Search in sources :

Example 1 with ChannelId

use of io.netty.channel.ChannelId in project spring-framework by spring-projects.

the class ReactorServerHttpResponse method touchDataBuffer.

@Override
protected void touchDataBuffer(DataBuffer buffer) {
    if (logger.isDebugEnabled()) {
        if (ReactorServerHttpRequest.reactorNettyRequestChannelOperationsIdPresent) {
            if (ChannelOperationsIdHelper.touch(buffer, this.response)) {
                return;
            }
        }
        this.response.withConnection(connection -> {
            ChannelId id = connection.channel().id();
            DataBufferUtils.touch(buffer, "Channel id: " + id.asShortText());
        });
    }
}
Also used : ChannelId(io.netty.channel.ChannelId)

Example 2 with ChannelId

use of io.netty.channel.ChannelId in project netty by netty.

the class DefaultChannelGroup method remove.

@Override
public boolean remove(Object o) {
    Channel c = null;
    if (o instanceof ChannelId) {
        c = nonServerChannels.remove(o);
        if (c == null) {
            c = serverChannels.remove(o);
        }
    } else if (o instanceof Channel) {
        c = (Channel) o;
        if (c instanceof ServerChannel) {
            c = serverChannels.remove(c.id());
        } else {
            c = nonServerChannels.remove(c.id());
        }
    }
    if (c == null) {
        return false;
    }
    c.closeFuture().removeListener(remover);
    return true;
}
Also used : ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) ChannelId(io.netty.channel.ChannelId) ServerChannel(io.netty.channel.ServerChannel)

Example 3 with ChannelId

use of io.netty.channel.ChannelId in project netty by netty.

the class Http2StreamChannelIdTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    ChannelId normalInstance = new Http2StreamChannelId(DefaultChannelId.newInstance(), 0);
    ByteBuf buf = Unpooled.buffer();
    ObjectOutputStream outStream = new ObjectOutputStream(new ByteBufOutputStream(buf));
    try {
        outStream.writeObject(normalInstance);
    } finally {
        outStream.close();
    }
    ObjectInputStream inStream = new ObjectInputStream(new ByteBufInputStream(buf, true));
    final ChannelId deserializedInstance;
    try {
        deserializedInstance = (ChannelId) inStream.readObject();
    } finally {
        inStream.close();
    }
    assertEquals(normalInstance, deserializedInstance);
    assertEquals(normalInstance.hashCode(), deserializedInstance.hashCode());
    assertEquals(0, normalInstance.compareTo(deserializedInstance));
    assertEquals(normalInstance.asLongText(), deserializedInstance.asLongText());
    assertEquals(normalInstance.asShortText(), deserializedInstance.asShortText());
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) DefaultChannelId(io.netty.channel.DefaultChannelId) ChannelId(io.netty.channel.ChannelId) ByteBuf(io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.jupiter.api.Test)

Example 4 with ChannelId

use of io.netty.channel.ChannelId in project netty by netty.

the class EmbeddedChannelIdTest method testSerialization.

@Test
public void testSerialization() throws IOException, ClassNotFoundException {
    // test that a deserialized instance works the same as a normal instance (issue #2869)
    ChannelId normalInstance = EmbeddedChannelId.INSTANCE;
    ByteBuf buf = Unpooled.buffer();
    ObjectOutputStream outStream = new ObjectOutputStream(new ByteBufOutputStream(buf));
    try {
        outStream.writeObject(normalInstance);
    } finally {
        outStream.close();
    }
    ObjectInputStream inStream = new ObjectInputStream(new ByteBufInputStream(buf, true));
    final ChannelId deserializedInstance;
    try {
        deserializedInstance = (ChannelId) inStream.readObject();
    } finally {
        inStream.close();
    }
    assertEquals(normalInstance, deserializedInstance);
    assertEquals(normalInstance.hashCode(), deserializedInstance.hashCode());
    assertEquals(0, normalInstance.compareTo(deserializedInstance));
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) ChannelId(io.netty.channel.ChannelId) ByteBuf(io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.jupiter.api.Test)

Example 5 with ChannelId

use of io.netty.channel.ChannelId in project netty by netty.

the class EmbeddedChannelTest method testConstructWithChannelId.

@Test
public void testConstructWithChannelId() {
    ChannelId channelId = new CustomChannelId(1);
    EmbeddedChannel channel = new EmbeddedChannel(channelId);
    assertSame(channelId, channel.id());
}
Also used : ChannelId(io.netty.channel.ChannelId) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelId (io.netty.channel.ChannelId)9 Channel (io.netty.channel.Channel)4 ByteBuf (io.netty.buffer.ByteBuf)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 Test (org.junit.jupiter.api.Test)3 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)2 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Before (org.junit.Before)2 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 ChannelPromise (io.netty.channel.ChannelPromise)1 DefaultChannelId (io.netty.channel.DefaultChannelId)1 ServerChannel (io.netty.channel.ServerChannel)1 CloseWebSocketFrame (io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)1 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)1 Attribute (io.netty.util.Attribute)1