Search in sources :

Example 11 with DefaultAddressedEnvelope

use of io.netty.channel.DefaultAddressedEnvelope in project camel by apache.

the class DatagramPacketByteArrayEncoder method encode.

@Override
protected void encode(ChannelHandlerContext ctx, AddressedEnvelope<Object, InetSocketAddress> msg, List<Object> out) throws Exception {
    if (msg.content() instanceof byte[]) {
        delegateEncoder.encode(ctx, (byte[]) msg.content(), out);
        ByteBuf buf = (ByteBuf) out.remove(out.size() - 1);
        AddressedEnvelope<Object, InetSocketAddress> addressedEnvelop = new DefaultAddressedEnvelope<Object, InetSocketAddress>(buf.retain(), msg.recipient(), msg.sender());
        out.add(addressedEnvelop);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ByteBuf(io.netty.buffer.ByteBuf) DefaultAddressedEnvelope(io.netty.channel.DefaultAddressedEnvelope)

Example 12 with DefaultAddressedEnvelope

use of io.netty.channel.DefaultAddressedEnvelope in project camel by apache.

the class DatagramPacketDelimiterDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, AddressedEnvelope<Object, InetSocketAddress> msg, List<Object> out) throws Exception {
    if (msg.content() instanceof ByteBuf) {
        ByteBuf payload = (ByteBuf) msg.content();
        Object result = delegateDecoder.decode(ctx, payload);
        AddressedEnvelope<Object, InetSocketAddress> addressEvelop = new DefaultAddressedEnvelope<Object, InetSocketAddress>(result, msg.recipient(), msg.sender());
        out.add(addressEvelop);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ByteBuf(io.netty.buffer.ByteBuf) DefaultAddressedEnvelope(io.netty.channel.DefaultAddressedEnvelope)

Aggregations

DefaultAddressedEnvelope (io.netty.channel.DefaultAddressedEnvelope)12 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuf (io.netty.buffer.ByteBuf)9 AddressedEnvelope (io.netty.channel.AddressedEnvelope)4 Test (org.junit.Test)4 DatagramPacket (io.netty.channel.socket.DatagramPacket)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 SocketAddress (java.net.SocketAddress)2 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 ChannelFuture (io.netty.channel.ChannelFuture)1 DatagramSocketAddress (io.netty.channel.unix.DatagramSocketAddress)1 Serializable (java.io.Serializable)1