private Class<? extends ProtocolServer> defaultProtocolServer() { if (protocol.getType() == ProtocolType.TCP) { return JsonLineProtocolServer.class; } return JsonFrameProtocolServer.class; }
private AsyncFuture<ProtocolConnection> bindTCP( final Logger log, final Protocol protocol, ProtocolServer server, RetryPolicy policy ) { final ServerBootstrap b = new ServerBootstrap(); b.group(boss, worker); b.channel(NioServerSocketChannel.class); b.childHandler(server.initializer()); b.option(ChannelOption.SO_BACKLOG, 128); if (protocol.getReceiveBufferSize() != null) { b.childOption(ChannelOption.SO_RCVBUF, protocol.getReceiveBufferSize()); } b.childOption(ChannelOption.SO_KEEPALIVE, true); final String host = protocol.getAddress().getHostString(); final int port = protocol.getAddress().getPort(); final RetryingProtocolConnection connection = new RetryingProtocolConnection(async, timer, log, policy, new ProtocolChannelSetup() { @Override public ChannelFuture setup() { return b.bind(host, port); } @Override public String toString() { return String.format("bind tcp://%s:%d", host, port); } }); return connection.getInitialFuture(); }
/** * Build a new protocol instance with the given defaults if they are missing. * * @param defaultType Default type. * @param defaultPort Default port. * @param defaultHost Default host. * @return */ public Protocol protocol(ProtocolType defaultType, int defaultPort, String defaultHost) { final ProtocolType t = parseProtocolType(type, defaultType); final InetSocketAddress address = parseSocketAddress(host, port, defaultPort, defaultHost); return new Protocol(t, address, receiveBufferSize); }
private AsyncFuture<ProtocolConnection> connectTCP( Logger log, Protocol protocol, ProtocolClient client, RetryPolicy policy ) { final Bootstrap b = new Bootstrap(); b.group(worker); b.channel(NioSocketChannel.class); b.handler(client.initializer()); b.option(ChannelOption.SO_KEEPALIVE, true); final String host = protocol.getAddress().getHostString(); final int port = protocol.getAddress().getPort(); final ProtocolConnection connection = new RetryingProtocolConnection(async, timer, log, policy, new ProtocolChannelSetup() { @Override public ChannelFuture setup() { return b.connect(host, port); } @Override public String toString() { return String.format("connect tcp://%s:%d", host, port); } }); return async.resolved(connection); }
b.handler(server.initializer()); if (protocol.getReceiveBufferSize() != null) { b.option(ChannelOption.SO_RCVBUF, protocol.getReceiveBufferSize()); final String host = protocol.getAddress().getHostString(); final int port = protocol.getAddress().getPort();
/** * Build a new protocol instance with the given defaults if they are missing. * * @param defaultType Default type. * @param defaultPort Default port. * @param defaultHost Default host. * @return */ public Protocol protocol(ProtocolType defaultType, int defaultPort, String defaultHost) { final ProtocolType t = parseProtocolType(type, defaultType); final InetSocketAddress address = parseSocketAddress(host, port, defaultPort, defaultHost); return new Protocol(t, address, receiveBufferSize); }
private Class<? extends ProtocolServer> parseProtocolServer() { if (protocol.getType() == ProtocolType.UDP) { return ProtobufFrameProtocolServer.class; } if (protocol.getType() == ProtocolType.TCP) { return ProtobufLengthPrefixedProtocolServer.class; } throw new IllegalArgumentException("Protocol not supported: " + protocol.getType()); }
private Class<? extends ProtocolServer> parseProtocolServer() { if (protocol.getType() == ProtocolType.UDP) { return RiemannUDPProtocolServer.class; } if (protocol.getType() == ProtocolType.TCP) { return RiemannTCPProtocolServer.class; } throw new IllegalArgumentException("Protocol not supported: " + protocol.getType()); }
private Class<? extends ProtocolServer> parseProtocolServer(final String delimiter) { if (FRAME.equals(delimiter)) { if (protocol.getType() == ProtocolType.TCP) { throw new IllegalArgumentException("frame-based decoding is not suitable for TCP"); } throw new IllegalArgumentException("frame-based decoding is not supported yet"); } if (LINE.equals(delimiter)) { return CarbonLineServer.class; } return defaultProtocolServer(); }
@Override public AsyncFuture<ProtocolConnection> bind( Logger log, Protocol protocol, ProtocolServer server, RetryPolicy policy ) { if (protocol.getType() == ProtocolType.UDP) { return bindUDP(log, protocol, server, policy); } if (protocol.getType() == ProtocolType.TCP) { return bindTCP(log, protocol, server, policy); } throw new IllegalArgumentException("Unsupported protocol: " + protocol); }
@Override public AsyncFuture<ProtocolConnection> connect( Logger log, Protocol protocol, ProtocolClient client, RetryPolicy policy ) { if (protocol.getType() == ProtocolType.UDP) { return connectUDP(protocol, client, policy); } if (protocol.getType() == ProtocolType.TCP) { return connectTCP(log, protocol, client, policy); } throw new IllegalArgumentException("Unsupported protocol: " + protocol); }
private Class<? extends ProtocolServer> parseProtocolServer(String delimiter) { if (FRAME.equals(delimiter)) { if (protocol.getType() == ProtocolType.TCP) { throw new IllegalArgumentException("frame-based decoding is not suitable for TCP"); } return JsonFrameProtocolServer.class; } if (LINE.equals(delimiter)) { return JsonLineProtocolServer.class; } return defaultProtocolServer(); }