public static void main(String[] args) throws UnknownHostException { InetAddress ip = InetAddress.getByName(args[0]); int port = Integer.parseInt(args[1]); Address selfAddress = new NettyAddress(ip, port); InetAddress ip2 = InetAddress.getByName(args[2]); int port2 = Integer.parseInt(args[3]); Address targetAddress = new NettyAddress(ip2, port2); Kompics.createAndStart(Parent.class, new Parent.Init(selfAddress, targetAddress), Receiver.THREADS, 50); }
@Override public Object fromBinary(ByteBuf buf, Optional<Object> hint) { byte[] ipBytes = new byte[4]; buf.readBytes(ipBytes); if ((ipBytes[0] == 0) && (ipBytes[1] == 0) && (ipBytes[2] == 0) && (ipBytes[3] == 0)) { return null; // IP 0.0.0.0 is not valid but null Address encoding } InetAddress ip; try { ip = InetAddress.getByAddress(ipBytes); } catch (UnknownHostException ex) { Serializers.LOG.error("AddressSerializer: Could not create InetAddress.", ex); return null; } byte portUpper = buf.readByte(); byte portLower = buf.readByte(); int port = Ints.fromBytes((byte) 0, (byte) 0, portUpper, portLower); return new NettyAddress(ip, port); }
public static void main(String[] args) throws UnknownHostException { InetAddress ip = InetAddress.getByName(args[0]); int port = Integer.parseInt(args[1]); Address selfAddress = new NettyAddress(ip, port); Kompics.createAndStart(Parent.class, new Parent.Init(selfAddress), 2, 50); }
@Override public void channelActive(ChannelHandlerContext ctx) { super.channelActive(ctx); UdtChannel channel = (UdtChannel) ctx.channel(); component.channels.addLocalSocket(channel); InetSocketAddress other = channel.remoteAddress(); channel.writeAndFlush(new DisambiguateConnection(component.self, new NettyAddress(other), protocol, component.boundUDTPort, true)); }
@Override public Object fromBinary(ByteBuf buf, DatagramPacket datagram) { byte type = buf.readByte(); SpecialSerializers.MessageSerializationUtil.MessageFields fields = SpecialSerializers.MessageSerializationUtil.msgFromBinary(buf); switch (type) { case DIS: { // Port 2 byte byte portUpper = buf.readByte(); byte portLower = buf.readByte(); int udtPort = Ints.fromBytes((byte) 0, (byte) 0, portUpper, portLower); return new DisambiguateConnection(new NettyAddress(datagram.sender()), new NettyAddress(datagram.recipient()), Transport.UDP, udtPort, fields.flag1); } case ACK: { UUID id = (UUID) SpecialSerializers.UUIDSerializer.INSTANCE.fromBinary(buf, Optional.absent()); return new NotifyAck(new NettyAddress(datagram.sender()), new NettyAddress(datagram.recipient()), Transport.UDP, id); } case ACK_REQ: { UUID id = (UUID) SpecialSerializers.UUIDSerializer.INSTANCE.fromBinary(buf, Optional.absent()); Msg msg = (Msg) Serializers.fromBinary(buf, datagram); return new AckRequestMsg(msg, id); } } return null; }
@Override public void channelActive(ChannelHandlerContext ctx) { super.channelActive(ctx); SocketChannel channel = (SocketChannel) ctx.channel(); component.channels.addLocalSocket(channel); InetSocketAddress other = channel.remoteAddress(); DisambiguateConnection r = new DisambiguateConnection(component.self, new NettyAddress(other), protocol, component.boundUDTPort, true); channel.writeAndFlush(r); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { component.setCustomMDC(); try { Channel channel = ctx.channel(); SocketAddress address = channel.remoteAddress(); InetSocketAddress inetAddress = null; if (address != null && address instanceof InetSocketAddress) { inetAddress = (InetSocketAddress) address; Address addr = new NettyAddress(inetAddress); component.networkException(new NetworkException("Error in Channel handler to " + addr, addr, protocol, Optional.of(cause))); } component.extLog.error("Error in channel.", cause); //cause.printStackTrace(); component.extLog.error("Closing channel {} due to error.", channel); channel.close(); } finally { MDC.clear(); } } }
component.networkStatus(ConnectionStatus.dropped(new NettyAddress(realAddress), Transport.TCP)); printStuff(); if (tcpChannels.get(realAddress).isEmpty()) { uc.close(); component.extLog.debug(" UDT Channel {} ({}) closed.", udtRealAddr, uc.remoteAddress()); component.networkStatus(ConnectionStatus.dropped(new NettyAddress(realAddress), Transport.UDT)); component.networkStatus(ConnectionStatus.dropped(new NettyAddress(realAddress), Transport.UDT)); printStuff(); } else {
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) {
self = new NettyAddress(init.self); customLogCtx.put(MDC_KEY_PORT, Integer.toString(self.getPort())); customLogCtx.put(MDC_KEY_IF, self.getIp().getHostAddress());