/** * 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 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); }
@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(); }
@Override public void startServer(InetSocketAddress socketAddress) { this.socketAddress = socketAddress; //TODO these should be set from spring serverBootstrap.setOption("broadcast", "false"); serverBootstrap.setOption("receiveBufferSizePredictorFactory", bufferSizePredictor); serverBootstrap.setOption("sendBufferSize", 65536); serverBootstrap.setOption("receiveBufferSize", 65536); configureServerBootStrap(args); try { channel = ((ConnectionlessBootstrap) serverBootstrap) .bind(socketAddress); } catch (ChannelException e) { LOG.error("Unable to start UDP server due to error {}",e); throw e; } }
@Override public void start() { // setup Netty server ConnectionlessBootstrap serverBootstrap = new ConnectionlessBootstrap( new OioDatagramChannelFactory(Executors.newCachedThreadPool())); final syslogHandler handler = new syslogHandler(); handler.setFormater(formaterProp); handler.setKeepFields(keepFields); handler.setClientIPHeader(clientIPHeader); handler.setClientHostnameHeader(clientHostnameHeader); 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)); } sourceCounter.start(); super.start(); }
@Override public void startup() { runner.execute(messageTask); boot.bind(new InetSocketAddress(socketAddress)); }
@Override public void startup() { runner.execute(messageTask); for(final int address : socketAddress) { boot.bind(new InetSocketAddress(address)); } }
@Override public void start(boolean master) { this.channel = (DatagramChannel) bootstrap.bind(); LOG.info("Channel {} listening on port {}", channel, port); if (!isSendToServerInsteadOfMulticast()) { final int multicastPort = multicastGroup.getPort(); this.multicastChannel = (DatagramChannel) bootstrap.bind(new InetSocketAddress(multicastPort)); if (multicastNetworkInterface != null) { LOG.info("Channel {} joining multicast group {} on network interface {}", new Object[]{multicastChannel, multicastGroup, multicastNetworkInterface}); multicastChannel.joinGroup(multicastGroup, multicastNetworkInterface); } else { LOG.info("Channel {} joining multicast group {} ", multicastChannel, multicastGroup); multicastChannel.joinGroup(multicastGroup.getAddress()); } } else this.multicastChannel = null; setReady(true); }
@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(); }
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); }
public NioUdpGntpClient(GntpApplicationInfo applicationInfo, SocketAddress growlAddress, Executor executor, GntpPassword password, boolean encrypted) { super(applicationInfo, growlAddress, password, encrypted); Preconditions.checkNotNull(executor, "Executor must not be null"); bootstrap = new ConnectionlessBootstrap(new OioDatagramChannelFactory(executor)); bootstrap.setPipelineFactory(new GntpChannelPipelineFactory(new GntpChannelHandler(this, null))); bootstrap.setOption("broadcast", "false"); datagramChannel = (DatagramChannel) bootstrap.bind(new InetSocketAddress(0)); }
@Override public void start() { // setup Netty server ConnectionlessBootstrap serverBootstrap = new ConnectionlessBootstrap( new OioDatagramChannelFactory(Executors.newCachedThreadPool())); final syslogHandler handler = new syslogHandler(); handler.setFormater(formaterProp); handler.setKeepFields(keepFields); handler.setClientIPHeader(clientIPHeader); handler.setClientHostnameHeader(clientHostnameHeader); 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)); } sourceCounter.start(); super.start(); }
@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); } }
udpChannel = udpServer.bind(udpAddress); allChannels.add(tcpChannel); allChannels.add(udpChannel);
/** * Starts this application * * @param pipelineFactory the {@link CoapChannelPipelineFactory} that creates the instances of * {@link AbstractCoapChannelHandler}s that deal with inbound and outbound messages * @param localSocket the socket address to be used for inbound and outbound messages */ protected void startApplication(CoapChannelPipelineFactory pipelineFactory, InetSocketAddress localSocket) { //ChannelFactory channelFactory = new NioDatagramChannelFactory(executor, executor.getCorePoolSize() / 2 ); ChannelFactory channelFactory = new NioDatagramChannelFactory(executor, 1 ); //System.out.println("Threads: " + (executor.getCorePoolSize() - 1)); //Create and configure bootstrap ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(channelFactory); bootstrap.setPipelineFactory(pipelineFactory); bootstrap.setOption("receiveBufferSizePredictor", new FixedReceiveBufferSizePredictor(RECEIVE_BUFFER_SIZE)); //Create datagram channel this.channel = (DatagramChannel) bootstrap.bind(localSocket); // set the channel handler contexts for (ChannelHandler handler : pipelineFactory.getChannelHandlers()) { if (handler instanceof AbstractCoapChannelHandler) { ChannelHandlerContext context = this.channel.getPipeline().getContext(handler.getClass()); ((AbstractCoapChannelHandler) handler).setContext(context); } } }
@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(); }
} else { Channel channel = connectionlessClientBootstrap.bind(new InetSocketAddress(0)); allChannels.add(channel); answer = new SucceededChannelFuture(channel);
datagramChannel = (DatagramChannel)connectionlessBootstrap.bind(hostAddress); String networkInterface = configuration.getNetworkInterface() == null ? LOOPBACK_INTERFACE : configuration.getNetworkInterface(); multicastNetworkInterface = NetworkInterface.getByName(networkInterface); } else { LOG.info("ConnectionlessBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort()); channel = connectionlessBootstrap.bind(hostAddress); allChannels.add(channel);
try { channel = bootstrap.bind(local);