当前位置: 首页>>代码示例>>Java>>正文


Java Value.Range方法代码示例

本文整理汇总了Java中org.apache.mesos.Protos.Value.Range方法的典型用法代码示例。如果您正苦于以下问题:Java Value.Range方法的具体用法?Java Value.Range怎么用?Java Value.Range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mesos.Protos.Value的用法示例。


在下文中一共展示了Value.Range方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pickAndRegisterPortNumber

import org.apache.mesos.Protos.Value; //导入方法依赖的package包/类
/**
 * Picks a port number from the given offer's port resources
 *
 * @param taskId the TaskID to register the picked ports with
 * @param offer  the offer from which's resources to pick a port
 * @return a port number
 */
public long pickAndRegisterPortNumber(TaskID taskId, Offer offer) {
    for (Resource resource : offer.getResourcesList()) {
        if (!resource.getName().equals("ports")) continue;

        List<Value.Range> offeredRanges = resource.getRanges().getRangeList();
        for (Value.Range portRange : offeredRanges) {
            long begin = portRange.getBegin();
            long end = portRange.getEnd();
            for (long port = begin; port < end; port++) {
                if (!usedPortNumbers.values().contains(port)) {
                    usedPortNumbers.put(taskId, port);
                    LOGGER.info("Task {} received port {}.", taskId, port);
                    return port;
                }
            }
        }
    }
    LOGGER.warn("Offer {} had no unused port to offer! Task {} received no port!", offer.getId().getValue(), taskId.getValue());
    return -1;
}
 
开发者ID:Praqma,项目名称:mesos-kibana,代码行数:28,代码来源:SchedulerConfiguration.java

示例2: buildPortResource

import org.apache.mesos.Protos.Value; //导入方法依赖的package包/类
/**
 * Creates a port Resource with given port range
 *
 * @param begin the beginning of the port range
 * @param end   the end of the port range
 * @return a port Resource with given port range
 */
public static Resource buildPortResource(long begin, long end) {
    Value.Range ports = Value.Range.newBuilder().setBegin(begin).setEnd(end).build();
    return Resource.newBuilder()
            .setName("ports")
            .setType(Value.Type.RANGES)
            .setRanges(Value.Ranges.newBuilder().addRange(ports))
            .build();
}
 
开发者ID:Praqma,项目名称:mesos-kibana,代码行数:16,代码来源:Resources.java

示例3: getPortCount

import org.apache.mesos.Protos.Value; //导入方法依赖的package包/类
/**
 * Counts the amount of ports offered in the given resource
 *
 * @param resource the resource to count the ports for
 * @return the number of ports offered in the resource
 */
public static int getPortCount(Resource resource) {
    int portCount = 0;
    List<Value.Range> offeredRanges = resource.getRanges().getRangeList();
    for (Value.Range portRange : offeredRanges) {
        long begin = portRange.getBegin();
        long end = portRange.getEnd();
        portCount += end - begin + 1;
    }
    return portCount;
}
 
开发者ID:Praqma,项目名称:mesos-kibana,代码行数:17,代码来源:Resources.java

示例4: findPortsToUse

import org.apache.mesos.Protos.Value; //导入方法依赖的package包/类
@VisibleForTesting
SortedSet<Long> findPortsToUse(Offer offer, int maxCount) {
    SortedSet<Long> portsToUse = new TreeSet<Long>();
    List<Value.Range> portRangesList = null;

    // Locate the port resource in the offer
    for (Resource resource : offer.getResourcesList()) {
      if (resource.getName().equals(PORT_RESOURCE_NAME)) {
        portRangesList = resource.getRanges().getRangeList();
        break;
      }
    }

    LOGGER.fine("portRangesList=" + portRangesList);

    /**
     * We need to find maxCount ports to use.
     * We are provided a list of port ranges to use
     * We are assured by the offer check that we have enough ports to use
     */
    // Check this port range for ports that we can use
    if (portRangesList != null) {
      for (Value.Range currentPortRange : portRangesList) {
        // Check each port until we reach the end of the current range
        long begin = currentPortRange.getBegin();
        long end = currentPortRange.getEnd();
        for (long candidatePort = begin; candidatePort <= end && portsToUse.size() < maxCount; candidatePort++) {
          portsToUse.add(candidatePort);
        }
      }
    }

    return portsToUse;
}
 
开发者ID:jenkinsci,项目名称:mesos-plugin,代码行数:35,代码来源:JenkinsScheduler.java


注:本文中的org.apache.mesos.Protos.Value.Range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。