List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:org.mimacom.sample.integration.patterns.user.service.integration.BulkHeadedSearchServiceIntegration.java
public void indexUser(User user, Consumer<Void> successConsumer, Consumer<Throwable> failureConsumer) { LOG.info("going to send request to index user '{}' '{}'", user.getFirstName(), user.getLastName()); HttpEntity<User> requestEntity = new HttpEntity<>(user); ListenableFuture<ResponseEntity<String>> listenableFuture = this.asyncIndexRestTemplate .postForEntity(this.searchServiceUrl + "/index", requestEntity, String.class); listenableFuture.addCallback(result -> { LOG.info("user '{}' '{}' was indexed and response status code was '{}'", user.getFirstName(), user.getLastName(), result.getStatusCode()); successConsumer.accept(null); }, failureConsumer::accept);/*from ww w. j a v a 2 s . co m*/ }
From source file:com.joyent.manta.client.multipart.ServerSideMultipartManagerTest.java
private ServerSideMultipartManager buildMockManager(final StatusLine statusLine, final String responseBody, final Consumer<CloseableHttpResponse> responseConfigCallback) throws IOException { final ConfigContext config = testConfigContext(); final CloseableHttpResponse response = mock(CloseableHttpResponse.class); when(response.getStatusLine()).thenReturn(statusLine); if (responseConfigCallback != null) { responseConfigCallback.accept(response); }/* ww w. j a v a2s .c om*/ if (responseBody != null) { final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8)); when(response.getEntity()).thenReturn(entity); } final MantaConnectionContext connectionContext = mock(MantaConnectionContext.class); final CloseableHttpClient fakeClient = new FakeCloseableHttpClient(response); when(connectionContext.getHttpClient()).thenReturn(fakeClient); final HttpHelper httpHelper = mock(HttpHelper.class); when(httpHelper.getConnectionContext()).thenReturn(connectionContext); when(httpHelper.getRequestFactory()).thenReturn(new MantaHttpRequestFactory(config.getMantaURL())); when(httpHelper.executeRequest(any(HttpUriRequest.class), any())).thenReturn(response); final MantaClient client = mock(MantaClient.class); return new ServerSideMultipartManager(config, httpHelper, client); }
From source file:com.ethlo.geodata.importer.HierarchyImporter.java
@Override public long processFile(Consumer<Map<String, String>> sink) throws IOException { long count = 0; try (final BufferedReader reader = IoUtils.getBufferedReader(hierarchyFile)) { String line;//from ww w. j a va 2 s . c om while ((line = reader.readLine()) != null) { if (StringUtils.hasLength(line)) { final String[] entry = StringUtils.delimitedListToStringArray(line, "\t"); final Map<String, String> paramMap = new TreeMap<>(); paramMap.put("parent_id", stripToNull(entry[0])); paramMap.put("child_id", stripToNull(entry[1])); paramMap.put("feature_code", stripToNull(entry[2])); sink.accept(paramMap); } count++; } } return count; }
From source file:org.drools.workbench.screens.dtablexls.backend.server.DecisionTableXLSServiceImplTest.java
private void testInvalidTable(Consumer<DecisionTableXLSServiceImpl> serviceConsumer) throws IOException { this.service = getServiceWithValidationOverride((tempFile) -> { // mock an invalid file Throwable t = new Throwable("testing invalid xls dt creation"); throw new DecisionTableParseException("DecisionTableParseException: " + t.getMessage(), t); });/*from w w w .java 2 s.c om*/ mockStatic(IOUtils.class); when(IOUtils.copy(any(InputStream.class), any(OutputStream.class))).thenReturn(0); try { serviceConsumer.accept(service); } catch (RuntimeException e) { // this is expected correct behavior } verify(ioService, never()).newOutputStream(any(org.uberfire.java.nio.file.Path.class), any(CommentedOption.class)); verifyStatic(never()); }
From source file:org.codice.ddf.itests.common.ServiceManagerImpl.java
private void printInactiveBundles(Consumer<String> headerConsumer, BiConsumer<String, Object[]> logConsumer) { headerConsumer.accept("Listing inactive bundles"); for (Bundle bundle : getBundleContext().getBundles()) { if (bundle.getState() != Bundle.ACTIVE) { Dictionary<String, String> headers = bundle.getHeaders(); if (headers.get("Fragment-Host") != null) { continue; }//from w w w. j a va 2 s . co m StringBuilder headerString = new StringBuilder("[ "); Enumeration<String> keys = headers.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); headerString.append(key).append("=").append(headers.get(key)).append(", "); } headerString.append(" ]"); logConsumer.accept("\n\tBundle: {}_v{} | {}\n\tHeaders: {}", new Object[] { bundle.getSymbolicName(), bundle.getVersion(), BUNDLE_STATES.getOrDefault(bundle.getState(), "UNKNOWN"), headerString }); } } }
From source file:com.haulmont.cuba.web.gui.components.mainwindow.WebAppMenu.java
@Override public MenuItem createMenuItem(String id, String caption, @Nullable String icon, @Nullable Consumer<MenuItem> command) { checkNotNullArgument(id);/*w w w.jav a2 s. c om*/ checkItemIdDuplicate(id); MenuItem menuItem = new MenuItemImpl(this, id); MenuBar.MenuItem delegateItem = component.createMenuItem(caption, WebComponentsHelper.getIcon(icon), null); if (command != null) { delegateItem.setCommand(selectedItem -> command.accept(menuItem)); } ((MenuItemImpl) menuItem).setDelegateItem(delegateItem); menuItem.setCaption(caption); menuItem.setIcon(icon); menuItem.setCommand(command); return menuItem; }
From source file:org.commonjava.util.partyline.FileTree.java
/** * Iterate all {@link FileEntry instances} to extract information about active locks. * * @param fileConsumer The operation to extract information from a single active file. *///from ww w .jav a 2s . c o m void forAll(Consumer<JoinableFile> fileConsumer) { forAll(entry -> entry.file != null, entry -> fileConsumer.accept(entry.file)); }
From source file:ch.ivyteam.ivy.maven.engine.EngineControl.java
private PumpStreamHandler createEngineLogStreamForwarder(Consumer<String> logLineHandler) throws FileNotFoundException { OutputStream output = getEngineLogTarget(); OutputStream engineLogStream = new LineOrientedOutputStreamRedirector(output) { @Override/*from ww w. ja v a 2s . c o m*/ protected void processLine(byte[] b) throws IOException { super.processLine(b); // write file log String line = new String(b); context.log.debug("engine: " + line); if (logLineHandler != null) { logLineHandler.accept(line); } } }; PumpStreamHandler streamHandler = new PumpStreamHandler(engineLogStream, System.err) { @Override public void stop() throws IOException { super.stop(); engineLogStream.close(); // we opened the stream - we're responsible to close it! } }; return streamHandler; }
From source file:com.diversityarrays.kdxplore.trialdesign.RscriptFinderPanel.java
public RscriptFinderPanel(BackgroundRunner br, Component component, String initialScriptPath, Consumer<Either<Throwable, String>> onScriptPathChecked) { super(new BorderLayout()); backgroundRunner = br;/*from w w w . j av a2 s .c om*/ this.onScriptPathChecked = onScriptPathChecked; scriptPathField.setText(initialScriptPath); scriptPathField.addMouseListener(clickAdapter); Box scriptPathBox = Box.createHorizontalBox(); Consumer<Void> updateFindScriptButton = new Consumer<Void>() { @Override public void accept(Void t) { checkScriptPath.setEnabled(!scriptPathField.getText().trim().isEmpty()); } }; scriptPathBox.add(scriptPathField); scriptPathBox.add(new JButton(checkScriptPath)); scriptPathField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateFindScriptButton.accept(null); } @Override public void insertUpdate(DocumentEvent e) { updateFindScriptButton.accept(null); } @Override public void changedUpdate(DocumentEvent e) { updateFindScriptButton.accept(null); } }); updateFindScriptButton.accept(null); add(scriptPathBox, BorderLayout.NORTH); if (component != null) { add(component, BorderLayout.CENTER); } }
From source file:org.mimacom.sample.integration.patterns.user.service.integration.AsyncSearchServiceIntegration.java
public void indexUserSlow(User user, int waitTime, Consumer<Void> successConsumer, Consumer<Throwable> failureConsumer) { LOG.info("[SLOW!] going to send request to index user '{}' '{}'", user.getFirstName(), user.getLastName()); HttpEntity<User> requestEntity = new HttpEntity<>(user); ListenableFuture<ResponseEntity<String>> listenableFuture = this.asyncRestTemplate.postForEntity( this.searchServiceUrl + "/index?waitTime={waitTime}", requestEntity, String.class, waitTime); listenableFuture.addCallback(result -> { LOG.info("[SLOW!] user '{}' '{}' was indexed and response status code was '{}'", user.getFirstName(), user.getLastName(), result.getStatusCode()); successConsumer.accept(null); }, failureConsumer::accept);/*from w w w . j av a2 s .co m*/ }