• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DatagramChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jboss.netty.channel.socket.DatagramChannel的典型用法代码示例。如果您正苦于以下问题:Java DatagramChannel类的具体用法?Java DatagramChannel怎么用?Java DatagramChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DatagramChannel类属于org.jboss.netty.channel.socket包,在下文中一共展示了DatagramChannel类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: connect

import org.jboss.netty.channel.socket.DatagramChannel; //导入依赖的package包/类
@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);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:30,代码来源:ClusterStatusListener.java


示例2: exceptionCaught

import org.jboss.netty.channel.socket.DatagramChannel; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    LOG.warn("Caught exception during channel read", e);

    if (ctx.getChannel() != null && !(ctx.getChannel() instanceof DatagramChannel)) {
        LOG.warn("Closing channel of IngestHandler");
        ctx.getChannel().close();
    }
}
 
开发者ID:Multifarious,项目名称:kafkalog,代码行数:10,代码来源:IngestHandler.java


示例3: shutdown

import org.jboss.netty.channel.socket.DatagramChannel; //导入依赖的package包/类
/**
   * Shutdown.
   */
  public void shutdown()
  {
  	log.info("Closing channels");
for (DatagramChannel channel : channels) {
	channel.close();
}
log.info("Executor shutdown");
      executorService.shutdown();     
  }
 
开发者ID:jagornet,项目名称:dhcp,代码行数:13,代码来源:NettyDhcpServer.java


示例4: closeChannel

import org.jboss.netty.channel.socket.DatagramChannel; //导入依赖的package包/类
private void closeChannel(Channel channel) {
    if (!(channel instanceof DatagramChannel)) {
        channel.close();
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:6,代码来源:MainEventHandler.java


示例5: decodeGprmc

import org.jboss.netty.channel.socket.DatagramChannel; //导入依赖的package包/类
private Position decodeGprmc(
        DeviceSession deviceSession, String sentence, SocketAddress remoteAddress, Channel channel) {

    if (ack && channel != null && !(channel instanceof DatagramChannel)) {
        channel.write("OK1\r\n");
    }

    Parser parser = new Parser(PATTERN_GPRMC, sentence);
    if (!parser.matches()) {
        return null;
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());

    if (deviceSession != null) {
        position.setDeviceId(deviceSession.getDeviceId());
    }

    DateBuilder dateBuilder = new DateBuilder()
            .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));

    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));

    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setTime(dateBuilder.getDate());

    if (parser.hasNext(5)) {
        position.set(Position.KEY_SATELLITES, parser.nextInt());

        deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
        if (deviceSession == null) {
            return null;
        }
        position.setDeviceId(deviceSession.getDeviceId());

        position.set(Position.KEY_IGNITION, parser.hasNext() && parser.next().equals("1"));
        position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
        position.set(Position.KEY_BATTERY, parser.nextInt());
    }

    if (parser.hasNext()) {
        String[] parameters = parser.next().split(",");
        for (int i = 1; i < parameters.length; i++) {
            position.set(Position.PREFIX_IO + i, parameters[i]);
        }
    }

    if (deviceSession != null) {
        return position;
    } else {
        this.position = position; // save position
        return null;
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:60,代码来源:T55ProtocolDecoder.java


示例6: startServerBootstrap

import org.jboss.netty.channel.socket.DatagramChannel; //导入依赖的package包/类
protected void startServerBootstrap() throws Exception {
    // create non-shared worker pool
    int count = configuration.getWorkerCount() > 0 ? configuration.getWorkerCount() : NettyHelper.DEFAULT_IO_THREADS;
    workerPool = new NioDatagramWorkerPool(Executors.newCachedThreadPool(), count);

    datagramChannelFactory = new NioDatagramChannelFactory(workerPool);

    connectionlessBootstrap = new ConnectionlessBootstrap(datagramChannelFactory);
    connectionlessBootstrap.setOption("child.keepAlive", configuration.isKeepAlive());
    connectionlessBootstrap.setOption("child.tcpNoDelay", configuration.isTcpNoDelay());
    connectionlessBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
    connectionlessBootstrap.setOption("child.reuseAddress", configuration.isReuseAddress());
    connectionlessBootstrap.setOption("child.connectTimeoutMillis", configuration.getConnectTimeout());
    connectionlessBootstrap.setOption("child.broadcast", configuration.isBroadcast());
    connectionlessBootstrap.setOption("sendBufferSize", configuration.getSendBufferSize());
    connectionlessBootstrap.setOption("receiveBufferSize", configuration.getReceiveBufferSize());
    // only set this if user has specified
    if (configuration.getReceiveBufferSizePredictor() > 0) {
        connectionlessBootstrap.setOption("receiveBufferSizePredictorFactory",
                new FixedReceiveBufferSizePredictorFactory(configuration.getReceiveBufferSizePredictor()));
    }
    if (configuration.getBacklog() > 0) {
        connectionlessBootstrap.setOption("backlog", configuration.getBacklog());
    }

    // set any additional netty options
    if (configuration.getOptions() != null) {
        for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
            connectionlessBootstrap.setOption(entry.getKey(), entry.getValue());
        }
    }

    LOG.debug("Created ConnectionlessBootstrap {} with options: {}", connectionlessBootstrap, connectionlessBootstrap.getOptions());

    // set the pipeline factory, which creates the pipeline for each newly created channels
    connectionlessBootstrap.setPipelineFactory(pipelineFactory);

    InetSocketAddress hostAddress = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    IpV4Subnet multicastSubnet = new IpV4Subnet(MULTICAST_SUBNET);

    if (multicastSubnet.contains(configuration.getHost())) {
        datagramChannel = (DatagramChannel)connectionlessBootstrap.bind(hostAddress);
        String networkInterface = configuration.getNetworkInterface() == null ? LOOPBACK_INTERFACE : configuration.getNetworkInterface();
        multicastNetworkInterface = NetworkInterface.getByName(networkInterface);
        ObjectHelper.notNull(multicastNetworkInterface, "No network interface found for '" + networkInterface + "'.");
        LOG.info("ConnectionlessBootstrap joining {}:{} using network interface: {}", new Object[]{configuration.getHost(), configuration.getPort(), multicastNetworkInterface.getName()});
        datagramChannel.joinGroup(hostAddress, multicastNetworkInterface).syncUninterruptibly();
        allChannels.add(datagramChannel);
    } else {
        LOG.info("ConnectionlessBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
        channel = connectionlessBootstrap.bind(hostAddress);
        allChannels.add(channel);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:55,代码来源:SingleUDPNettyServerBootstrapFactory.java



注:本文中的org.jboss.netty.channel.socket.DatagramChannel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MulExpr类代码示例发布时间:2022-05-23
下一篇:
Java Entry类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap