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

Java Range类代码示例

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

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



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

示例1: buildPortRanges

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
public static Resource buildPortRanges(String... ranges) {
  Resource.Builder resources = Resource.newBuilder()
      .setType(Type.RANGES)
      .setName(MesosUtils.PORTS);

  Ranges.Builder rangesBuilder = Ranges.newBuilder();

  for (String range : ranges) {
    String[] split = range.split("\\:");

    rangesBuilder.addRange(
        Range.newBuilder()
        .setBegin(Long.parseLong(split[0]))
        .setEnd(Long.parseLong(split[1])));
  }

  resources.setRanges(rangesBuilder);

  return resources.build();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:21,代码来源:MesosUtilsTest.java


示例2: getPorts

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
public static long[] getPorts(Resource portsResource, int numPorts) {
  long[] ports = new long[numPorts];
  if (numPorts == 0) {
    return ports;
  }

  int idx = 0;

  for (Range r : portsResource.getRanges().getRangeList()) {
    for (long port = r.getBegin(); port <= r.getEnd(); port++) {
      ports[idx++] = port;

      if (idx >= numPorts) {
        return ports;
      }
    }
  }

  return ports;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:21,代码来源:MesosUtils.java


示例3: collectPorts

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private void collectPorts(List<Resource> offers, List<Integer> portList, int maxPorts) {
  for (Resource r : offers) {
    if (r.getName().equals("ports")) {
      for (Range range : r.getRanges().getRangeList()) {
        if (portList.size() >= maxPorts) {
          break;
        } else {
          int start = (int) range.getBegin();
          int end = (int) range.getEnd();
          for (int p = start; p <= end; p++) {
            portList.add(p);
            if (portList.size() >= maxPorts) {
              break;
            }
          }
        }
      }
    }
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:21,代码来源:MesosNimbus.java


示例4: getResourcesRange

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
protected List<Resource> getResourcesRange(final List<Resource> offerResources,
                                           final long value,
                                           final String name) {
  for (Resource r : offerResources) {
    if (r.hasReservation()) {
      // skip reserved resources
      continue;
    }
    if (r.getType() == Type.RANGES && r.getName().equals(name)) {
      for (Range range : r.getRanges().getRangeList()) {
        if (value >= range.getBegin() && value <= range.getEnd()) {
          return Arrays.asList(r.toBuilder()
              .setRanges(
                  Ranges.newBuilder()
                      .addRange(
                          Range.newBuilder().setBegin(value).setEnd(value).build()
                      ).build()
              )
              .build()
          );
        }
      }
    }
  }
  return new ArrayList<>();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:27,代码来源:MesosNimbus.java


示例5: testRangeIsInAny

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
@Test
public void testRangeIsInAny() {
    List<Range> r1 = Arrays.asList(getRange(1, 3), getRange(5, 7));
    assertFalse(RangeUtils.isInAny(r1, 0));
    assertTrue(RangeUtils.isInAny(r1, 1));
    assertTrue(RangeUtils.isInAny(r1, 2));
    assertTrue(RangeUtils.isInAny(r1, 3));
    assertFalse(RangeUtils.isInAny(r1, 4));
    assertTrue(RangeUtils.isInAny(r1, 5));
    assertTrue(RangeUtils.isInAny(r1, 6));
    assertTrue(RangeUtils.isInAny(r1, 7));
    assertFalse(RangeUtils.isInAny(r1, 8));

    List<Range> r2 = Arrays.asList(getRange(2, 2));
    assertFalse(RangeUtils.isInAny(r2, 1));
    assertTrue(RangeUtils.isInAny(r2, 2));
    assertFalse(RangeUtils.isInAny(r2, 3));
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:19,代码来源:RangeUtilsTest.java


示例6: getPortMappingIterator

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private Iterator<Long> getPortMappingIterator(TaskInfo taskInfo) {
    List<Resource> list = taskInfo.getResourcesList();
    List<Long> ports = new ArrayList<Long>();
    for (Resource resource : list) {
        String name = resource.getName();
        if ("ports".equals(name)) {
            Ranges ranges = resource.getRanges();
            for (Range range : ranges.getRangeList()) {
                long startPort = range.getBegin();
                long endPort = range.getEnd();
                for (int i = 0; i <= endPort - startPort; i++) {
                    ports.add(startPort + i);
                }
            }
        }
    }
    return ports.iterator();
}
 
开发者ID:mesos,项目名称:docker-compose-executor,代码行数:19,代码来源:ComposeRewriteHelper.java


示例7: getPortMappingIterator

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private Iterator<Long> getPortMappingIterator(TaskInfo taskInfo){
	List<Resource> list = taskInfo.getResourcesList();
	List<Long> ports = new ArrayList<Long>();
	for(Resource resource:list){
		String name = resource.getName();
		if("ports".equals(name)){
			Ranges ranges = resource.getRanges();
			for(Range range:ranges.getRangeList()){
				long startPort = range.getBegin();
				long endPort = range.getEnd();
				for(int i=0;i<=endPort-startPort;i++){
					ports.add(startPort+i);
				}
			}
		}
	}
	return ports.iterator();
}
 
开发者ID:mohitsoni,项目名称:compose-executor,代码行数:19,代码来源:DockerRewriteHelper.java


示例8: findOffer

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private OfferID findOffer(WorkerSlot worker) {
    int port = worker.getPort();
    ArrayList<Offer> offers = new ArrayList(_offers.values());
    Collections.shuffle(offers);
    for (Offer offer : offers) {
        if (offer.getHostname().equals(worker.getNodeId())) {
            for (Resource r : offer.getResourcesList()) {
                if (r.getName().equals("ports")) {
                    for (Range range : r.getRanges().getRangeList()) {
                        if (port >= range.getBegin() && port <= range.getEnd()) {
                            return offer.getId();
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
开发者ID:deric,项目名称:storm-mesos,代码行数:20,代码来源:MesosNimbus.java


示例9: getResourceMessage

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
/**
 * Creates string out an offer in a nice format.
 * @param resource - mesos resource to make into string.
 * @return string representing a resource.
 */
public static String getResourceMessage(Resource resource) {
    Type type = resource.getType();
    String ret = resource.getName() +" "+resource.getRole()+ ": ";
    switch (type) {
        case SCALAR:
            ret += resource.getScalar().getValue();
            break;
        case RANGES:
            for (Range range : resource.getRanges().getRangeList())
                ret += range.getBegin() + " - "+range.getEnd()+",";
            break;
        case TEXT:
            ret += " TEXT type...cannot find.";
            break;
        case SET:
            for (String string : resource.getSet().getItemList())
                ret += string + ",";
            break;
    }
    return ret;
}
 
开发者ID:apache,项目名称:oodt,代码行数:27,代码来源:MesosUtilities.java


示例10: getNumRanges

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private static int getNumRanges(List<Resource> resources, String name) {
  int totalRanges = 0;

  for (Range range : getRanges(resources, name).getRangeList()) {
    totalRanges += (range.getEnd() - range.getBegin()) + 1;
  }

  return totalRanges;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:10,代码来源:MesosUtils.java


示例11: getAllPorts

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
public static List<Long> getAllPorts(List<Resource> resources) {
  Ranges ranges = getRanges(resources, PORTS);

  final List<Long> ports = Lists.newArrayList();
  if (ranges != null) {
    for (Range range : ranges.getRangeList()) {
      for (long port = range.getBegin(); port <= range.getEnd(); port++) {
        ports.add(port);
      }
    }
  }

  return ports;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:15,代码来源:MesosUtils.java


示例12: getNumAvailablePorts

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private int getNumAvailablePorts() {
  int offeredPorts = 0;
  for (Range range : getPortRanges()) {
    offeredPorts += 1 + range.getEnd() - range.getBegin();
  }
  return offeredPorts;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:8,代码来源:Resources.java


示例13: getPortRanges

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private Iterable<Range> getPortRanges() {
  ImmutableList.Builder<Range> ranges = ImmutableList.builder();
  for (Resource r : getResources(PORTS.getMesosName())) {
    ranges.addAll(r.getRanges().getRangeList().iterator());
  }

  return ranges.build();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:9,代码来源:Resources.java


示例14: createPortRanges

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private Resource createPortRanges(Set<Pair<Integer, Integer>> ports) {
  Ranges.Builder ranges = Ranges.newBuilder();
  for (Pair<Integer, Integer> range : ports) {
    ranges.addRange(Range.newBuilder().setBegin(range.getFirst()).setEnd(range.getSecond()));
  }

  return Resource.newBuilder()
      .setName(PORTS.getMesosName())
      .setType(RANGES)
      .setRanges(ranges)
      .build();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:13,代码来源:ResourcesTest.java


示例15: createOffer

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
public static Offer createOffer(
    double cpu,
    double ramMb,
    double diskMb,
    Pair<Integer, Integer> portRange) {

  Ranges portRanges = Ranges.newBuilder()
      .addRange(Range
          .newBuilder().setBegin(portRange.getFirst()).setEnd(portRange.getSecond()).build())
      .build();

  return Offer.newBuilder()
      .addResources(Resource.newBuilder().setType(Type.SCALAR).setName(CPUS.getMesosName())
          .setScalar(Scalar.newBuilder().setValue(cpu)))
      .addResources(Resource.newBuilder().setType(Type.SCALAR).setName(RAM_MB.getMesosName())
          .setScalar(Scalar.newBuilder().setValue(ramMb)))
      .addResources(Resource.newBuilder().setType(Type.SCALAR).setName(DISK_MB.getMesosName())
          .setScalar(Scalar.newBuilder().setValue(diskMb)))
      .addResources(Resource.newBuilder().setType(Type.RANGES).setName(PORTS.getMesosName())
          .setRanges(portRanges))
      .addAttributes(Protos.Attribute.newBuilder().setType(Type.TEXT)
          .setName("host")
          .setText(Protos.Value.Text.newBuilder().setValue("slavehost")))
      .setSlaveId(SlaveID.newBuilder().setValue("SlaveId").build())
      .setHostname("slavehost")
      .setFrameworkId(Protos.FrameworkID.newBuilder().setValue("framework-id").build())
      .setId(OfferID.newBuilder().setValue("OfferId").build())
      .build();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:30,代码来源:Offers.java


示例16: rangeToString

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
/**
 * Create String representation of mesos protobuf Range type.
 */
private static String rangeToString(Range range) {
  String beginStr = String.valueOf(range.getBegin());
  String endStr = String.valueOf(range.getEnd());
  /*
   * A Range representing a single number still has both Range.begin
   * and Range.end populated, but they are set to the same value.
   * In that case we just return "N" instead of "N-N".
   */
  if (range.getBegin() == range.getEnd()) {
    return beginStr;
  } else {
    return beginStr + "-" + endStr;
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:18,代码来源:PrettyProtobuf.java


示例17: subtractRanges

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
/**
 * Removes the range intervals listed in {@code subtrahend} from {@code minuend}.
 */
public static List<Range> subtractRanges(List<Range> minuend, List<Range> subtrahend) {
    IntervalSet iMinuend = intervalsToIntervalSet(rangesToIntervals(minuend));
    IntervalSet iSubtrahend = intervalsToIntervalSet(rangesToIntervals(subtrahend));
    IntervalSet iDifference = IntervalSet.subtract(iMinuend, iSubtrahend);
    return intervalSetToRanges(iDifference);
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:10,代码来源:RangeUtils.java


示例18: isInAny

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
/**
 * Returns whether the provided value is encompassed by any of the provided ranges.
 */
public static boolean isInAny(List<Range> ranges, long value) {
    for (Interval interval : rangesToIntervals(ranges)) {
        if (interval.a <= value && value <= interval.b) {
            return true;
        }
    }
    return false;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:12,代码来源:RangeUtils.java


示例19: rangesToIntervals

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private static List<Interval> rangesToIntervals(List<Range> ranges) {
    List<Interval> intervals = new ArrayList<Interval>();
    for (Range range : ranges) {
        intervals.add(rangeToInterval(range));
    }
    return intervals;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:8,代码来源:RangeUtils.java


示例20: intervalsToRanges

import org.apache.mesos.Protos.Value.Range; //导入依赖的package包/类
private static List<Range> intervalsToRanges(List<Interval> intervals) {
    List<Range> ranges = new ArrayList<Range>();
    for (Interval interval : intervals) {
        ranges.add(Range.newBuilder().setBegin(interval.a).setEnd(interval.b).build());
    }
    return ranges;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:8,代码来源:RangeUtils.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java ProjectDependencyGraph类代码示例发布时间:2022-05-23
下一篇:
Java SimpleWebApplicationServiceSerializer类代码示例发布时间: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