本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}