Example usage for io.netty.channel.socket.nio NioSocketChannel remoteAddress

List of usage examples for io.netty.channel.socket.nio NioSocketChannel remoteAddress

Introduction

In this page you can find the example usage for io.netty.channel.socket.nio NioSocketChannel remoteAddress.

Prototype

@Override
    public InetSocketAddress remoteAddress() 

Source Link

Usage

From source file:org.opendaylight.usc.plugin.UscPluginTcp.java

License:Open Source License

/**
 * Constructs a new UscPluginTcp/*ww w.  j a v a  2  s  .  c  o  m*/
 */
public UscPluginTcp() {
    super(new LocalAddress("usc-local-server-tcp"));

    UscRouteBrokerService routeBroker = UscServiceUtils.getService(UscRouteBrokerService.class);
    if (routeBroker != null) {
        routeBroker.setConnetionManager(ChannelType.TCP, super.getConnectionManager());
        routeBroker.setConnetionManager(ChannelType.TLS, super.getConnectionManager());
    } else {
        log.error("UscRouteBrokerService is not found, failed to set connection manager for all TCP Channel!");
    }

    configService = UscServiceUtils.getService(UscConfigurationService.class);
    secureService = UscServiceUtils.getService(UscSecureService.class);
    agentBootstrap.group(agentGroup);
    agentBootstrap.channel(NioSocketChannel.class);
    agentBootstrap.handler(new ChannelInitializer<Channel>() {
        @Override
        public void initChannel(final Channel ch) throws Exception {
            if (secureService == null) {
                log.error("UscSecureService is not initialized!");
                return;
            }
            ChannelPipeline p = ch.pipeline();
            initAgentPipeline(p, secureService.getTcpClientHandler(ch));
        }
    });

    final ServerBootstrap callHomeServerTcpBootstrap = new ServerBootstrap();
    callHomeServerTcpBootstrap.group(agentGroup);
    callHomeServerTcpBootstrap.channel(NioServerSocketChannel.class);
    // callHomeServerTcpBootstrap.handler(new
    // LoggingHandler(LogLevel.TRACE));
    callHomeServerTcpBootstrap.childHandler(new ChannelInitializer<NioSocketChannel>() {

        @Override
        public void initChannel(final NioSocketChannel channel) throws Exception {
            if (secureService == null) {
                log.error("UscSecureService is not initialized!");
                return;
            }
            log.debug("Received call home TCP connection");

            ChannelPipeline p = channel.pipeline();

            addCallHomeConnection(channel.remoteAddress(), channel);

            initAgentPipeline(p, secureService.getTcpServerHandler(channel));
        }
    });
    if (configService == null) {
        log.error("UscConfigurationService is not initialized!");
        return;
    }
    final ChannelFuture callHomeChannelTcpFuture = callHomeServerTcpBootstrap
            .bind(configService.getConfigIntValue(UscConfigurationService.USC_PLUGIN_PORT));
    log.debug("callHomeChannelTcpFuture : " + callHomeChannelTcpFuture);
}