List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:fredboat.messaging.CentralMessaging.java
private static MessageFuture sendFile0(@Nonnull MessageChannel channel, @Nonnull File file, @Nullable Message message, @Nullable Consumer<Message> onSuccess, @Nullable Consumer<Throwable> onFail) { if (channel == null) { throw new IllegalArgumentException("Channel is null"); }/* w ww .j a va 2 s. co m*/ if (file == null) { throw new IllegalArgumentException("File is null"); } MessageFuture result = new MessageFuture(); Consumer<Message> successWrapper = m -> { result.complete(m); Metrics.successfulRestActions.labels("sendFile").inc(); if (onSuccess != null) { onSuccess.accept(m); } }; Consumer<Throwable> failureWrapper = t -> { result.completeExceptionally(t); if (onFail != null) { onFail.accept(t); } else { String info = String.format("Could not send file %s to channel %s in guild %s", file.getAbsolutePath(), channel.getId(), (channel instanceof TextChannel) ? ((TextChannel) channel).getGuild().getIdLong() : "null"); getJdaRestActionFailureHandler(info).accept(t); } }; try { // ATTENTION: Do not use JDA's MessageChannel#sendFile(File file, Message message) // as it will skip permission checks, since TextChannel does not override that method // this is scheduled to be fixed through JDA's message-rw branch channel.sendFile(FileUtils.readFileToByteArray(file), file.getName(), message).queue(successWrapper, failureWrapper); } catch (InsufficientPermissionException e) { failureWrapper.accept(e); handleInsufficientPermissionsException(channel, e); } catch (IOException e) { log.error("Could not send file {}, it appears to be borked", file.getAbsolutePath(), e); } return result; }
From source file:fredboat.messaging.CentralMessaging.java
private static MessageFuture editMessage0(@Nonnull MessageChannel channel, long oldMessageId, @Nonnull Message newMessage, @Nullable Consumer<Message> onSuccess, @Nullable Consumer<Throwable> onFail) { if (channel == null) { throw new IllegalArgumentException("Channel is null"); }/*from ww w.j a v a 2 s .c om*/ if (newMessage == null) { throw new IllegalArgumentException("New message is null"); } MessageFuture result = new MessageFuture(); Consumer<Message> successWrapper = m -> { result.complete(m); Metrics.successfulRestActions.labels("editMessage").inc(); if (onSuccess != null) { onSuccess.accept(m); } }; Consumer<Throwable> failureWrapper = t -> { result.completeExceptionally(t); if (onFail != null) { onFail.accept(t); } else { String info = String.format( "Could not edit message %s in channel %s in guild %s with new content %s", oldMessageId, channel.getId(), (channel instanceof TextChannel) ? ((TextChannel) channel).getGuild().getIdLong() : "null", newMessage.getRawContent()); getJdaRestActionFailureHandler(info).accept(t); } }; try { channel.editMessageById(oldMessageId, newMessage).queue(successWrapper, failureWrapper); } catch (InsufficientPermissionException e) { failureWrapper.accept(e); handleInsufficientPermissionsException(channel, e); } return result; }
From source file:fr.landel.utils.io.InternalFileSystemUtils.java
/** * List the files in a directory/* w ww . j a v a 2 s .com*/ * * @param output * the output list (optional) * @param src * the directory to analyze * @param fileFilter * the file filter (optional) * @param filenameFilter * the filename filter (optional) * @param actionOnEachFile * the action applied on each file (optional) * @return the list of files * @throws IOException * on IO errors */ protected static List<File> listFiles(final Optional<List<File>> output, final File src, final FileFilter fileFilter, final FilenameFilter filenameFilter, Consumer<File> actionOnEachFile) throws IOException { final List<File> list = output.orElse(new ArrayList<>()); if (src.isDirectory()) { // creation du repertoire si necessaire // creation de la liste des fichiers et repertoires File[] files = listFiles(src, fileFilter, filenameFilter); if (files != null) { list.addAll(Arrays.asList(files)); for (File entry : files) { if (actionOnEachFile != null) { actionOnEachFile.accept(entry); } if (entry.isDirectory()) { InternalFileSystemUtils.listFiles(Optional.of(list), entry, fileFilter, filenameFilter, actionOnEachFile); } } } } else if (matchFilter(src, fileFilter, filenameFilter)) { list.add(src); if (actionOnEachFile != null) { actionOnEachFile.accept(src); } } return list; }
From source file:com.eclecticlogic.pedal.testing.NoopTransactionMock.java
/** * @see com.eclecticlogic.pedal.TransactionRunner#run(java.util.function.Consumer) *//*www . j ava2 s .com*/ @Override public void run(Consumer<Context> block) { block.accept(new NoopContext()); }
From source file:org.lendingclub.mercator.docker.DockerScannerBuilder.java
public DockerScannerBuilder withConfig(Consumer<Builder> b) { b.accept(configBuilder); return this; }
From source file:com.example.app.support.service.AppUtil.java
/** * Walk component tree.// w w w.j ava 2 s.co m * * @param parent the parent * @param actionOnComponent the action to be performed on each component within the component tree */ public static void walkComponentTree(ParentComponent parent, Consumer<Component> actionOnComponent) { parent.components().forEachRemaining(component -> { if (component instanceof ParentComponent) { actionOnComponent.accept(component); walkComponentTree((ParentComponent) component, actionOnComponent); } else { actionOnComponent.accept(component); } }); }
From source file:com.eclecticlogic.pedal.impl.TransactionSynchronizationAdapterTask.java
@Override public void beforeCommit(boolean readOnly) { DataContextImpl data = new DataContextImpl(); for (Consumer<DataContext> task : preCommit) { task.accept(data); }//from ww w .j av a 2 s.c om }
From source file:com.eclecticlogic.pedal.impl.TransactionSynchronizationAdapterTask.java
@Override public void afterCommit() { DataContextImpl data = new DataContextImpl(); for (Consumer<DataContext> task : postCommit) { task.accept(data); }// ww w .ja v a 2s. com }
From source file:org.jugvale.peoplemanagement.client.service.RESTPersonService.java
private void handle(java.lang.RuntimeException e, Consumer<String> onFail) { e.printStackTrace();//from w ww .ja va 2 s.com onFail.accept("Error: " + e.getMessage() + "; Exception: " + e.getClass().getSimpleName()); }
From source file:org.apache.metron.performance.load.monitor.writers.Writer.java
public void writeAll() { int i = 0;// w w w . j av a2 s . c o m Date dateOf = new Date(); List<Results> results = new ArrayList<>(); for (AbstractMonitor m : monitors) { Long eps = m.get(); if (eps != null && summaryLookback > 0) { LinkedList<Double> summary = summaries.get(i); addToLookback(eps.doubleValue(), summary); results.add(new Results(m.format(), m.name(), eps, Optional.of(getStats(summary)))); } else { results.add(new Results(m.format(), m.name(), eps, Optional.empty())); } i++; } Writable writable = new Writable(dateOf, results); for (Consumer<Writable> writer : writers) { writer.accept(writable); } }