List of usage examples for java.util Queue stream
default Stream<E> stream()
From source file:com.thinkbiganalytics.metadata.jobrepo.nifi.provenance.NifiStatsJmsReceiver.java
public List<NifiFeedProcessorErrors> getErrorsForFeed(String feedName, Long startTime, Long endTime) { List<NifiFeedProcessorErrors> errors = null; Queue<NifiFeedProcessorErrors> queue = feedProcessorErrors.getUnchecked(feedName); if (queue != null) { if (startTime != null && endTime != null) { if (queue != null) { errors = queue.stream() .filter(error -> error.getErrorMessageTimestamp().getMillis() >= startTime && error.getErrorMessageTimestamp().getMillis() <= endTime) .collect(Collectors.toList()); }//from w ww . j a v a 2 s . co m } else if (startTime == null && endTime != null) { errors = queue.stream().filter(error -> error.getErrorMessageTimestamp().getMillis() <= endTime) .collect(Collectors.toList()); } else if (startTime != null && endTime == null) { errors = queue.stream().filter(error -> error.getErrorMessageTimestamp().getMillis() >= startTime) .collect(Collectors.toList()); } else { errors = new ArrayList<>(); errors.addAll(queue); } } else { errors = Collections.emptyList(); } return errors; }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.java
@Override public void asyncOffloadPrefix(Position pos, OffloadCallback callback, Object ctx) { PositionImpl requestOffloadTo = (PositionImpl) pos; if (!isValidPosition(requestOffloadTo)) { callback.offloadFailed(new InvalidCursorPositionException("Invalid position for offload"), ctx); return;// w ww. j a v a 2 s .c o m } PositionImpl firstUnoffloaded; Queue<LedgerInfo> ledgersToOffload = new ConcurrentLinkedQueue<>(); synchronized (this) { log.info("[{}] Start ledgersOffload. ledgers={} totalSize={}", name, ledgers.keySet(), TOTAL_SIZE_UPDATER.get(this)); if (STATE_UPDATER.get(this) == State.Closed) { log.info("[{}] Ignoring offload request since the managed ledger was already closed", name); callback.offloadFailed(new ManagedLedgerAlreadyClosedException( "Can't offload closed managed ledger (" + name + ")"), ctx); return; } if (ledgers.isEmpty()) { log.info("[{}] Tried to offload a managed ledger with no ledgers, giving up", name); callback.offloadFailed(new ManagedLedgerAlreadyClosedException( "Can't offload managed ledger (" + name + ") with no ledgers"), ctx); return; } long current = ledgers.lastKey(); // the first ledger which will not be offloaded. Defaults to current, // in the case that the whole headmap is offloaded. Otherwise it will // be set as we iterate through the headmap values long firstLedgerRetained = current; for (LedgerInfo ls : ledgers.headMap(current).values()) { if (requestOffloadTo.getLedgerId() > ls.getLedgerId()) { // don't offload if ledger has already been offloaded, or is empty if (!ls.getOffloadContext().getComplete() && ls.getSize() > 0) { ledgersToOffload.add(ls); } } else { firstLedgerRetained = ls.getLedgerId(); break; } } firstUnoffloaded = PositionImpl.get(firstLedgerRetained, 0); } if (ledgersToOffload.isEmpty()) { log.info("[{}] No ledgers to offload", name); callback.offloadComplete(firstUnoffloaded, ctx); return; } if (offloadMutex.tryLock()) { log.info("[{}] Going to offload ledgers {}", name, ledgersToOffload.stream().map(l -> l.getLedgerId()).collect(Collectors.toList())); CompletableFuture<PositionImpl> promise = new CompletableFuture<>(); promise.whenComplete((result, exception) -> { offloadMutex.unlock(); if (exception != null) { callback.offloadFailed(new ManagedLedgerException(exception), ctx); } else { callback.offloadComplete(result, ctx); } }); offloadLoop(promise, ledgersToOffload, firstUnoffloaded, Optional.empty()); } else { callback.offloadFailed( new ManagedLedgerException.OffloadInProgressException("Offload operation already running"), ctx); } }
From source file:org.codelibs.fess.helper.SearchLogHelper.java
protected void processSearchLogQueue(final Queue<SearchLog> queue) { final FessConfig fessConfig = ComponentUtil.getFessConfig(); final String value = fessConfig.getPurgeByBots(); String[] botNames;//from w ww .ja va2 s .c o m if (StringUtil.isBlank(value)) { botNames = StringUtil.EMPTY_STRINGS; } else { botNames = value.split(","); } final List<SearchLog> searchLogList = new ArrayList<>(); final Map<String, UserInfo> userInfoMap = new HashMap<>(); queue.stream().forEach(searchLog -> { final String userAgent = searchLog.getUserAgent(); final boolean isBot = userAgent != null && stream(botNames).get(stream -> stream.anyMatch(botName -> userAgent.indexOf(botName) >= 0)); if (!isBot) { searchLog.getUserInfo().ifPresent(userInfo -> { final String code = userInfo.getId(); final UserInfo oldUserInfo = userInfoMap.get(code); if (oldUserInfo != null) { userInfo.setCreatedAt(oldUserInfo.getCreatedAt()); } userInfoMap.put(code, userInfo); }); searchLogList.add(searchLog); } }); if (!userInfoMap.isEmpty()) { final List<UserInfo> insertList = new ArrayList<>(userInfoMap.values()); final List<UserInfo> updateList = new ArrayList<>(); final UserInfoBhv userInfoBhv = ComponentUtil.getComponent(UserInfoBhv.class); userInfoBhv.selectList(cb -> { cb.query().setId_InScope(userInfoMap.keySet()); cb.fetchFirst(userInfoMap.size()); }).forEach(userInfo -> { final String code = userInfo.getId(); final UserInfo entity = userInfoMap.get(code); entity.setId(userInfo.getId()); entity.setCreatedAt(userInfo.getCreatedAt()); updateList.add(entity); insertList.remove(entity); }); userInfoBhv.batchInsert(insertList); userInfoBhv.batchUpdate(updateList); searchLogList.stream().forEach(searchLog -> { searchLog.getUserInfo().ifPresent(userInfo -> { searchLog.setUserInfoId(userInfo.getId()); }); }); } if (!searchLogList.isEmpty()) { storeSearchLogList(searchLogList); if (fessConfig.isSuggestSearchLog()) { final SuggestHelper suggestHelper = ComponentUtil.getSuggestHelper(); suggestHelper.indexFromSearchLog(searchLogList); } } }