List of usage examples for java.util.function Supplier get
T get();
From source file:uk.co.sdev.async.http.ning.ObservableClient.java
private <T> Observable<T> execute(Supplier<Request> requestSupplier, Consumer<Request> requestConsumer, ResponseMapper<T> responseMapper) { return Observable.create(subscriber -> { try {//ww w. j ava2 s. co m Request request = requestSupplier.get(); requestConsumer.accept(request); asyncHttpClient.executeRequest(request, new AsyncCompletionHandler<T>() { @Override public T onCompleted(Response response) throws Exception { T t = responseMapper.map(response); subscriber.onNext(t); subscriber.onCompleted(); return t; } @Override public void onThrowable(Throwable t) { subscriber.onError(t); } }); } catch (Exception e) { subscriber.onError(e); } }); }
From source file:alfio.manager.WaitingQueueManager.java
private Stream<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> distributeAvailableSeats( Event event, Ticket.TicketStatus status, Supplier<Integer> availableSeatSupplier) { int availableSeats = availableSeatSupplier.get(); int eventId = event.getId(); log.debug("processing {} subscribers from waiting queue", availableSeats); List<TicketCategory> unboundedCategories = ticketCategoryRepository .findUnboundedOrderByExpirationDesc(eventId); Iterator<Ticket> tickets = ticketRepository .selectWaitingTicketsForUpdate(eventId, status.name(), availableSeats).stream() .filter(t -> t.getCategoryId() != null || unboundedCategories.size() > 0).iterator(); int expirationTimeout = configurationManager.getIntConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), WAITING_QUEUE_RESERVATION_TIMEOUT), 4); ZonedDateTime expiration = ZonedDateTime.now(event.getZoneId()).plusHours(expirationTimeout) .with(WorkingDaysAdjusters.defaultWorkingDays()); if (!tickets.hasNext()) { log.warn("Unable to assign tickets, returning an empty stream"); return Stream.empty(); }//from w w w. jav a 2s . c om return waitingQueueRepository.loadWaiting(eventId, availableSeats).stream() .map(wq -> Pair.of(wq, tickets.next())).map(pair -> { TicketReservationModification ticketReservation = new TicketReservationModification(); ticketReservation.setAmount(1); Integer categoryId = Optional.ofNullable(pair.getValue().getCategoryId()) .orElseGet(() -> findBestCategory(unboundedCategories, pair.getKey()) .orElseThrow(RuntimeException::new).getId()); ticketReservation.setTicketCategoryId(categoryId); return Pair.of(pair.getLeft(), new TicketReservationWithOptionalCodeModification( ticketReservation, Optional.<SpecialPrice>empty())); }).map(pair -> Triple.of(pair.getKey(), pair.getValue(), expiration)); }
From source file:es.upv.grycap.coreutils.fiber.http.Http2Client.java
/** * Puts data to a server via a HTTP PUT request. * @param url - URL target of this request * @param mediaType - Content-Type header for this request * @param supplier - supplies the content of this request * @param callback - is called back when the response is readable *///from ww w. j av a 2s. c o m public void asyncPut(final String url, final String mediaType, final Supplier<String> supplier, final Callback callback) { requireNonNull(supplier, "A valid supplier expected"); asyncPutBytes(url, mediaType, () -> ofNullable(supplier.get()).orElse("").getBytes(), callback); }
From source file:es.upv.grycap.coreutils.fiber.http.Http2Client.java
/** * Posts data to a server via a HTTP POST request. * @param url - URL target of this request * @param mediaType - Content-Type header for this request * @param supplier - supplies the content of this request * @param callback - is called back when the response is readable *//*from www . j a v a2s . c om*/ public void asyncPost(final String url, final String mediaType, final Supplier<String> supplier, final Callback callback) { requireNonNull(supplier, "A valid supplier expected"); asyncPostBytes(url, mediaType, () -> ofNullable(supplier.get()).orElse("").getBytes(), callback); }
From source file:org.n52.iceland.config.json.AbstractJsonActivationDao.java
protected Supplier<ObjectNode> encode(Supplier<ObjectNode> supplier, ServiceOperatorKey key) { Objects.requireNonNull(supplier); return () -> { String service = key == null ? null : key.getService(); String version = key == null ? null : key.getVersion(); return supplier.get().put(JsonConstants.SERVICE, service).put(JsonConstants.VERSION, version); };/*from ww w. ja v a 2s. c om*/ }
From source file:com.hotelbeds.distribution.hotel_api_sdk.helpers.LoggingRequestInterceptor.java
private void logBody(Supplier<Buffer> bufferSupplier, MediaType contentType, Headers headers) { if (bodyEncoded(headers)) { log.trace(" Body: encoded, not shown"); } else {//from w ww. ja va2 s .co m Buffer buffer = bufferSupplier.get(); Charset charset = AssignUtils.UTF8; if (contentType != null) { try { charset = contentType.charset(AssignUtils.UTF8); } catch (UnsupportedCharsetException e) { log.error(" Body: Could not be decoded {}", e.getMessage()); } } String body = buffer.readString(charset); String bodyContentType = headers.get(HotelApiClient.CONTENT_TYPE_HEADER); if (bodyContentType != null && bodyContentType.toLowerCase().startsWith(HotelApiClient.APPLICATION_JSON_HEADER)) { log.trace(" JSON Body: {}", writeJSON(body)); } else { log.trace(" Body: {}", body); } } }
From source file:fi.hsl.parkandride.back.RequestLogDao.java
private BiMap<Long, String> insertMissing(Set<String> toInsert, Supplier<BiMap<Long, String>> persistedGetter, RelationalPath<?> path, BiConsumer<SQLInsertClause, String> processor) { final BiMap<Long, String> persisted = persistedGetter.get(); final Set<String> difference = difference(toInsert, persisted); if (difference.isEmpty()) { // Nothing to insert, just return the already persisted sources return persisted; }/*from w ww.j a v a2 s . c o m*/ insertBatch(difference, path, processor); return persistedGetter.get(); }
From source file:de.ks.binding.Binding.java
@SuppressWarnings("unchecked") protected <T extends Property, V, K, O> T addProperty(Class<V> clazz, Function<V, K> function, Supplier<T> supplier, Function<K, O> model2Controller, Function<O, K> controller2Model) { PropertyPath path = PropertyPath.ofTypeSafe(clazz, function); if (!properties.containsKey(path)) { T value = supplier.get(); properties.put(path, value);/*from ww w.j a va 2 s. co m*/ if (model2Controller != null && controller2Model != null) { converters.put(value, Pair.of(model2Controller, controller2Model)); } else if (model2Controller != null || controller2Model != null) { throw new IllegalArgumentException("Please specify both converters"); } } return (T) properties.get(path); }
From source file:me.Wundero.Ray.variables.Variables.java
/** * Register a new variable wrapper/* w ww .j a v a 2s . c o m*/ */ public boolean registerWrapper(String key, Supplier<Text> s) { return registerWrapper(key, (BiFunction<Variable, Text, Text>) (v, t) -> s.get()); }
From source file:me.Wundero.Ray.variables.Variables.java
/** * Register a new variable//from www .j av a2s . c o m */ public boolean registerVariable(String key, Supplier<Text> replacer) { return registerVariable(key, (Function<Map<Param, Object>, Text>) (o) -> replacer.get()); }