Example usage for com.google.common.collect Ranges closedOpen

List of usage examples for com.google.common.collect Ranges closedOpen

Introduction

In this page you can find the example usage for com.google.common.collect Ranges closedOpen.

Prototype

public static <C extends Comparable<?>> Range<C> closedOpen(C paramC1, C paramC2) 

Source Link

Usage

From source file:co.cask.cdap.gateway.handlers.DatasetServiceStore.java

@Override
public synchronized void setRestartAllInstancesRequest(String serviceName, long startTimeMs, long endTimeMs,
        boolean isSuccess) {
    Preconditions.checkNotNull(serviceName, "Service name should not be null.");

    RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE;
    int instanceCount = (this.getServiceInstance(serviceName) == null) ? 0
            : this.getServiceInstance(serviceName);
    Set<Integer> instancesToRestart = Ranges.closedOpen(0, instanceCount).asSet(DiscreteDomains.integers());

    RestartServiceInstancesStatus restartStatus = new RestartServiceInstancesStatus(serviceName, startTimeMs,
            endTimeMs, status, instancesToRestart);
    String toJson = GSON.toJson(restartStatus, RestartServiceInstancesStatus.class);

    table.put(Bytes.toBytes(serviceName + "-restart"), Bytes.toBytes(toJson));
}

From source file:com.conductor.kafka.zk.ZkUtils.java

/**
 * Checks whether the provided partition exists on the {@link Broker}.
 * //from ww  w  . j a v a2  s  .  com
 * @param broker
 *            the broker.
 * @param topic
 *            the topic.
 * @param partId
 *            the partition id.
 * @return true if this partition exists on the {@link Broker}, false otherwise.
 */
public boolean partitionExists(final Broker broker, final String topic, final int partId) {
    final String parts = client.readData(getTopicBrokerIdPath(topic, broker.getId()), true);
    return !Strings.isNullOrEmpty(parts) && Ranges.closedOpen(0, Integer.parseInt(parts)).contains(partId);
}

From source file:com.facebook.hiveio.input.HiveApiInputFormat.java

/**
 * Compute column IDs from names/*from ww w.  j a  v a 2s  . c om*/
 *
 * @param columnNames names of columns
 * @param tableSchema schema for Hive table
 * @return array of column IDs
 */
private int[] computeColumnIds(List<String> columnNames, HiveTableSchema tableSchema) {
    List<Integer> ints;
    if (columnNames.isEmpty()) {
        Range<Integer> range = Ranges.closedOpen(0, tableSchema.numColumns());
        ints = range.asSet(DiscreteDomains.integers()).asList();
    } else {
        ints = transform(columnNames, HiveTableSchemas.schemaLookupFunc(tableSchema));
    }
    int[] result = new int[ints.size()];
    for (int i = 0; i < ints.size(); ++i) {
        result[i] = ints.get(i);
    }
    return result;
}

From source file:com.google.cloud.genomics.denovo.VariantsBuffer.java

/** Get Matching variant from the queue
 * @param person trio member//w  w  w .  j  a  v  a  2  s.  c om
 * @param snpPosition
 * @return Get matching variant call pairs at matching position
 */
private Pair<Variant, Call> getMatchingPair(TrioMember person, Long snpPosition) {
    for (Pair<Variant, Call> pair : getQueue(person)) {
        Variant variant = pair.getValue0();

        if (Ranges.closedOpen(variant.getStart(), variant.getEnd()).contains(snpPosition)) {
            return pair;
        }
    }
    return null;
}

From source file:org.apache.twill.internal.appmaster.ApplicationMasterService.java

/**
 * Helper method to restart instances of runnables.
 *///from www.j a  v a  2s  .c  o m
private void restartRunnableInstances(final String runnableName, @Nullable final Set<Integer> instanceIds,
        final Runnable completion) {
    instanceChangeExecutor.execute(new Runnable() {
        @Override
        public void run() {
            LOG.debug("Begin restart runnable {} instances.", runnableName);
            int runningCount = runningContainers.count(runnableName);
            Set<Integer> instancesToRemove = instanceIds == null ? null : ImmutableSet.copyOf(instanceIds);
            if (instancesToRemove == null) {
                instancesToRemove = Ranges.closedOpen(0, runningCount).asSet(DiscreteDomains.integers());
            }

            LOG.info("Restarting instances {} for runnable {}", instancesToRemove, runnableName);
            RunnableContainerRequest containerRequest = createRunnableContainerRequest(runnableName,
                    instancesToRemove.size(), false);
            runnableContainerRequests.add(containerRequest);

            for (int instanceId : instancesToRemove) {
                LOG.debug("Stop instance {} for runnable {}", instanceId, runnableName);
                try {
                    runningContainers.stopByIdAndWait(runnableName, instanceId);
                } catch (Exception ex) {
                    // could be thrown if the container already stopped.
                    LOG.info("Exception thrown when stopping instance {} probably already stopped.",
                            instanceId);
                }
            }

            LOG.info("All instances in {} for runnable {} are stopped. Ready to provision", instancesToRemove,
                    runnableName);

            // set the container request to be ready
            containerRequest.setReadyToBeProvisioned();

            // For all runnables that needs to re-request for containers, update the expected count timestamp
            // so that the EventHandler would be triggered with the right expiration timestamp.
            expectedContainers.updateRequestTime(Collections.singleton(runnableName));

            completion.run();
        }
    });
}