List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:com.thoughtworks.go.server.service.PipelineScheduler.java
protected EntityConfigChangedListener<ConfigRepoConfig> configRepoConfigChangedListener() { final Consumer<CruiseConfig> configChangeConsumer = this::onConfigChange; return new EntityConfigChangedListener<ConfigRepoConfig>() { @Override/*from w ww.ja va 2 s. c o m*/ public void onEntityConfigChange(ConfigRepoConfig configRepoConfig) { configChangeConsumer.accept(goConfigService.cruiseConfig()); } }; }
From source file:io.syndesis.jsondb.impl.SqlJsonDB.java
private void withTransaction(Consumer<Handle> cb) { try (final Handle h = dbi.open()) { try {/*from w w w. j ava2 s . co m*/ h.begin(); cb.accept(h); h.commit(); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException e) { h.rollback(); throw e; } } }
From source file:com.redhat.red.build.koji.it.AbstractIT.java
protected void withNewClient(Consumer<CloseableHttpClient> consumer) { CloseableHttpClient client = null;/*from w ww . j av a 2s . c o m*/ FileOutputStream stream = null; try { client = factory.createClient(); consumer.accept(client); } catch (Exception err) { System.out.println("Failed to retrieve server logs after error. Reason: " + err.getMessage()); err.printStackTrace(); } finally { IOUtils.closeQuietly(client); } }
From source file:org.everit.json.schema.loader.internal.TypeBasedMultiplexer.java
/** * Checks if the {@code obj} is an instance of any previously set classes (by {@link #ifIs(Class)} * or {@link #ifObject()}), performs the mapped action of found or invokes {@code orElseConsumer} * with the {@code obj}./*from w ww.j a va 2s . c o m*/ * * @param orElseConsumer * the callback to be called if no types matched. */ public void orElse(final Consumer<Object> orElseConsumer) { @SuppressWarnings("unchecked") Consumer<Object> consumer = (Consumer<Object>) actions.keySet().stream() .filter(clazz -> clazz.isAssignableFrom(obj.getClass())).findFirst().map(actions::get) .orElse(orElseConsumer::accept); consumer.accept(obj); }
From source file:com.github.erchu.beancp.DeclarativeMapImpl.java
@Override public DeclarativeMap<S, D> afterMap(final Consumer<Mapper> action) { if (mode == MapMode.CONFIGURATION) { _afterMapExecuted = true;//from www. j a v a 2 s .com } if (mode == MapMode.EXECUTION) { action.accept(_executionPhaseMapper); } return this; }
From source file:org.onlab.netty.NettyMessaging.java
@Override public void registerHandler(String type, Consumer<byte[]> handler, Executor executor) { handlers.put(type, message -> executor.execute(() -> handler.accept(message.payload()))); }
From source file:io.bosh.client.jobs.SpringJobs.java
private Observable<Task> changeJobState(String deploymentName, Consumer<UriComponentsBuilder> builderCallback) { HttpHeaders headers = new HttpHeaders(); headers.put("content-type", Arrays.asList("text/yaml")); return deployments.get(deploymentName) .flatMap(deployment -> exchangeForEntity(deployment.getRawManifest(), Void.class, headers, HttpMethod.PUT, builder -> builderCallback.accept(builder))) .flatMap(response -> tasks.trackToCompletion(getTaskId(response))); }
From source file:io.vertx.ext.shell.term.TelnetTermServerTest.java
private void testClose(TestContext context, Consumer<Term> closer) throws Exception { Async async1 = context.async();/*from w w w.j av a 2s . c o m*/ Async async2 = context.async(); startTelnet(context, term -> { term.closeHandler(v -> { async2.complete(); }); closer.accept(term); async1.complete(); }); client.connect("localhost", server.actualPort()); async1.await(4000); OutputStream out = client.getOutputStream(); long now = System.currentTimeMillis(); while (true) { context.assertTrue(System.currentTimeMillis() - now < 10000); try { out.write(4); out.flush(); } catch (IOException ignore) { break; } Thread.sleep(10); } }
From source file:io.bosh.client.jobs.SpringJobs.java
private final Observable<File> getGzip(Consumer<UriComponentsBuilder> builderCallback) { // For responses that have a Content-Type of application/x-gzip, we need to // decompress them. The RestTemplate and HttpClient don't handle this for // us//from ww w . j av a 2 s . co m return createObservable(() -> { UriComponentsBuilder builder = UriComponentsBuilder.fromUri(this.root); builderCallback.accept(builder); URI uri = builder.build().toUri(); return this.restOperations.execute(uri, HttpMethod.GET, null, new ResponseExtractor<File>() { @Override public File extractData(ClientHttpResponse response) throws IOException { return decompress(response.getBody()); } }); }); }
From source file:io.pravega.segmentstore.server.host.stat.AutoScaleProcessorTest.java
private EventStreamWriter<AutoScaleEvent> createWriter(Consumer<AutoScaleEvent> consumer) { return new EventStreamWriter<AutoScaleEvent>() { @Override/*from w w w. j a v a 2 s .co m*/ public CompletableFuture<Void> writeEvent(AutoScaleEvent event) { return null; } @Override public CompletableFuture<Void> writeEvent(String routingKey, AutoScaleEvent event) { consumer.accept(event); return null; } @Override public Transaction<AutoScaleEvent> beginTxn(long transactionTimeout, long maxExecutionTime, long scaleGracePeriod) { return null; } @Override public Transaction<AutoScaleEvent> getTxn(UUID transactionId) { return null; } @Override public EventWriterConfig getConfig() { return null; } @Override public void flush() { } @Override public void close() { } }; }