List of usage examples for java.util.function BiConsumer accept
void accept(T t, U u);
From source file:org.eclipse.hono.adapter.rest.VertxBasedRestProtocolAdapter.java
private void doRegistrationAction(final RoutingContext ctx, final BiConsumer<RegistrationClient, HttpServerResponse> action) { final String tenant = getTenantParam(ctx); final HttpServerResponse resp = ctx.response(); getRegistrationServiceClient().getOrCreateRegistrationClient(tenant, done -> { if (done.succeeded()) { action.accept(done.result(), resp); } else {//from www. j a v a2 s.c o m // we don't have a connection to Hono serviceUnavailable(resp, 2); } }); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.core.DataProcessor.java
private long calculateMetric(@NonNull List<SolutionPerJob> spjList, BiConsumer<SolutionPerJob, Double> resultSaver, Consumer<SolutionPerJob> ifEmpty) { //to support also parallel stream. AtomicLong executionTime = new AtomicLong(); spjList.forEach(spj -> {/* w w w. j a v a 2s . c om*/ Pair<Optional<Double>, Long> result = simulateClass(spj); executionTime.addAndGet(result.getRight()); Optional<Double> optionalValue = result.getLeft(); if (optionalValue.isPresent()) resultSaver.accept(spj, optionalValue.get()); else ifEmpty.accept(spj); }); return executionTime.get(); }
From source file:com.vmware.admiral.compute.container.ShellContainerExecutorService.java
private void getContainerWhenAvailable(String containerLink, int retryCount, BiConsumer<ContainerState, Exception> callback) { sendRequest(Operation.createGet(this, containerLink).setCompletion((o, e) -> { if (e == null && o.hasBody()) { ContainerState containerState = o.getBody(ContainerState.class); if (containerState.powerState == PowerState.RUNNING) { logInfo("Container %s for shell execution is running", containerState.documentSelfLink); callback.accept(containerState, null); return; }/*from ww w . j av a2s. c om*/ } if (retryCount > 0) { int retriesRemaining = retryCount - 1; int delaySeconds = RETRY_COUNT - retriesRemaining; logInfo("Retrying to retrieve running container %s for shell execution. Retries left %d", containerLink, retriesRemaining); getHost().schedule(() -> { getContainerWhenAvailable(containerLink, retriesRemaining, callback); }, delaySeconds, TimeUnit.SECONDS); } else { callback.accept(null, new RuntimeException("Shell container not available")); } })); }
From source file:at.gridtec.lambda4j.consumer.bi.ThrowableBiConsumer.java
/** * Returns a composed {@link BiConsumer2} that first applies this consumer to its input, and then applies the {@code * recover} operation if a {@link Throwable} is thrown from this one. The {@code recover} operation is represented * by a curried operation which is called with throwable information and same arguments of this consumer. * * @param recover The operation to apply if this consumer throws a {@code Throwable} * @return A composed {@link BiConsumer2} that first applies this consumer to its input, and then applies the {@code * recover} operation if a {@code Throwable} is thrown from this one. * @throws NullPointerException If given argument or the returned enclosing consumer is {@code null} * @implSpec The implementation checks that the returned enclosing consumer from {@code recover} operation is not * {@code null}. If it is, then a {@link NullPointerException} with appropriate message is thrown. * @implNote If thrown {@code Throwable} is of type {@link Error}, it is thrown as-is and thus not passed to {@code * recover} operation.//from w w w . j a v a 2s .c o m */ @Nonnull default BiConsumer2<T, U> recover( @Nonnull final Function<? super Throwable, ? extends BiConsumer<? super T, ? super U>> recover) { Objects.requireNonNull(recover); return (t, u) -> { try { this.acceptThrows(t, u); } catch (Error e) { throw e; } catch (Throwable throwable) { final BiConsumer<? super T, ? super U> consumer = recover.apply(throwable); Objects.requireNonNull(consumer, () -> "recover returned null for " + throwable.getClass() + ": " + throwable.getMessage()); consumer.accept(t, u); } }; }
From source file:com.diffplug.gradle.p2.P2Model.java
@Override public String toString() { return StringPrinter.buildString(printer -> { BiConsumer<String, Set<String>> add = (name, set) -> { for (String element : set) { printer.print(name);//ww w. j av a2 s .c o m printer.print(": "); printer.print(element); printer.println(""); } }; add.accept("repo", repos); add.accept("metadataRepo", metadataRepos); add.accept("artifactRepo", artifactRepos); add.accept("ius", ius); }); }
From source file:com.vmware.admiral.request.ContainerRedeploymentTaskService.java
private void sendEventLog(List<String> tenantLinks, String description, BiConsumer<Operation, Throwable> callback) { EventLogState eventLog = new EventLogState(); eventLog.tenantLinks = tenantLinks;/*from www .j ava 2 s . c o m*/ eventLog.resourceType = getClass().getName(); eventLog.eventLogType = EventLogType.INFO; eventLog.description = description; sendRequest(Operation.createPost(getHost(), EventLogService.FACTORY_LINK).setBody(eventLog) .setCompletion((op, ex) -> { if (ex != null) { callback.accept(op, ex); } callback.accept(op, null); })); }
From source file:org.eclipse.hono.service.http.AbstractHttpEndpoint.java
/** * Sends a request message to an address via the vert.x event bus for further processing. * <p>//from w ww. j a v a 2s . co m * The address is determined by invoking {@link #getEventBusAddress()}. * * @param ctx The routing context of the request. * @param requestMsg The JSON object to send via the event bus. * @param responseHandler The handler to be invoked for the message received in response to the request. * <p> * The handler will be invoked with the <em>status code</em> retrieved from the * {@link MessageHelper#APP_PROPERTY_STATUS} field and the <em>payload</em> * retrieved from the {@link RequestResponseApiConstants#FIELD_PAYLOAD} field. * @throws NullPointerException If the routing context is {@code null}. */ protected final void sendAction(final RoutingContext ctx, final JsonObject requestMsg, final BiConsumer<Integer, JsonObject> responseHandler) { vertx.eventBus().send(getEventBusAddress(), requestMsg, invocation -> { if (invocation.failed()) { HttpUtils.serviceUnavailable(ctx, 2); } else { final JsonObject jsonResult = (JsonObject) invocation.result().body(); final Integer status = jsonResult.getInteger(MessageHelper.APP_PROPERTY_STATUS); final JsonObject payload = jsonResult.getJsonObject(RequestResponseApiConstants.FIELD_PAYLOAD); responseHandler.accept(status, payload); } }); }
From source file:com.diffplug.gradle.p2.P2Model.java
/** Creates an XML node representing all the repos in this model. */ private Node sourceNode(Node parent) { Node source = new Node(parent, "source"); @SuppressWarnings("unchecked") BiConsumer<Iterable<String>, Consumer<Map<String, String>>> addRepos = (urls, repoAttributes) -> { for (String url : urls) { Node repository = source.appendNode("repository"); repository.attributes().put("location", url); repoAttributes.accept(repository.attributes()); }/*from w w w . j av a 2s .com*/ }; addRepos.accept(repos, Consumers.doNothing()); addRepos.accept(metadataRepos, repoAttr -> repoAttr.put("kind", "metadata")); addRepos.accept(artifactRepos, repoAttr -> repoAttr.put("kind", "artifact")); return source; }
From source file:com.diversityarrays.kdxplore.field.CollectionPathPanel.java
public CollectionPathPanel(boolean wantPlotsPerGroup, BiConsumer<VisitOrder2D, PlotsPerGroup> onChoiceChanged, List<? extends OrOrTr> onlyThese) { super(new BorderLayout()); plotsPerGroupChoice.setSelectedItem(plotsPerGroup); odtChoicePanel.setOrOrTr(visitOrder); this.onChoiceChanged = onChoiceChanged; if (wantPlotsPerGroup) { plotsPerGroupChoice.addItemListener(new ItemListener() { @Override// w ww .j a va 2s .c o m public void itemStateChanged(ItemEvent e) { plotsPerGroup = (PlotsPerGroup) plotsPerGroupChoice.getSelectedItem(); onChoiceChanged.accept(visitOrder, plotsPerGroup); } }); Box top = Box.createHorizontalBox(); top.add(new JLabel("Plots Per Group:")); top.add(plotsPerGroupChoice); top.add(Box.createHorizontalGlue()); add(top, BorderLayout.NORTH); } if (!Check.isEmpty(onlyThese)) { OrOrTr first = onlyThese.get(0); odtChoicePanel.setOnlyAllow(onlyThese.toArray(new OrOrTr[onlyThese.size()])); String msg; if (onlyThese.size() == 1) { msg = "<HTML>For now, only supporting:<BR>" + onlyThese.get(0).toString(); } else { msg = onlyThese.stream().map(oot -> oot.toString()) .collect(Collectors.joining("<BR>", "<HTML>For now, only supporting:<BR>", "")); } JLabel label = new JLabel(msg, JLabel.CENTER); label.setForeground(Color.RED); add(label, BorderLayout.SOUTH); } add(odtChoicePanel, BorderLayout.CENTER); }
From source file:org.trustedanalytics.cloud.cc.CcClient.java
private void updateUserRole(String type, UUID userGuid, UUID orgSpaceGuid, Role role, BiConsumer<String, Map<String, Object>> runRequest) { Map<String, Object> pathVars = new HashMap<>(); pathVars.put("type", type); pathVars.put("user", userGuid); pathVars.put("orgSpace", orgSpaceGuid); pathVars.put("role", role.getValue()); runRequest.accept(baseUrl + "/v2/{type}/{orgSpace}/{role}/{user}", pathVars); }