Example usage for java.util.function Consumer accept

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

Introduction

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

Prototype

void accept(T t);

Source Link

Document

Performs this operation on the given argument.

Usage

From source file:org.mimacom.sample.integration.patterns.user.service.integration.HystrixSearchServiceIntegration.java

public void indexUser(User user, Consumer<Void> successConsumer, Consumer<Throwable> failureConsumer) {
    IndexUserHystrixCommand hystrixCommand = new IndexUserHystrixCommand(user, this.restTemplate,
            this.searchServiceUrl + "/index");
    hystrixCommand.observe().subscribe((ignored) -> {
        successConsumer.accept(null);
    }, failureConsumer::accept);/*from w w w . j  av  a  2 s  .c  o  m*/
}

From source file:at.gridtec.lambda4j.function.bi.BiFunction2.java

/**
 * Returns a composed {@link BiConsumer2} that fist applies this function to its input, and then consumes the result
 * using the given {@link Consumer}.//  w  w w .  j a  v a  2  s .  co  m
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code BiConsumer2} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
default BiConsumer2<T, U> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, u) -> consumer.accept(apply(t, u));
}

From source file:io.github.bktlib.event.DynamicEvents.java

/**
 * Registra a ao({@code action}) que sera executada quando o
 * determinado evento({@code eventClass}) for executado.
 *
 * @param id Um id unico, que pode ou no ser usado no {@link #unregister(String)}
 * @param eventClass Classe do evento// w  ww . java2s.c o  m
 * @param callback Ao que ser executada.
 * @param <E> Tipo do evento
 */
@SuppressWarnings("unchecked")
public <E extends Event> void register(String id, Class<E> eventClass, Consumer<E> callback) {
    register0(eventClass, id, (l, e) -> {
        if (eventClass.isAssignableFrom(e.getClass())) {
            callback.accept((E) e);
        }
    });
}

From source file:org.mimacom.sample.integration.patterns.user.service.integration.AsyncSearchServiceIntegration.java

public void searchUserByFirstName(String firstName, Consumer<List<User>> successConsumer,
        Consumer<Throwable> failureConsumer) {
    ListenableFuture<ResponseEntity<User[]>> listenableFuture = this.asyncRestTemplate.getForEntity(
            this.searchServiceUrl + "/search-by-firstname?firstName={firstName}", User[].class, firstName);

    listenableFuture.addCallback(result -> successConsumer.accept(asList(result.getBody())),
            failureConsumer::accept);/*from   w w  w  . ja  va2s . co  m*/

}

From source file:org.mimacom.sample.integration.patterns.user.service.integration.BulkHeadedSearchServiceIntegration.java

public void searchUserByFirstName(String firstName, Consumer<List<User>> successConsumer,
        Consumer<Throwable> failureConsumer) {
    ListenableFuture<ResponseEntity<User[]>> listenableFuture = this.asyncSearchRestTemplate.getForEntity(
            this.searchServiceUrl + "/search-by-firstname?firstName={firstName}", User[].class, firstName);

    listenableFuture.addCallback(result -> successConsumer.accept(asList(result.getBody())),
            failureConsumer::accept);/*from www. j  a v a  2  s.  co  m*/

}

From source file:de.jackwhite20.japs.client.cache.impl.PubSubCacheImpl.java

@SuppressWarnings("unchecked")
@Override// w w  w.  j av  a 2  s  .com
public void received(JSONObject jsonObject) {

    Integer op = ((Integer) jsonObject.remove("op"));

    OpCode opCode = OpCode.of(op);

    switch (opCode) {
    case OP_CACHE_GET:
        int id = jsonObject.getInt("id");
        Object value = (jsonObject.has("value")) ? jsonObject.get("value") : null;

        try {
            // Remove the consumer and accept it if it is not null
            Consumer remove = callbacks.remove(id);
            if (remove != null) {
                remove.accept(value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;
    case OP_CACHE_HAS:
        int hasId = jsonObject.getInt("id");

        try {
            // Remove the consumer and accept it if it is not null
            Consumer remove = callbacks.remove(hasId);
            if (remove != null) {
                remove.accept(new JSONObject().put("has", jsonObject.getBoolean("has")));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;
    }
}

From source file:org.jboss.pnc.buildagent.server.termserver.Term.java

void notifyStatusUpdated(TaskStatusUpdateEvent event) {
    if (event.getNewStatus().isFinal()) {
        activeCommand = false;// w  w  w  . j  a v a 2 s .com
        log.debug("Command [context:{} taskId:{}] execution completed with status {}.", event.getContext(),
                event.getTaskId(), event.getNewStatus());
        writeCompletedToReadonlyChannel(StatusConverter.toTermdStatus(event.getNewStatus()));
        destroyIfInactiveAndDisconnected();
    } else {
        log.debug("Setting command active flag [context:{} taskId:{}] execution completed with status {}.",
                event.getContext(), event.getTaskId(), event.getNewStatus());
        activeCommand = true;
    }
    for (Consumer<TaskStatusUpdateEvent> statusUpdateListener : statusUpdateListeners) {
        log.debug("Notifying listener {} in task {} with new status {}", statusUpdateListener,
                event.getTaskId(), event.getNewStatus());
        statusUpdateListener.accept(event);
    }
}

From source file:org.commonjava.indy.filer.ispn.fileio.StorageFileIO.java

public void walkFiles(Path root, Consumer<Path> operation) {
    Stream.of(root.toFile().list()).map((s -> root.resolve(s))).forEach((p) -> {
        if (p.toFile().isDirectory()) {
            walkFiles(p, operation);//from   w w w.  ja v a 2s . co m
        } else {
            operation.accept(p);
        }
    });
}

From source file:me.Wundero.Ray.variables.Variables.java

/**
 * Register a new variable/*from  www  .j a v a  2 s  . c o  m*/
 */
public boolean registerVariable(String key, Consumer<Map<Param, Object>> task) {
    return registerVariable(key, (Function<Map<Param, Object>, Text>) (o) -> {
        task.accept(o);
        return Text.EMPTY;
    });
}

From source file:org.apache.hadoop.hbase.client.AsyncRegionLocatorHelper.java

static void updateCachedLocationOnError(HRegionLocation loc, Throwable exception,
        Function<HRegionLocation, HRegionLocation> cachedLocationSupplier, Consumer<HRegionLocation> addToCache,
        Consumer<HRegionLocation> removeFromCache, Optional<MetricsConnection> metrics) {
    HRegionLocation oldLoc = cachedLocationSupplier.apply(loc);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Try updating {} , the old value is {}, error={}", loc, oldLoc,
                exception != null ? exception.toString() : "none");
    }//from www.j  av a  2s. c  om
    if (!canUpdateOnError(loc, oldLoc)) {
        return;
    }
    Throwable cause = findException(exception);
    if (LOG.isDebugEnabled()) {
        LOG.debug("The actual exception when updating {} is {}", loc,
                cause != null ? cause.toString() : "none");
    }
    if (cause == null || !isMetaClearingException(cause)) {
        LOG.debug("Will not update {} because the exception is null or not the one we care about", loc);
        return;
    }
    if (cause instanceof RegionMovedException) {
        RegionMovedException rme = (RegionMovedException) cause;
        HRegionLocation newLoc = new HRegionLocation(loc.getRegion(), rme.getServerName(),
                rme.getLocationSeqNum());
        LOG.debug("Try updating {} with the new location {} constructed by {}", loc, newLoc, rme.toString());
        addToCache.accept(newLoc);
    } else {
        LOG.debug("Try removing {} from cache", loc);
        metrics.ifPresent(m -> m.incrCacheDroppingExceptions(exception));
        removeFromCache.accept(loc);
    }
}