List of usage examples for java.util.function Supplier get
T get();
From source file:com.example.app.communication.service.NotificationService.java
/** * Send an email.// ww w .j a va 2 s .c o m * * @param plan the plan. * @param emailTemplate the email template. * @param context the context. * @param defaultFromNameSupplier the supplier for the name of the default sender. */ public void sendEmail(Profile plan, EmailTemplate emailTemplate, EmailTemplateContext context, @Nullable Supplier<String> defaultFromNameSupplier) { // FUTURE : delay, send at the right time of the day for user try { final FileEntityMailDataHandler mdh = _emailTemplateProcessor.process(context, emailTemplate); try (MailMessage mm = new MailMessage(mdh)) { if (mm.getToRecipients().isEmpty()) { final EmailTemplateRecipient recipientAttribute = context.getRecipientAttribute(); if (recipientAttribute != null) mm.addTo(recipientAttribute.getEmailAddress()); } if (mm.getFrom().isEmpty()) { UnparsedAddress from = new UnparsedAddress(_systemSender, defaultFromNameSupplier != null ? defaultFromNameSupplier.get() : null); mm.addFrom(from); } sendEmail(plan, mm); } } catch (EmailTemplateException | MailDataHandlerException e) { _logger.error("Unable to send message.", e); } }
From source file:enumj.Enumerator.java
/** * Returns an enumerator enumerating over a {@code Stream} supplied lazily. * <p>// w w w .ja v a 2 s . c o m * This method works like {@link #of(java.util.stream.Stream)} with the * distinction that {@code source} is supplied by a {@link Supplier}. * </p> * * @param <E> the type of elements being enumerated. * @param source the {@code Supplier} supplying the {@link Stream} to * enumerate upon. * @return the new enumerator. * @see #of(java.util.stream.Stream) * @exception IllegalArgumentException {@code source} is null. */ public static <E> Enumerator<E> ofLazyStream(Supplier<? extends Stream<E>> source) { Checks.ensureNotNull(source, Messages.NULL_ENUMERATOR_SOURCE); return LazyEnumerator.of(() -> of(source.get())); }
From source file:enumj.Enumerator.java
/** * Returns an enumerator enumerating over an {@code Iterable} supplied * lazily./* w w w.j a va 2 s .c o m*/ * <p> * This method works like {@link #of(java.lang.Iterable)} with the * distinction that <code>source</code> is supplied by a {@link Supplier}. * </p> * * @param <E> the type of elements being enumerated. * @param source the {@code Supplier} supplying the {@link Iterable} to * enumerate upon. * @return the new enumerator. * @see #of(java.lang.Iterable) * @exception IllegalArgumentException {@code source} is null. */ public static <E> Enumerator<E> ofLazyIterable(Supplier<? extends Iterable<E>> source) { Checks.ensureNotNull(source, Messages.NULL_ENUMERATOR_SOURCE); return LazyEnumerator.of(() -> of(source.get())); }
From source file:enumj.Enumerator.java
/** * Returns an enumerator enumerating over an {@code Enumeration} supplied * lazily./*from w w w . j a v a 2 s . c o m*/ * <p> * This method works like {@link #of(java.util.Enumeration)} with the * distinction that {@code source} is supplied by a {@link Supplier}. * </p> * * @param <E> the type of elements being enumerated * @param source the {@code Supplier} supplying the {@link Enumeration} to * enumerate upon * @return the new enumerator * @see #of(java.util.Enumeration) * @exception IllegalArgumentException {@code source} is null. */ public static <E> Enumerator<E> ofLazyEnumeration(Supplier<? extends Enumeration<E>> source) { Checks.ensureNotNull(source, Messages.NULL_ENUMERATOR_SOURCE); return LazyEnumerator.of(() -> of(source.get())); }
From source file:enumj.Enumerator.java
/** * Returns an enumerator enumerating over a {@code Spliterator} supplied * lazily.//from www .j a v a2 s . c o m * <p> * This method works like {@link #of(java.util.Spliterator)} with the * distinction that {@code source} is supplied by a {@link Supplier}. * </p> * * @param <E> the type of elements being enumerated. * @param source the {@code Supplier} supplying the {@link Spliterator} to * enumerate upon. * @return the new enumerator. * @see #of(java.util.Spliterator) * @exception IllegalArgumentException {@code source} is null. */ public static <E> Enumerator<E> ofLazySpliterator(Supplier<? extends Spliterator<E>> source) { Checks.ensureNotNull(source, Messages.NULL_ENUMERATOR_SOURCE); return LazyEnumerator.of(() -> of(source.get())); }
From source file:io.pravega.controller.server.eventProcessor.ControllerEventProcessors.java
private CompletableFuture<Void> handleOrphanedReaders( final EventProcessorGroup<? extends ControllerEvent> group, final Supplier<Set<String>> processes) { return withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> { try {/*from w w w. j a va2 s.c om*/ return group.getProcesses(); } catch (CheckpointStoreException e) { if (e.getType().equals(CheckpointStoreException.Type.NoNode)) { return Collections.<String>emptySet(); } throw new CompletionException(e); } }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor) .thenComposeAsync(groupProcesses -> withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> { try { return new ImmutablePair<>(processes.get(), groupProcesses); } catch (Exception e) { log.error(String.format("Error fetching current processes%s", group.toString()), e); throw new CompletionException(e); } }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor)).thenComposeAsync(pair -> { Set<String> activeProcesses = pair.getLeft(); Set<String> registeredProcesses = pair.getRight(); if (registeredProcesses == null || registeredProcesses.isEmpty()) { return CompletableFuture.completedFuture(null); } if (activeProcesses != null) { registeredProcesses.removeAll(activeProcesses); } List<CompletableFuture<Void>> futureList = new ArrayList<>(); for (String process : registeredProcesses) { futureList.add(withRetriesAsync(() -> CompletableFuture.runAsync(() -> { try { group.notifyProcessFailure(process); } catch (CheckpointStoreException e) { log.error(String.format( "Error notifying failure of process=%s in event processor group %s", process, group.toString()), e); throw new CompletionException(e); } }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor)); } return FutureHelpers.allOf(futureList); }); }
From source file:module.mission.domain.MissionProcess.java
public Collection<WorkflowQueue> getProcessParticipantInformationQueues() { final Supplier<Stream<AccountabilityType>> types = () -> getMission().getParticipantesSet().stream() .flatMap(p -> p.getParentAccountabilityStream()).filter(a -> a.isValid()) .map(a -> a.getAccountabilityType()); return MissionSystem.getInstance().getAccountabilityTypeQueuesSet().stream() .filter(q -> types.get().anyMatch(t -> t == q.getAccountabilityType())) .map(q -> q.getWorkflowQueue()).collect(Collectors.toSet()); }
From source file:io.pravega.controller.store.stream.PersistentStreamBase.java
private <U> CompletableFuture<U> verifyState(Supplier<CompletableFuture<U>> future, List<State> states) { return getState().thenCompose(state -> { if (state != null && states.contains(state)) { return future.get(); } else {/* w w w . ja va 2s .c o m*/ throw StoreException.create(StoreException.Type.ILLEGAL_STATE, "Stream: " + getName() + " State: " + state.name()); } }); }
From source file:com.example.test.HibernateBookRepositoryTest.java
private void persistBooks(Supplier<AbstractBook> bookSupplier) throws Exception { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override/*from w ww. j a va 2 s. c o m*/ protected void doInTransactionWithoutResult(TransactionStatus ts) { Session session = getCurrentSession(); Category softwareDevelopment = new Category(); softwareDevelopment.setName("Software development"); session.persist(softwareDevelopment); Category systemDesign = new Category(); systemDesign.setName("System design"); session.persist(systemDesign); Author martinFowler = new Author(); martinFowler.setFullName("Martin Fowler"); session.persist(martinFowler); AbstractBook poeaa = bookSupplier.get(); poeaa.setIsbn("007-6092019909"); poeaa.setTitle("Patterns of Enterprise Application Architecture"); poeaa.setPublicationDate(Date.from(Instant.parse("2002-11-15T00:00:00.00Z"))); poeaa.setAuthors(asList(martinFowler)); poeaa.setCategories(asList(softwareDevelopment, systemDesign)); session.persist(poeaa); Author gregorHohpe = new Author(); gregorHohpe.setFullName("Gregor Hohpe"); session.persist(gregorHohpe); Author bobbyWoolf = new Author(); bobbyWoolf.setFullName("Bobby Woolf"); session.persist(bobbyWoolf); AbstractBook eip = bookSupplier.get(); eip.setIsbn("978-0321200686"); eip.setTitle("Enterprise Integration Patterns"); eip.setPublicationDate(Date.from(Instant.parse("2003-10-20T00:00:00.00Z"))); eip.setAuthors(asList(gregorHohpe, bobbyWoolf)); eip.setCategories(asList(softwareDevelopment, systemDesign)); session.persist(eip); Category objectOrientedSoftwareDesign = new Category(); objectOrientedSoftwareDesign.setName("Object-Oriented Software Design"); session.persist(objectOrientedSoftwareDesign); Author ericEvans = new Author(); ericEvans.setFullName("Eric Evans"); session.persist(ericEvans); AbstractBook ddd = bookSupplier.get(); ddd.setIsbn("860-1404361814"); ddd.setTitle("Domain-Driven Design: Tackling Complexity in the Heart of Software"); ddd.setPublicationDate(Date.from(Instant.parse("2003-08-01T00:00:00.00Z"))); ddd.setAuthors(asList(ericEvans)); ddd.setCategories(asList(softwareDevelopment, systemDesign, objectOrientedSoftwareDesign)); session.persist(ddd); Category networkingCloudComputing = new Category(); networkingCloudComputing.setName("Networking & Cloud Computing"); session.persist(networkingCloudComputing); Category databasesBigData = new Category(); databasesBigData.setName("Databases & Big Data"); session.persist(databasesBigData); Author pramodSadalage = new Author(); pramodSadalage.setFullName("Pramod J. Sadalage"); session.persist(pramodSadalage); AbstractBook nosql = bookSupplier.get(); nosql.setIsbn("978-0321826626"); nosql.setTitle("NoSQL Distilled: A Brief Guide to the Emerging World of Polyglot Persistence"); nosql.setPublicationDate(Date.from(Instant.parse("2012-08-18T00:00:00.00Z"))); nosql.setAuthors(asList(pramodSadalage, martinFowler)); nosql.setCategories(asList(networkingCloudComputing, databasesBigData)); session.persist(nosql); } }); System.out.println("##################################################"); }
From source file:com.example.app.profile.model.company.CompanyDAO.java
/** * New membership type membership type./*from w ww.ja v a 2s. c om*/ * * @param pt the pt * @param name the name * @param operations the operations * @param progId the prog id * * @return the membership type */ public MembershipType createMembershipType(ProfileType pt, String name, Supplier<List<MembershipOperation>> operations, @Nullable String progId) { MembershipType mt = new MembershipType(); TransientLocalizedObjectKey tlok = new TransientLocalizedObjectKey(singletonMap(Locale.ENGLISH, name)); TransientLocalizedObjectKey dtlok = new TransientLocalizedObjectKey(singletonMap(Locale.ENGLISH, name)); mt.setName(tlok); mt.setDescription(dtlok); mt.setProgrammaticIdentifier( isEmptyString(progId) ? GloballyUniqueStringGenerator.getUniqueString() : progId); mt.setDefaultOperations(operations.get()); mt.setProfileType(pt); return mt; }