Example usage for java.util.function Supplier get

List of usage examples for java.util.function Supplier get

Introduction

In this page you can find the example usage for java.util.function Supplier get.

Prototype

T get();

Source Link

Document

Gets a result.

Usage

From source file:org.kie.server.integrationtests.prometheus.PrometheusIntegrationTest.java

@Test
public void testPrometheusProcessAndTaskMetrics() {
    processClient.startProcess(CONTAINER_ID, PROCESS_ID);
    Long instanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID);
    processClient.abortProcessInstance(CONTAINER_ID, instanceId);

    taskClient.findTasksAssignedAsPotentialOwner(USER_ID, 0, 100).forEach(task -> {
        taskClient.startTask(CONTAINER_ID, task.getId(), USER_ID);
        taskClient.completeTask(CONTAINER_ID, task.getId(), USER_ID, null);
    });// w  w  w .j a v  a 2s  .  c o  m

    List<ProcessInstance> instances = queryClient.findProcessInstancesByProcessId(PROCESS_ID,
            Arrays.asList(STATE_COMPLETED, STATE_ABORTED), 0, 100);

    int totalInstances = instances.size();
    long completedInstances = instances.stream().filter(pi -> pi.getState() == STATE_COMPLETED).count();
    long abortedInstances = instances.stream().filter(pi -> pi.getState() == STATE_ABORTED).count();

    final List<TaskSummary> tasks = taskClient.findTasks(USER_ID, 0, 1000);
    final Supplier<Stream<TaskSummary>> taskSummaryStream = () -> tasks.stream().filter(
            t -> "First task".equals(t.getName()) && CONTAINER_ID.equals(t.getContainerId()) && StringUtils
                    .equalsAny(t.getStatus(), Status.Completed.toString(), Status.Exited.toString()));
    long totalTasks = taskSummaryStream.get().count();
    long completedTasks = taskSummaryStream.get().filter(t -> Status.Completed.toString().equals(t.getStatus()))
            .count();
    long exitedTasks = taskSummaryStream.get().filter(t -> Status.Exited.toString().equals(t.getStatus()))
            .count();

    assertThat(getMetrics()).contains(format(
            "kie_server_process_instance_started_total{container_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",} %d.0",
            totalInstances),
            format("kie_server_process_instance_completed_total{container_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",status=\"2\",} %d.0",
                    completedInstances),
            format("kie_server_process_instance_completed_total{container_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",status=\"3\",} %d.0",
                    abortedInstances),
            format("kie_server_process_instance_duration_seconds_count{container_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",} %d.0",
                    totalInstances),
            "kie_server_process_instance_duration_seconds_sum{container_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",}",
            "kie_server_process_instance_running_total{container_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",} 0.0",
            "kie_server_work_item_duration_seconds_count{name=\"Human Task\",}",
            "kie_server_work_item_duration_seconds_sum{name=\"Human Task\",}",
            format("kie_server_task_added_total{deployment_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",task_name=\"First task\",} %d.0",
                    totalTasks),
            format("kie_server_task_completed_total{deployment_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",task_name=\"First task\",} %d.0",
                    completedTasks),
            format("kie_server_task_duration_seconds_count{deployment_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",task_name=\"First task\",} %d.0",
                    totalTasks),
            "kie_server_task_duration_seconds_sum{deployment_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",task_name=\"First task\",}",
            format("kie_server_task_exited_total{deployment_id=\"prometheus\",process_id=\"per-process-instance-project.usertask\",task_name=\"First task\",} %d.0",
                    exitedTasks));
}

From source file:org.lanternpowered.server.data.manipulator.gen.DataManipulatorGenerator.java

@SuppressWarnings("unchecked")
public <M extends ListData<E, M, I>, I extends ImmutableListData<E, I, M>, E> DataManipulatorRegistration<M, I> newListRegistrationFor(
        PluginContainer pluginContainer, String id, String name, Class<M> manipulatorType,
        Class<I> immutableManipulatorType, Key<ListValue<E>> key, Supplier<List<E>> listSupplier) {
    final Base<M, I> base = generateBase(this.abstractListDataTypeGenerator, pluginContainer, id, name,
            manipulatorType, immutableManipulatorType, null, null, null, null);
    try {/*from  w w  w .ja  v  a  2 s .  c  o  m*/
        base.mutableManipulatorTypeImpl.getField(AbstractListDataTypeGenerator.KEY).set(null, key);
        base.mutableManipulatorTypeImpl.getField(AbstractListDataTypeGenerator.LIST_SUPPLIER).set(null,
                listSupplier);
        base.immutableManipulatorTypeImpl.getField(AbstractListDataTypeGenerator.KEY).set(null, key);
        base.immutableManipulatorTypeImpl.getField(AbstractListDataTypeGenerator.LIST_SUPPLIER).set(null,
                (Supplier<List>) () -> ImmutableList.copyOf(listSupplier.get()));
    } catch (IllegalAccessException | NoSuchFieldException e) {
        throw new RuntimeException(e);
    }
    return base.supplier.get();
}

From source file:org.lightjason.examples.pokemon.CCommon.java

/**
 * creates an int-pair-stream/*from  w  ww. j a  v  a2 s .c  o m*/
 *
 * @param p_firststart start value of first component
 * @param p_firstend end (inclusive) of first component
 * @param p_secondstart start value of second component
 * @param p_secondend end (inclusive) of second component
 * @return int-pair-sream
 */
public static Stream<Pair<Integer, Integer>> inttupelstream(final int p_firststart, final int p_firstend,
        final int p_secondstart, final int p_secondend) {
    final Supplier<IntStream> l_inner = () -> IntStream.rangeClosed(p_secondstart, p_secondend);
    return IntStream.rangeClosed(p_firststart, p_firstend).boxed()
            .flatMap(i -> l_inner.get().mapToObj(j -> new ImmutablePair<>(i, j)));
}

From source file:org.magicdgs.popgenlib.neutralitytest.TajimasD.java

@VisibleForTesting
static double tajimasD(final double pairwiseDifferences, final Supplier<Double> thetaSupplier,
        final double variance) {
    // variance equals 0 returns directly
    if (variance == 0) {
        return 0;
    }// w w w .  j  a  v  a2s.  c o  m
    // returns by computing theta
    return (pairwiseDifferences - thetaSupplier.get()) / variance;
}

From source file:org.matsim.contrib.drt.routing.StopBasedDrtRoutingModule.java

private void printError(Supplier<String> supplier) {
    if (drtCfg.isPrintDetailedWarnings()) {
        Logger.getLogger(getClass()).error(supplier.get());
    }//ww  w  . ja v a2s.c o  m
}

From source file:org.moe.gradle.utils.TaskUtils.java

public static <T> T compute(@NotNull Supplier<T> supplier) {
    return supplier.get();
}

From source file:org.nuxeo.ecm.core.io.download.DownloadServiceImpl.java

@Override
public void transferBlobWithByteRange(Blob blob, ByteRange byteRange,
        Supplier<OutputStream> outputStreamSupplier) throws UncheckedIOException {
    try (InputStream in = blob.getStream()) {
        @SuppressWarnings("resource")
        OutputStream out = outputStreamSupplier.get(); // not ours to close
        BufferingServletOutputStream.stopBuffering(out);
        if (byteRange == null) {
            IOUtils.copy(in, out);/*from  w  w  w  .  j a  v a2s. c o  m*/
        } else {
            IOUtils.copyLarge(in, out, byteRange.getStart(), byteRange.getLength());
        }
        out.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.nuxeo.runtime.api.Framework.java

/**
 * Calls the given {@link Supplier} while logged in as a system user and returns its result.
 *
 * @param supplier what to call/*from   w ww  .  j a v  a2s.  c om*/
 * @return the supplier's result
 * @since 8.4
 */
public static <T> T doPrivileged(Supplier<T> supplier) {
    try {
        LoginContext loginContext = login();
        try {
            return supplier.get();
        } finally {
            if (loginContext != null) { // may be null in tests
                loginContext.logout();
            }
        }
    } catch (LoginException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.nuxeo.runtime.transaction.TransactionHelper.java

/**
 * Calls the given {@link Supplier} in a transactional context. Will not start a new transaction if one already
 * exists./*from w  w  w  .  j a  va2s  .  c om*/
 *
 * @param supplier the {@link Supplier}
 * @return the supplier's result
 * @since 8.4
 */
public static <R> R runInTransaction(Supplier<R> supplier) {
    boolean startTransaction = !isTransactionActiveOrMarkedRollback();
    if (startTransaction) {
        if (!startTransaction()) {
            throw new TransactionRuntimeException("Cannot start transaction");
        }
    }
    boolean completedAbruptly = true;
    try {
        R result = supplier.get();
        completedAbruptly = false;
        return result;
    } finally {
        try {
            if (completedAbruptly) {
                setTransactionRollbackOnly();
            }
        } finally {
            if (startTransaction) {
                commitOrRollbackTransaction();
            }
        }
    }
}

From source file:org.obiba.mica.core.service.AbstractGitPersistableService.java

@NotNull
public T findEntityState(T1 gitPersistable, Supplier<T> stateSupplier) {
    T defaultState;/*  w ww  .j av  a 2s.c  o  m*/

    if (gitPersistable.isNew()) {
        defaultState = stateSupplier.get();
        defaultState.setId(generateId(gitPersistable));
        getEntityStateRepository().save(defaultState);
        gitPersistable.setId(defaultState.getId());

        return defaultState;
    }

    T existingState = getEntityStateRepository().findOne(gitPersistable.getId());

    if (existingState == null) {
        defaultState = stateSupplier.get();
        defaultState.setId(gitPersistable.getId());
        getEntityStateRepository().save(defaultState);

        return defaultState;
    }

    return existingState;
}