Java 类org.jboss.netty.channel.socket.DatagramChannelFactory 实例源码

项目:hadoop    文件:SimpleUdpServer.java   
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);
}
项目:aliyun-oss-hadoop-fs    文件:SimpleUdpServer.java   
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);
}
项目:big-c    文件:SimpleUdpServer.java   
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);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:SimpleUdpServer.java   
public void run() {
  // Configure the client.
  DatagramChannelFactory f = new NioDatagramChannelFactory(
      Executors.newCachedThreadPool(), workerCount);

  ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
  b.setPipeline(Channels.pipeline(
          RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram,
          RpcUtil.STAGE_RPC_UDP_RESPONSE));

  b.setOption("broadcast", "false");
  b.setOption("sendBufferSize", SEND_BUFFER_SIZE);
  b.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);

  // Listen to the UDP port
  Channel ch = b.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);
}
项目:hadoop-plus    文件:SimpleUdpServer.java   
public void run() {
  // Configure the client.
  DatagramChannelFactory f = new NioDatagramChannelFactory(
      Executors.newCachedThreadPool(), workerCount);

  ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
  ChannelPipeline p = b.getPipeline();
  p.addLast("handler", new SimpleUdpServerHandler(rpcProgram));

  b.setOption("broadcast", "false");
  b.setOption("sendBufferSize", SEND_BUFFER_SIZE);
  b.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);

  // Listen to the UDP port
  b.bind(new InetSocketAddress(port));

  LOG.info("Started listening to UDP requests at port " + port + " for "
      + rpcProgram + " with workerCount " + workerCount);
}
项目:hops    文件:SimpleUdpServer.java   
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);
}
项目:hadoop-TCP    文件:SimpleUdpServer.java   
public void run() {
  // Configure the client.
  DatagramChannelFactory f = new NioDatagramChannelFactory(
      Executors.newCachedThreadPool(), workerCount);

  ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
  b.setPipeline(Channels.pipeline(
          RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram,
          RpcUtil.STAGE_RPC_UDP_RESPONSE));

  b.setOption("broadcast", "false");
  b.setOption("sendBufferSize", SEND_BUFFER_SIZE);
  b.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);

  // Listen to the UDP port
  b.bind(new InetSocketAddress(port));

  LOG.info("Started listening to UDP requests at port " + port + " for "
      + rpcProgram + " with workerCount " + workerCount);
}
项目:pinpoint    文件:NettyUdpReceiverTest.java   
private ConnectionlessBootstrap createUdpServer() {
        DatagramChannelFactory udpFactory = new NioDatagramChannelFactory(Executors.newCachedThreadPool(), 4);
        ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
            @Override
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline pipeline = Channels.pipeline();
                pipeline.addLast("test", new SimpleChannelHandler() {
                    @Override
                    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
                        String name = Thread.currentThread().getName();
                        logger.debug("sleep:{}", name);
                        Thread.sleep(10000);
//                        if (!name.equals("New I/O worker #1")) {
                            logger.debug("messageReceived thread-{} message:", Thread.currentThread().getName());
//                        }
                    }
                });
                return pipeline;
            }
        };
        ConnectionlessBootstrap udpBootstrap = new ConnectionlessBootstrap(udpFactory);
        udpBootstrap.setPipelineFactory(pipelineFactory);
        return udpBootstrap;
    }
项目:hardfs    文件:SimpleUdpServer.java   
public void run() {
  // Configure the client.
  DatagramChannelFactory f = new NioDatagramChannelFactory(
      Executors.newCachedThreadPool(), workerCount);

  ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
  b.setPipeline(Channels.pipeline(
          RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram,
          RpcUtil.STAGE_RPC_UDP_RESPONSE));

  b.setOption("broadcast", "false");
  b.setOption("sendBufferSize", SEND_BUFFER_SIZE);
  b.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);

  // Listen to the UDP port
  b.bind(new InetSocketAddress(port));

  LOG.info("Started listening to UDP requests at port " + port + " for "
      + rpcProgram + " with workerCount " + workerCount);
}
项目:hadoop-on-lustre2    文件:SimpleUdpServer.java   
public void run() {
  // Configure the client.
  DatagramChannelFactory f = new NioDatagramChannelFactory(
      Executors.newCachedThreadPool(), workerCount);

  ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
  b.setPipeline(Channels.pipeline(
          RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram,
          RpcUtil.STAGE_RPC_UDP_RESPONSE));

  b.setOption("broadcast", "false");
  b.setOption("sendBufferSize", SEND_BUFFER_SIZE);
  b.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);

  // Listen to the UDP port
  Channel ch = b.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);
}
项目:parallec    文件:UdpMeta.java   
public UdpMeta(String command, int udpPort, int udpIdleTimeoutSec,
        DatagramChannelFactory channelFactory) {
    super();
    this.command = command;
    this.udpPort = udpPort;
    this.udpIdleTimeoutSec = udpIdleTimeoutSec;
    this.channelFactory = channelFactory;

}
项目:HIndex    文件:ClusterStatusListener.java   
@Override
public void connect(Configuration conf) throws IOException {
  // Can't be NiO with Netty today => not implemented in Netty.
  DatagramChannelFactory f = new OioDatagramChannelFactory(service);

  ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
  b.setPipeline(Channels.pipeline(
      new ProtobufDecoder(ClusterStatusProtos.ClusterStatus.getDefaultInstance()),
      new ClusterStatusHandler()));

  String mcAddress = conf.get(HConstants.STATUS_MULTICAST_ADDRESS,
      HConstants.DEFAULT_STATUS_MULTICAST_ADDRESS);
  String bindAddress = conf.get(HConstants.STATUS_MULTICAST_BIND_ADDRESS,
    HConstants.DEFAULT_STATUS_MULTICAST_BIND_ADDRESS);
  int port = conf.getInt(HConstants.STATUS_MULTICAST_PORT,
      HConstants.DEFAULT_STATUS_MULTICAST_PORT);

  channel = (DatagramChannel) b.bind(new InetSocketAddress(bindAddress, port));

  channel.getConfig().setReuseAddress(true);

  InetAddress ina;
  try {
    ina = InetAddress.getByName(mcAddress);
  } catch (UnknownHostException e) {
    throw new IOException("Can't connect to " + mcAddress, e);
  }
  channel.joinGroup(ina);
}
项目:c5    文件:ClusterStatusListener.java   
@Override
public void connect(Configuration conf) throws IOException {
  // Can't be NiO with Netty today => not implemented in Netty.
  DatagramChannelFactory f = new OioDatagramChannelFactory(service);

  ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
  b.setPipeline(Channels.pipeline(
      new ProtobufDecoder(ClusterStatusProtos.ClusterStatus.getDefaultInstance()),
      new ClusterStatusHandler()));

  String mcAddress = conf.get(HConstants.STATUS_MULTICAST_ADDRESS,
      HConstants.DEFAULT_STATUS_MULTICAST_ADDRESS);
  String bindAddress = conf.get(HConstants.STATUS_MULTICAST_BIND_ADDRESS,
    HConstants.DEFAULT_STATUS_MULTICAST_BIND_ADDRESS);
  int port = conf.getInt(HConstants.STATUS_MULTICAST_PORT,
      HConstants.DEFAULT_STATUS_MULTICAST_PORT);

  channel = (DatagramChannel) b.bind(new InetSocketAddress(bindAddress, port));

  channel.getConfig().setReuseAddress(true);

  InetAddress ina;
  try {
    ina = InetAddress.getByName(mcAddress);
  } catch (UnknownHostException e) {
    throw new IOException("Can't connect to " + mcAddress, e);
  }
  channel.joinGroup(ina);
}
项目:parallec    文件:TcpUdpSshPingResourceStore.java   
public DatagramChannelFactory getDatagramChannelFactory() {
    return datagramChannelFactory;
}
项目:parallec    文件:TcpUdpSshPingResourceStore.java   
public void setDatagramChannelFactory(DatagramChannelFactory datagramChannelFactory) {
    this.datagramChannelFactory = datagramChannelFactory;
}
项目:parallec    文件:UdpMeta.java   
public void setChannelFactory(DatagramChannelFactory channelFactory) {
    this.channelFactory = channelFactory;
}
项目:dhcp    文件:ClientSimulatorV6.java   
/**
   * Start sending DHCPv6 SOLICITs.
   */
  public void start()
  {
    DatagramChannelFactory factory = 
        new OioDatagramChannelFactory(Executors.newCachedThreadPool());

    server = new InetSocketAddress(serverAddr, serverPort);
    client = new InetSocketAddress(clientPort);

ChannelPipeline pipeline = Channels.pipeline();
      pipeline.addLast("logger", new LoggingHandler());
      pipeline.addLast("encoder", new DhcpV6ChannelEncoder());
      pipeline.addLast("decoder", new DhcpV6ChannelDecoder(client, false));
      pipeline.addLast("executor", new ExecutionHandler(
            new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)));
      pipeline.addLast("handler", this);

      channel = factory.newChannel(pipeline);
channel.getConfig().setNetworkInterface(mcastNetIf);
    channel.bind(client);

    for (int i=1; i<=numRequests; i++) {
        executor.execute(new ClientMachine(i));
    }

    synchronized (syncDone) {
        long ms = timeout * 1000;
        try {
            log.info("Waiting total of " + timeout + " milliseconds for completion");
            syncDone.wait(ms);
        }
        catch (InterruptedException ex) {
            log.error("Interrupted", ex);
        }
}

log.info("Complete: solicitsSent=" + solicitsSent +
        " advertisementsReceived=" + advertisementsReceived +
        " requestsSent=" + requestsSent +
        " requestRepliesReceived=" + requestRepliesReceived +
        " releasesSent=" + releasesSent +
        " releaseRepliesReceived=" + releaseRepliesReceived +
        " elapsedTime=" + (endTime - startTime) + "ms");

    log.info("Shutting down executor...");
    executor.shutdownNow();
    log.info("Closing channel...");
    channel.close();
    log.info("Done.");
    if ((solicitsSent.get() == advertisementsReceived.get()) &&
            (requestsSent.get() == requestRepliesReceived.get()) &&
            (releasesSent.get() == releaseRepliesReceived.get())) {

        System.exit(0);
    }
    else {
        System.exit(1);
    }
  }
项目:dhcp    文件:ClientSimulatorV4.java   
/**
   * Start sending DHCPv4 DISCOVERs.
   */
  public void start()
  {
    DatagramChannelFactory factory = 
        new NioDatagramChannelFactory(Executors.newCachedThreadPool());

    server = new InetSocketAddress(serverAddr, serverPort);
    client = new InetSocketAddress(clientPort);

ChannelPipeline pipeline = Channels.pipeline();
      pipeline.addLast("logger", new LoggingHandler());
      pipeline.addLast("encoder", new DhcpV4ChannelEncoder());
      pipeline.addLast("decoder", new DhcpV4ChannelDecoder(client, false));
      pipeline.addLast("executor", new ExecutionHandler(
            new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)));
      pipeline.addLast("handler", this);

      channel = factory.newChannel(pipeline);
    channel.bind(client);

    for (int i=1; i<=numRequests; i++) {
        executor.execute(new ClientMachine(i));
    }

    synchronized (syncDone) {
        long ms = timeout * 1000;
        try {
            log.info("Waiting total of " + timeout + " milliseconds for completion");
            syncDone.wait(ms);
        }
        catch (InterruptedException ex) {
            log.error("Interrupted", ex);
        }
}

log.info("Complete: discoversSent=" + discoversSent +
        " offersReceived=" + offersReceived +
        " requestsSent=" + requestsSent +
        " acksReceived=" + acksReceived +
        " releasesSent=" + releasesSent +
        " elapsedTime=" + (endTime - startTime) + "ms");

    log.info("Shutting down executor...");
    executor.shutdownNow();
    log.info("Closing channel...");
    channel.close();
    log.info("Done.");
    if ((discoversSent.get() == offersReceived.get()) &&
            (requestsSent.get() == acksReceived.get()) &&
            (releasesSent.get() == numRequests)) {

        System.exit(0);
    }
    else {
        System.exit(1);
    }
  }
项目:elasterix    文件:SipServer.java   
public void setDatagramChannelFactory(DatagramChannelFactory datagramChannelFactory) {
    this.datagramChannelFactory = datagramChannelFactory;
}