Example usage for io.netty.channel AddressedEnvelope sender

List of usage examples for io.netty.channel AddressedEnvelope sender

Introduction

In this page you can find the example usage for io.netty.channel AddressedEnvelope sender.

Prototype

A sender();

Source Link

Document

Returns the address of the sender of this message.

Usage

From source file:org.apache.camel.component.netty4.NettyPayloadHelper.java

License:Apache License

public static void setIn(Exchange exchange, Object payload) {
    if (payload instanceof DefaultExchangeHolder) {
        DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) payload);
    } else if (payload instanceof AddressedEnvelope) {
        @SuppressWarnings("unchecked")
        AddressedEnvelope<Object, InetSocketAddress> dp = (AddressedEnvelope<Object, InetSocketAddress>) payload;
        // need to check if the content is ExchangeHolder
        if (dp.content() instanceof DefaultExchangeHolder) {
            DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) dp.content());
        } else {// w  ww. ja v  a 2s .  c o  m
            // need to take out the payload here 
            exchange.getIn().setBody(dp.content());
        }
        // setup the sender address here for sending the response message back
        exchange.setProperty(NettyConstants.NETTY_REMOTE_ADDRESS, dp.sender());
    } else {
        // normal transfer using the body only
        exchange.getIn().setBody(payload);
    }
}

From source file:org.apache.camel.component.netty4.NettyPayloadHelper.java

License:Apache License

public static void setOut(Exchange exchange, Object payload) {
    if (payload instanceof DefaultExchangeHolder) {
        DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) payload);
    } else if (payload instanceof AddressedEnvelope) {
        @SuppressWarnings("unchecked")
        AddressedEnvelope<Object, InetSocketAddress> dp = (AddressedEnvelope<Object, InetSocketAddress>) payload;
        // need to check if the content is ExchangeHolder
        if (dp.content() instanceof DefaultExchangeHolder) {
            DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) dp.content());
        } else {/*from   w  w  w .j  a v a 2s .  co  m*/
            // need to take out the payload here 
            exchange.getOut().setBody(dp.content());
        }
        // setup the sender address here for sending the response message back
        exchange.setProperty(NettyConstants.NETTY_REMOTE_ADDRESS, dp.sender());
    } else {
        // normal transfer using the body only and preserve the headers
        exchange.getOut().setHeaders(exchange.getIn().getHeaders());
        exchange.getOut().setBody(payload);
    }
}

From source file:sas.systems.imflux.network.udp.UdpControlHandler.java

License:Apache License

/**
 * To be compatible to io.Netty version 5.0:
 * {@code channelRead0(ChannelHandlerContext, I)} will be renamed to {@code messageReceived(ChannelHandlerContext, I)} in 5.0.
 * /*from   w  w  w  . j  a  va2 s.com*/
 * @param ctx           the {@link ChannelHandlerContext} which this {@link SimpleChannelInboundHandler}/
 *                      {@link UdpDataHandler} belongs to
 * @param msg           the message to handle
 * @throws Exception    is thrown if an error occurred
 */
//@Override
protected void messageReceived(ChannelHandlerContext ctx,
        AddressedEnvelope<CompoundControlPacket, SocketAddress> msg) throws Exception {
    final CompoundControlPacket packet = msg.content();
    final SocketAddress sender = msg.sender();
    this.receiver.controlPacketReceived(sender, packet);
}

From source file:sas.systems.imflux.network.udp.UdpDataHandler.java

License:Apache License

/**
 * To be compatible to io.Netty version 5.0:
 * {@code channelRead0(ChannelHandlerContext, I)} will be renamed to {@code messageReceived(ChannelHandlerContext, I)} in 5.0.
 * //w w  w .j  a va2 s  . com
 * @param ctx           the {@link ChannelHandlerContext} which this {@link SimpleChannelInboundHandler}/
 *                      {@link UdpDataHandler} belongs to
 * @param msg           the message to handle
 * @throws Exception    is thrown if an error occurred
 */
//@Override
protected void messageReceived(ChannelHandlerContext ctx, AddressedEnvelope<DataPacket, SocketAddress> msg)
        throws Exception {
    final DataPacket packet = msg.content();
    final SocketAddress sender = msg.sender();
    this.receiver.dataPacketReceived(sender, packet);
}