Example usage for java.util.function BiConsumer accept

List of usage examples for java.util.function BiConsumer accept

Introduction

In this page you can find the example usage for java.util.function BiConsumer accept.

Prototype

void accept(T t, U u);

Source Link

Document

Performs this operation on the given arguments.

Usage

From source file:org.keycloak.testsuite.admin.ComponentsTest.java

private void testConcurrency(BiConsumer<ExecutorService, Integer> taskCreator) throws InterruptedException {
    ExecutorService s = Executors.newFixedThreadPool(NUMBER_OF_THREADS, new BasicThreadFactory.Builder()
            .daemon(true).uncaughtExceptionHandler((t, e) -> log.error(e.getMessage(), e)).build());
    this.remainingDeleteSubmissions = new CountDownLatch(NUMBER_OF_TASKS);

    for (int i = 0; i < NUMBER_OF_TASKS; i++) {
        taskCreator.accept(s, i);
    }/*  w  ww.j  a  v  a2 s .  co m*/

    try {
        assertTrue("Did not create all components in time",
                this.remainingDeleteSubmissions.await(30, TimeUnit.SECONDS));
        s.shutdown();
        assertTrue("Did not finish before timeout", s.awaitTermination(30, TimeUnit.SECONDS));
    } finally {
        s.shutdownNow();
    }
}

From source file:org.ligoj.app.plugin.id.dao.IdCacheDao.java

private long updateDelegateDn(final Map<String, ? extends CacheContainer> containers, final Object type,
        final String typePath, final Function<DelegateOrg, String> id, Function<DelegateOrg, String> getDn,
        BiConsumer<DelegateOrg, String> setDn) {
    final AtomicInteger updated = new AtomicInteger();
    // Get all delegates of he related receiver type
    delegateOrgRepository.findAllBy(typePath, type).stream().peek(d -> {
        // Consider only the existing ones
        final String dn = Optional.ofNullable(containers.get(id.apply(d))).map(CacheContainer::getDescription)
                .orElse(null);/* w  ww  .  j a  va  2 s . c o  m*/

        // Consider only the dirty one
        final String delegateDn = getDn.apply(d);
        if (!delegateDn.equalsIgnoreCase(dn)) {
            // The delegate DN needed this update
            setDn.accept(d, dn);
            updated.incrementAndGet();
        }
    }).filter(d -> getDn.apply(d) == null).forEach(delegateOrgRepository::delete);
    return updated.get();
}

From source file:org.nuxeo.ecm.core.test.StorageConfiguration.java

/**
 * Due to some DB restriction this method could fire a false negative. For example 1001ms is before 1002ms but it's
 * not the case for MySQL (they're equals).
 *//*  w w w.  ja va2 s  .  c  o  m*/
public void assertBeforeTimestamp(Calendar expected, Calendar actual) {
    BiConsumer<Calendar, Calendar> assertTrue = (exp,
            act) -> assertTrue(String.format("expected=%s is not before actual=%s", exp, act), exp.before(act));
    assertTrue.accept(convertToStoredCalendar(expected), convertToStoredCalendar(actual));
}

From source file:org.nuxeo.ecm.core.test.StorageConfiguration.java

public void assertNotBeforeTimestamp(Calendar expected, Calendar actual) {
    BiConsumer<Calendar, Calendar> assertFalse = (exp,
            act) -> assertFalse(String.format("expected=%s is before actual=%s", exp, act), exp.before(act));
    assertFalse.accept(convertToStoredCalendar(expected), convertToStoredCalendar(actual));
}

From source file:org.nuxeo.ecm.core.test.StorageConfiguration.java

/**
 * Due to some DB restriction this method could fire a false negative. For example 1002ms is after 1001ms but it's
 * not the case for MySQL (they're equals).
 *///ww  w.  ja  v a  2 s .com
public void assertAfterTimestamp(Calendar expected, Calendar actual) {
    BiConsumer<Calendar, Calendar> assertTrue = (exp,
            act) -> assertTrue(String.format("expected=%s is not after actual=%s", exp, act), exp.after(act));
    assertTrue.accept(convertToStoredCalendar(expected), convertToStoredCalendar(actual));
}

From source file:org.nuxeo.ecm.core.test.StorageConfiguration.java

public void assertNotAfterTimestamp(Calendar expected, Calendar actual) {
    BiConsumer<Calendar, Calendar> assertFalse = (exp,
            act) -> assertFalse(String.format("expected=%s is after actual=%s", exp, act), exp.after(act));
    assertFalse.accept(convertToStoredCalendar(expected), convertToStoredCalendar(actual));
}

From source file:org.onosproject.store.cluster.messaging.impl.NettyMessagingManager.java

@Override
public void registerHandler(String type, BiConsumer<Endpoint, byte[]> handler, Executor executor) {
    checkPermission(CLUSTER_WRITE);/*from   w  ww . ja va 2s .  c  o m*/
    handlers.put(type, message -> executor.execute(() -> handler.accept(message.sender(), message.payload())));
}

From source file:org.opencb.opencga.storage.mongodb.variant.adaptors.VariantMongoDBAdaptor.java

/**
 * Accepts a list of filters separated with "," or ";" with the expression:
 * {STUDY}:{POPULATION}{OPERATION}{VALUE}.
 *
 * @param key       PopulationFrequency schema field
 * @param value     Value to parse//from   w ww .  j  a  v  a  2  s  . co  m
 * @param builder   QueryBuilder
 * @param addFilter For complex filter
 * @return QueryBuilder
 */
private QueryBuilder addFrequencyFilter(String key, String value, QueryBuilder builder,
        VariantQueryParams queryParam, BiConsumer<String, QueryBuilder> addFilter) {
    final List<String> list;
    QueryOperation operation = checkOperator(value);
    list = splitValue(value, operation);

    List<BasicDBObject> dbObjects = new ArrayList<>();
    for (String elem : list) {
        String[] split = elem.split(IS);
        if (split.length != 2) {
            logger.error("Bad population frequency filter: " + elem);
            throw VariantQueryException.malformedParam(queryParam, value);
            //new IllegalArgumentException("Bad population frequency filter: " + elem);
        }
        String study = split[0];
        String population = split[1];
        String[] populationFrequency = splitKeyValue(population);
        logger.debug("populationFrequency = " + Arrays.toString(populationFrequency));

        QueryBuilder frequencyBuilder = new QueryBuilder();
        frequencyBuilder.and(DocumentToVariantAnnotationConverter.POPULATION_FREQUENCY_STUDY_FIELD).is(study);
        frequencyBuilder.and(DocumentToVariantAnnotationConverter.POPULATION_FREQUENCY_POP_FIELD)
                .is(populationFrequency[0]);
        Document studyPopFilter = new Document(frequencyBuilder.get().toMap());
        addFilter.accept(populationFrequency[1], frequencyBuilder);
        BasicDBObject elemMatch = new BasicDBObject(key,
                new BasicDBObject("$elemMatch", frequencyBuilder.get()));
        if (populationFrequency[1].startsWith("<")) {
            BasicDBObject orNotExistsAnyPopulation = new BasicDBObject(key,
                    new BasicDBObject("$exists", false));
            BasicDBObject orNotExistsPopulation = new BasicDBObject(key,
                    new BasicDBObject("$not", new BasicDBObject("$elemMatch", studyPopFilter)));
            dbObjects.add(new BasicDBObject("$or",
                    Arrays.asList(orNotExistsAnyPopulation, orNotExistsPopulation, elemMatch)));
        } else {
            dbObjects.add(elemMatch);
        }
    }
    if (!dbObjects.isEmpty()) {
        if (operation == null || operation == QueryOperation.AND) {
            builder.and(dbObjects.toArray(new BasicDBObject[dbObjects.size()]));
        } else {
            builder.and(new BasicDBObject("$or", dbObjects));
        }
    }
    return builder;
}

From source file:org.openhab.binding.loxone.internal.core.LxWsSecurity.java

/**
 * Initiate user authentication. This method will return immediately and authentication will be done in a separate
 * thread asynchronously. On successful or unsuccessful completion, a provided callback will be called with
 * information about failed reason and details of failure. In case of success, the reason value will be
 * {@link LxOfflineReason#NONE}/*from   w  w w  . j  av  a  2 s .co m*/
 * Only one authentication can run in parallel and must be performed sequentially (create no more threads).
 *
 * @param doneCallback
 *            callback to execute when authentication is finished or failed
 */
void authenticate(BiConsumer<LxOfflineReason, String> doneCallback) {
    Runnable init = () -> {
        authenticationLock.lock();
        try {
            execute();
            doneCallback.accept(reason, details);
        } finally {
            authenticationLock.unlock();
        }
    };
    new Thread(init).start();
}

From source file:org.openhab.binding.loxone.internal.security.LxWsSecurity.java

/**
 * Initiate user authentication. This method will return immediately and authentication will be done in a separate
 * thread asynchronously. On successful or unsuccessful completion, a provided callback will be called with
 * information about failed reason and details of failure. In case of success, the reason value will be
 * {@link LxErrorCode#OK}/*from  w w  w  .j av  a  2 s  .c  om*/
 * Only one authentication can run in parallel and must be performed sequentially (create no more threads).
 *
 * @param doneCallback callback to execute when authentication is finished or failed
 */
public void authenticate(BiConsumer<LxErrorCode, String> doneCallback) {
    Runnable init = () -> {
        authenticationLock.lock();
        try {
            execute();
            doneCallback.accept(reason, details);
        } finally {
            authenticationLock.unlock();
        }
    };
    new Thread(init).start();
}