Refine search
@Override public void start() { // setup Netty server ConnectionlessBootstrap serverBootstrap = new ConnectionlessBootstrap( new OioDatagramChannelFactory(Executors.newCachedThreadPool())); final NetcatHandler handler = new NetcatHandler(); serverBootstrap.setOption("receiveBufferSizePredictorFactory", new AdaptiveReceiveBufferSizePredictorFactory(DEFAULT_MIN_SIZE, DEFAULT_INITIAL_SIZE, maxsize)); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { return Channels.pipeline(handler); } }); if (host == null) { nettyChannel = serverBootstrap.bind(new InetSocketAddress(port)); } else { nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port)); } super.start(); }
/** * Creates a new connected channel with the specified * {@code "remoteAddress"} and the current {@code "localAddress"} option. * If the {@code "localAddress"} option is not set, the local address of * a new channel is determined automatically. This method is identical * with the following code: * * <pre> * {@link ConnectionlessBootstrap} b = ...; * b.connect(remoteAddress, b.getOption("localAddress")); * </pre> * * @return a future object which notifies when the creation of the connected * channel succeeds or fails * * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect(SocketAddress remoteAddress) { if (remoteAddress == null) { throw new NullPointerException("remotedAddress"); } SocketAddress localAddress = (SocketAddress) getOption("localAddress"); return connect(remoteAddress, localAddress); }
public void run() { udpBootstrap.releaseExternalResources(); } });
/** * Creates a new channel which is bound to the local address which was * specified in the current {@code "localAddress"} option. This method is * similar to the following code: * * <pre> * {@link ConnectionlessBootstrap} b = ...; * b.bind(b.getOption("localAddress")); * </pre> * * @return a new bound channel which accepts incoming connections * * @throws IllegalStateException * if {@code "localAddress"} option was not set * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelException * if failed to create a new channel and * bind it to the local address */ public Channel bind() { SocketAddress localAddress = (SocketAddress) getOption("localAddress"); if (localAddress == null) { throw new IllegalStateException("localAddress option is not set."); } return bind(localAddress); }
void start(final int idleTimeMilliSeconds, final SocketAddress tcpAddress, final SocketAddress udpAddress) { tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); tcpServer.setPipelineFactory(new ChannelPipelineFactory() { private final HashedWheelTimer timer = new HashedWheelTimer(); private final IdleStateHandler idleStateHandler = new IdleStateHandler( udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory( Executors.newCachedThreadPool())); udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, handler, RpcUtil.STAGE_RPC_UDP_RESPONSE)); tcpChannel = tcpServer.bind(tcpAddress); udpChannel = udpServer.bind(udpAddress); allChannels.add(tcpChannel); allChannels.add(udpChannel);
@Override public void launch(final MessageInput input) throws MisfireException { final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = getBaseChannelHandlers(input); final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalHandlers = getFinalChannelHandlers(input); handlerList.putAll(finalHandlers); try { bootstrap = getBootstrap(); bootstrap.setPipelineFactory(getPipelineFactory(handlerList)); // sigh, bindable bootstraps do not share a common interface int receiveBufferSize; if (bootstrap instanceof ConnectionlessBootstrap) { acceptChannel = ((ConnectionlessBootstrap) bootstrap).bind(socketAddress); final DefaultDatagramChannelConfig channelConfig = (DefaultDatagramChannelConfig) acceptChannel.getConfig(); receiveBufferSize = channelConfig.getReceiveBufferSize(); } else if (bootstrap instanceof ServerBootstrap) { acceptChannel = ((ServerBootstrap) bootstrap).bind(socketAddress); final ServerSocketChannelConfig channelConfig = (ServerSocketChannelConfig) acceptChannel.getConfig(); receiveBufferSize = channelConfig.getReceiveBufferSize(); } else { log.error("Unknown Netty bootstrap class returned: {}. Cannot safely bind.", bootstrap); throw new IllegalStateException("Unknown netty bootstrap class returned: " + bootstrap + ". Cannot safely bind."); } if (receiveBufferSize != getRecvBufferSize()) { log.warn("receiveBufferSize (SO_RCVBUF) for input {} should be {} but is {}.", input, getRecvBufferSize(), receiveBufferSize); } } catch (Exception e) { throw new MisfireException(e); } }
public HistoricReplayListenerClientDDF(final int socketAddress, final Executor executor) { this.socketAddress = socketAddress; runner = executor; final DatagramChannelFactory channelFactory = new NioDatagramChannelFactory( runner); boot = new ConnectionlessBootstrap(channelFactory); final ChannelPipelineFactory pipelineFactory = new PipelineFactoryDDF( this); boot.setPipelineFactory(pipelineFactory); boot.setOption("broadcast", "false"); boot.setOption("receiveBufferSizePredictorFactory", // new FixedReceiveBufferSizePredictorFactory(2 * 1024)); }
void shutdown() { allChannels.close().awaitUninterruptibly(); tcpServer.releaseExternalResources(); udpServer.releaseExternalResources(); }
public void run() { // Configure the client. DatagramChannelFactory f = new NioDatagramChannelFactory( Executors.newCachedThreadPool(), workerCount); server = new ConnectionlessBootstrap(f); server.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE)); server.setOption("broadcast", "false"); server.setOption("sendBufferSize", SEND_BUFFER_SIZE); server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE); // Listen to the UDP port ch = server.bind(new InetSocketAddress(port)); InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress(); boundPort = socketAddr.getPort(); LOG.info("Started listening to UDP requests at port " + boundPort + " for " + rpcProgram + " with workerCount " + workerCount); }
bootstrap = new ConnectionlessBootstrap(channelFactory); bootstrap.setPipelineFactory( new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { bootstrap.setOption("resolver", resolver); bootstrap.setOption("remoteAddress", resolver.resolve()); bootstrap.setOption("sendBufferSize", sendBufferSize.get()); final ChannelFuture result = bootstrap.connect().awaitUninterruptibly();
@Override public Bootstrap getBootstrap() { final ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory(workerExecutor)); final int recvBufferSize = Ints.saturatedCast(getRecvBufferSize()); LOG.debug("Setting receive buffer size to {} bytes", recvBufferSize); bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(recvBufferSize)); bootstrap.setOption("receiveBufferSize", recvBufferSize); return bootstrap; }
@Override protected void bindRequested(ChannelPipeline pipeline, ChannelStateEvent evt) throws Exception { ChannelAddress localAddress = (ChannelAddress) evt.getValue(); // Use ConnectionlessBootstrap to create a NioDatagramChannel for an UdpServerChannel UdpServerChannel serverChannel = (UdpServerChannel) evt.getChannel(); ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(serverChannelFactory); DatagramChannelPipelineFactory pipelineFactory = new DatagramChannelPipelineFactory(serverChannel, timer); bootstrap.setPipelineFactory(pipelineFactory); NioDatagramChannel datagramChannel = (NioDatagramChannel) bootstrap.bind(toInetSocketAddress(localAddress)); serverChannel.setLocalAddress(localAddress); serverChannel.setTransport(datagramChannel); serverChannel.setBound(); evt.getFuture().setSuccess(); }
this.udpBootstrap = new ConnectionlessBootstrap(this.channelFactory); udpBootstrap.setOption("broadcast", "true"); this.pipelineFactory = pipelineFactory; udpBootstrap.setPipeline(pipelineFactory.getPipeline()); Runtime.getRuntime().addShutdownHook(new Thread()
/** * Creates a new datagram channel instance using the {@link #udpBootstrap} * by binding to local host. * * @param localhostName * The host machine (for e.g. 'localhost') to which it needs to * bind to. This is <b>Not</b> the remote jet-server hostname. * @return The newly created instance of the datagram channel. * @throws UnknownHostException */ public DatagramChannel createDatagramChannel(String localhostName) throws UnknownHostException { DatagramChannel datagramChannel = (DatagramChannel) udpBootstrap .bind(new InetSocketAddress(localhostName, 0)); return datagramChannel; }
/** * Creates the udpClient with proper handler. * * @return the bound request builder * @throws HttpRequestCreateException * the http request create exception */ public ConnectionlessBootstrap bootStrapUdpClient() throws HttpRequestCreateException { ConnectionlessBootstrap udpClient = null; try { // Configure the client. udpClient = new ConnectionlessBootstrap(udpMeta.getChannelFactory()); udpClient.setPipeline(new UdpPipelineFactory( TcpUdpSshPingResourceStore.getInstance().getTimer(), this) .getPipeline()); } catch (Exception t) { throw new TcpUdpRequestCreateException( "Error in creating request in udp worker. " + " If udpClient is null. Then fail to create.", t); } return udpClient; }
@Override public Bootstrap createServerBootstrap() { serverBootstrap = new ConnectionlessBootstrap( new NioDatagramChannelFactory(Executors .newCachedThreadPool(new NamedThreadFactory( "UDP-Server-Worker")))); return serverBootstrap; }
public void run(Timeout timeout) throws Exception { if (bootstrap instanceof ClientBootstrap) { ClientBootstrap b = (ClientBootstrap) bootstrap; b.setOption("remoteAddress", getRemoteAddress()); b.connect(); } else if (bootstrap instanceof ConnectionlessBootstrap) { ConnectionlessBootstrap b = (ConnectionlessBootstrap) bootstrap; b.setOption("remoteAddress", getRemoteAddress()); b.connect(); } } }, delay.get(), unit);
public void setReceiveBufferSize(int size) { assertDuringInitialization(); bootstrap.setOption("receiveBufferSize", size); }
udpBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
.connect(new InetSocketAddress(targetHost, udpMeta.getUdpPort()));