Example usage for io.netty.channel.udt UdtChannel localAddress

List of usage examples for io.netty.channel.udt UdtChannel localAddress

Introduction

In this page you can find the example usage for io.netty.channel.udt UdtChannel localAddress.

Prototype

@Override
    InetSocketAddress localAddress();

Source Link

Usage

From source file:se.sics.kompics.network.netty.ChannelManager.java

License:Open Source License

void flushAndClose(CloseChannel msg, Channel c) {
    synchronized (this) {
        component.setCustomMDC();/*from  w  ww . j  a  v a  2s. c o m*/
        try {
            if (c instanceof SocketChannel) {
                SocketChannel sc = (SocketChannel) c;
                SocketChannel activeC = tcpActiveChannels.get(msg.getSource().asSocket());
                tcpChannels.put(msg.getSource().asSocket(), sc); // just to make sure
                Set<SocketChannel> channels = tcpChannels.get(msg.getSource().asSocket());
                if (channels.size() < 2) {
                    component.extLog.warn(
                            "Can't close TCP channel between {} and {}: local {}, remote {} -- it's the only channel!",
                            new Object[] { msg.getSource(), msg.getDestination(), sc.localAddress(),
                                    sc.remoteAddress() });
                    tcpActiveChannels.put(msg.getSource().asSocket(), sc);
                    sc.writeAndFlush(new MessageNotify.Req(
                            new CheckChannelActive(component.self, msg.getSource(), Transport.TCP)));
                } else {
                    if (activeC.equals(sc)) { // pick any channel as active
                        for (SocketChannel channel : channels) {
                            if (!channel.equals(sc)) {
                                tcpActiveChannels.put(msg.getSource().asSocket(), channel);
                                activeC = channel;
                            }
                        }
                    }
                    ChannelFuture f = sc.writeAndFlush(new MessageNotify.Req(
                            new ChannelClosed(component.self, msg.getSource(), Transport.TCP)));
                    f.addListener(ChannelFutureListener.CLOSE);
                    component.extLog.info(
                            "Closing duplicate TCP channel between {} and {}: local {}, remote {}",
                            new Object[] { msg.getSource(), msg.getDestination(), sc.localAddress(),
                                    sc.remoteAddress() });

                }
            } else if (c instanceof UdtChannel) {
                UdtChannel uc = (UdtChannel) c;
                UdtChannel activeC = udtActiveChannels.get(msg.getSource().asSocket());
                udtChannels.put(msg.getSource().asSocket(), uc); // just to make sure
                Set<UdtChannel> channels = udtChannels.get(msg.getSource().asSocket());
                if (channels.size() < 2) {
                    component.extLog.warn(
                            "Can't close UDT channel between {} and {}: local {}, remote {} -- it's the only channel!",
                            new Object[] { msg.getSource(), msg.getDestination(), uc.localAddress(),
                                    uc.remoteAddress() });
                    udtActiveChannels.put(msg.getSource().asSocket(), uc);
                    uc.writeAndFlush(new MessageNotify.Req(
                            new CheckChannelActive(component.self, msg.getSource(), Transport.UDT)));
                } else {
                    if (activeC.equals(uc)) { // pick any channel as active
                        for (UdtChannel channel : channels) {
                            if (!channel.equals(uc)) {
                                udtActiveChannels.put(msg.getSource().asSocket(), channel);
                                activeC = channel;
                            }
                        }
                    }
                    ChannelFuture f = uc.writeAndFlush(new MessageNotify.Req(
                            new ChannelClosed(component.self, msg.getSource(), Transport.UDT)));
                    f.addListener(ChannelFutureListener.CLOSE);
                    component.extLog.info(
                            "Closing duplicate UDT channel between {} and {}: local {}, remote {}",
                            new Object[] { msg.getSource(), msg.getDestination(), uc.localAddress(),
                                    uc.remoteAddress() });

                }
            }
        } finally {
            MDC.clear();
        }
    }
}

From source file:se.sics.kompics.network.netty.ChannelManager.java

License:Open Source License

void checkUDTChannel(Msg msg, UdtChannel c) {
    // Ignore some messages
    if (msg instanceof CheckChannelActive) {
        return;/*  www.j a  v  a 2  s . c o  m*/
    }
    if (msg instanceof CloseChannel) {
        return;
    }
    if (msg instanceof ChannelClosed) {
        return;
    }
    if (!c.equals(udtActiveChannels.get(msg.getSource().asSocket()))) {
        synchronized (this) {
            component.setCustomMDC();
            try {
                UdtChannel activeC = udtActiveChannels.get(msg.getSource().asSocket());

                udtActiveChannels.put(msg.getSource().asSocket(), c);
                udtChannels.put(msg.getSource().asSocket(), c);
                if (activeC != null && !activeC.equals(c)) {
                    component.extLog.warn("Duplicate TCP channel between {} and {}: local {}, remote {}",
                            new Object[] { msg.getSource(), msg.getDestination(), c.localAddress(),
                                    c.remoteAddress() });

                    UdtChannel minsc = minChannel(udtChannels.get(msg.getSource().asSocket()));

                    minsc.writeAndFlush(new MessageNotify.Req(
                            new CheckChannelActive(component.self, msg.getSource(), Transport.UDT)));

                }
            } finally {
                MDC.clear();
            }
        }
        component.trigger(new SendDelayed(msg.getSource(), Transport.UDT));
    }
}

From source file:se.sics.kompics.network.netty.ChannelManager.java

License:Open Source License

private int channel2Id(UdtChannel c) {
    return c.localAddress().getPort() + c.remoteAddress().getPort();
}