udpBootstrap.setPipeline(pipelineFactory.getPipeline()); Runtime.getRuntime().addShutdownHook(new Thread()
/** * 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; }
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); }
Executors.newCachedThreadPool())); udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, handler, RpcUtil.STAGE_RPC_UDP_RESPONSE));
/** * 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; }