Example usage for io.netty.channel.udt.nio NioUdtProvider socketUDT

List of usage examples for io.netty.channel.udt.nio NioUdtProvider socketUDT

Introduction

In this page you can find the example usage for io.netty.channel.udt.nio NioUdtProvider socketUDT.

Prototype

public static SocketUDT socketUDT(final Channel channel) 

Source Link

Document

Expose underlying SocketUDT for debugging and monitoring.

Usage

From source file:com.hop.hhxx.example.udt.echo.bytes.ByteEchoClientHandler.java

License:Apache License

@Override
public void channelActive(final ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
    ctx.writeAndFlush(message);//from  w ww  .j  a v a2 s . c  om
}

From source file:com.hop.hhxx.example.udt.echo.bytes.ByteEchoServerHandler.java

License:Apache License

@Override
public void channelActive(final ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
}

From source file:com.hop.hhxx.example.udt.echo.rendezvousBytes.ByteEchoPeerHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
    ctx.writeAndFlush(message);/* ww w.  j  a  v  a 2 s. c o m*/
}

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

License:Open Source License

UdtChannel createUDTChannel(final Address destination, final Bootstrap bootstrapUDTClient) {
    synchronized (this) {
        UdtChannel c = udtActiveChannels.get(destination.asSocket());
        if (c != null) {
            return c;
        }/*  ww  w  . j  a v a  2  s  .  co  m*/
        ChannelFuture f = udtIncompleteChannels.get(destination.asSocket());
        if (f != null) {
            component.extLog.trace("UDT channel to {} is already being created.", destination.asSocket());
            return null; // already establishing connection but not done, yet
        }
        InetSocketAddress isa = udtBoundPorts.get(destination.asSocket());
        if (isa == null) { // We have to ask for the UDT port first, since it's random
            component.extLog.trace("Need to find UDT port at {} before creating channel.",
                    destination.asSocket());
            DisambiguateConnection r = new DisambiguateConnection(component.self, new NettyAddress(destination),
                    Transport.TCP, component.boundUDTPort, true);
            SocketChannel tcpC = this.getTCPChannel(destination);
            if (tcpC == null) {
                tcpC = this.createTCPChannel(destination, component.bootstrapTCPClient);
            }
            if (tcpC == null) {
                component.extLog.debug("Putting disamb on hold until TCP channel is created: {}", r);
                waitingDisambs.put(destination.asSocket(), r);
                return null;
            }
            waitingForCreationUDT.add(destination.asSocket());
            tcpC.writeAndFlush(new MessageWrapper(r));
            return null;
        }
        component.extLog.trace("Creating new UDT channel to {}.", destination.asSocket());
        component.networkStatus(ConnectionStatus.requested(destination, Transport.UDT));
        f = bootstrapUDTClient.connect(isa);
        udtIncompleteChannels.put(destination.asSocket(), f);
        f.addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                synchronized (ChannelManager.this) {
                    component.setCustomMDC();
                    try {
                        udtIncompleteChannels.remove(destination.asSocket());
                        if (future.isSuccess()) {
                            UdtChannel sc = (UdtChannel) future.channel();
                            udtActiveChannels.put(destination.asSocket(), sc);
                            udtChannels.put(destination.asSocket(), sc);
                            udtChannelsByRemote.put(sc.remoteAddress(), sc);
                            address4Remote.put(sc.remoteAddress(), destination.asSocket());
                            component.trigger(new SendDelayed(destination, Transport.UDT));
                            SocketUDT socket = NioUdtProvider.socketUDT(sc);
                            //                            if (component.udtBufferSizes > 0) {
                            //                                socket.setSendBufferSize(component.udtBufferSizes);
                            //                                socket.setReceiveBufferSize(component.udtBufferSizes);
                            //                            }
                            if (component.udtMSS > 0) {
                                socket.setOption(OptionUDT.Maximum_Transfer_Unit, component.udtMSS);
                            }
                            component.trigger(new SendDelayed(destination, Transport.UDT));
                            component.extLog.debug("New UDT channel to {} was created! Properties: \n {} \n {}",
                                    new Object[] { destination.asSocket(), socket.toStringOptions(),
                                            socket.toStringMonitor() });
                            component.networkStatus(ConnectionStatus.established(destination, Transport.UDT));
                        } else {
                            component.extLog.error("Error while trying to connect to {}! Error was {}",
                                    destination, future.cause());
                            component.networkStatus(ConnectionStatus.dropped(destination, Transport.UDT));
                            component.trigger(new DropDelayed(destination, Transport.UDT));
                        }
                    } finally {
                        MDC.clear();
                    }
                }
            }
        });

    }
    return null;
}

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

License:Open Source License

void monitor() {
    component.extLog.debug("Monitoring UDT channels:");
    for (UdtChannel c : udtChannelsByRemote.values()) {
        SocketUDT socket = NioUdtProvider.socketUDT(c);
        if (socket != null) {
            component.extLog.debug("UDT Stats: \n {} \n {}",
                    new Object[] { socket.toStringMonitor(), socket.toStringOptions() });
            try {
                socket.updateMonitor(true); // reset statistics
            } catch (ExceptionUDT ex) {
                component.extLog.warn("Couldn't reset UDT monitoring stats.");
            }//w  w  w  . java  2  s  . co  m
        }
    }
}