@Override public Stream<ConsumerRecord<K, V>> stream() { return consumed.stream(); }
private void filterBufferAndResetFetchRunnable(Set<StreamPartition<String>> partitions) throws InterruptedException { scheduledExec.shutdown(); try { if (!scheduledExec.awaitTermination(EXCEPTION_RETRY_DELAY_MS, TimeUnit.MILLISECONDS)) { scheduledExec.shutdownNow(); } } catch (InterruptedException e) { log.warn(e, "InterruptedException while shutting down"); throw e; } scheduledExec = Executors.newScheduledThreadPool( fetchThreads, Execs.makeThreadFactory("KinesisRecordSupplier-Worker-%d") ); // filter records in buffer and only retain ones whose partition was not seeked BlockingQueue<OrderedPartitionableRecord<String, String>> newQ = new LinkedBlockingQueue<>(recordBufferSize); records .stream() .filter(x -> !partitions.contains(x.getStreamPartition())) .forEachOrdered(newQ::offer); records = newQ; // restart fetching threads partitionResources.values().forEach(x -> x.started = false); checkPartitionsStarted = true; }
/** * Not thread-safe. Can only be called from the solver thread. * @param stepIndex at least 0 */ public void startNextStep(int stepIndex) { synchronized (this) { if (filterStepIndex >= stepIndex) { throw new IllegalStateException("The old filterStepIndex (" + filterStepIndex + ") must be less than the stepIndex (" + stepIndex + ")"); } filterStepIndex = stepIndex; MoveResult<Solution_> exceptionResult = innerQueue.stream().filter(MoveResult::hasThrownException) .findFirst().orElse(null); if (exceptionResult != null) { throw new IllegalStateException("The move thread with moveThreadIndex (" + exceptionResult.getMoveThreadIndex() + ") has thrown an exception." + " Relayed here in the parent thread.", exceptionResult.getThrowable()); } innerQueue.clear(); } nextMoveIndex = 0; backlog.clear(); }
/** * Returns a stream of all pending tasks. This is similar to {@link #getQueue()} but will expose the originally submitted * {@link Runnable} instances rather than potentially wrapped ones. */ public Stream<Runnable> getTasks() { return this.getQueue().stream().map(this::unwrap); }
private Optional<Task> findAlreadyScheduled(Task aTask) { return queue.stream().filter(aTask::matches).findAny(); } }
private Optional<Task> findAlreadyScheduled(Task aTask) { return queue.stream().filter(aTask::matches).findAny(); } }
/** * This is a helper method for unit testing. Disclaimer: Do not use this method outside unit tests, as * this method is iterating the queue which can be an expensive operation (CPU time, queue locking). * * @return true, if the queue contains at least one expired element */ @VisibleForTesting // (otherwise = VisibleForTesting.NONE) boolean backlogContainsExpiredMessages(long nowNanos) { return backlog.stream().anyMatch(entry -> entry.isTimedOut(nowNanos)); }
/** * Returns a stream of all pending tasks. This is similar to {@link #getQueue()} but will expose the originally submitted * {@link Runnable} instances rather than potentially wrapped ones. */ public Stream<Runnable> getTasks() { return this.getQueue().stream().map(this::unwrap); }
/** * This is a helper method for unit testing. Disclaimer: Do not use this method outside unit tests, as * this method is iterating the queue which can be an expensive operation (CPU time, queue locking). * * @return true, if the queue contains at least one expired element */ @VisibleForTesting // (otherwise = VisibleForTesting.NONE) boolean backlogContainsExpiredMessages(long nowNanos) { return backlog.stream().anyMatch(entry -> entry.isTimedOut(nowNanos)); }
/** * Returns a stream of all pending tasks. This is similar to {@link #getQueue()} but will expose the originally submitted * {@link Runnable} instances rather than potentially wrapped ones. */ public Stream<Runnable> getTasks() { return this.getQueue().stream().map(this::unwrap); }
/** * This is a helper method for unit testing. Disclaimer: Do not use this method outside unit tests, as * this method is iterating the queue which can be an expensive operation (CPU time, queue locking). * * @return true, if the queue contains at least one expired element */ @VisibleForTesting // (otherwise = VisibleForTesting.NONE) boolean backlogContainsExpiredMessages(long nowNanos) { return backlog.stream().anyMatch(entry -> entry.isTimedOut(nowNanos)); }
/** * Returns a stream of all pending tasks. This is similar to {@link #getQueue()} but will expose the originally submitted * {@link Runnable} instances rather than potentially wrapped ones. */ public Stream<Runnable> getTasks() { return this.getQueue().stream().map(this::unwrap); }
@Override public void remove(final IProcessIdentfier identifier) { final List<ProcessScheduledFuture<?>> futures = this.executor .getQueue() .stream() .map(r -> (ProcessScheduledFuture<?>) r) .collect(Collectors.toList()); for (final ProcessScheduledFuture<?> future : futures) { if (future.getIdentifier().equals(identifier)) { this.executor.getQueue().remove(future); return; } } }
@Override public void cancel(final IProcessIdentfier identifier) { final List<ProcessScheduledFuture<?>> futures = this.executor .getQueue() .stream() .map(r -> (ProcessScheduledFuture<?>) r) .collect(Collectors.toList()); for (final ProcessScheduledFuture<?> future : futures) { if (future.getIdentifier().equals(identifier)) { future.cancel(true); return; } } }
@Override public void remove(final IProcessIdentfier identifier) { final List<ProcessScheduledFuture<?>> futures = this.executor .getQueue() .stream() .map(r -> (ProcessScheduledFuture<?>) r) .collect(Collectors.toList()); for (final ProcessScheduledFuture<?> future : futures) { if (future.getIdentifier().equals(identifier)) { this.executor.getQueue().remove(future); return; } } }
@Override public void cancel(final IProcessIdentfier identifier) { final List<ProcessScheduledFuture<?>> futures = this.executor .getQueue() .stream() .map(r -> (ProcessScheduledFuture<?>) r) .collect(Collectors.toList()); for (final ProcessScheduledFuture<?> future : futures) { if (future.getIdentifier().equals(identifier)) { future.cancel(true); return; } } }
public boolean isIndexInProgress(Project aProject) { Validate.notNull(aProject, "Project cannot be null"); return queue.stream().anyMatch(task -> aProject.equals(task.getProject())) || consumer.getActiveTask().map(t -> aProject.equals(t.getProject())).orElse(false); }
public boolean isIndexInProgress(Project aProject) { Validate.notNull(aProject, "Project cannot be null"); return queue.stream().anyMatch(task -> aProject.equals(task.getProject())) || consumer.getActiveTask().map(t -> aProject.equals(t.getProject())).orElse(false); }
/** * Assert that all the commands already invoked remotely have been verified and there were no errors. */ public void verifyNoErrors() { assertTrue("Unexpected remote invocations: " + blockedRequests.stream().map(i -> i.getCommand().toString()).collect(Collectors.joining(", ")), blockedRequests.isEmpty()); }
/** * Creates the audio state by copying the currently playing track, the volume, * voice and channel IDs used for the music, guild ID, as well as all the * tracks in the queue, the audio state can be used when the bot shuts * down, to save it all the cache, or when the bot starts back up * again, to load everything back into the music player. * * @param musicManager The guild music manager that the audio state should be created for. * @param guild The JDA guild object for the current guild music manager. */ public AudioState(GuildMusicManager musicManager, Guild guild) { this.volume = musicManager.getPlayer().getVolume(); this.guildId = guild.getIdLong(); VoiceChannel channel = LavalinkManager.LavalinkManagerHolder.lavalink.getConnectedChannel(guild); voiceChannelId = channel != null ? channel.getIdLong() : 0L; messageChannelId = musicManager.getLastActiveMessage() != null ? musicManager.getLastActiveMessage().getChannel().getIdLong() : 0L; AudioTrack playingTrack = musicManager.getPlayer().getPlayingTrack(); AudioTrackContainer container = musicManager.getScheduler().getAudioTrackContainer(); this.playingTrack = playingTrack == null ? null : new AudioCache( playingTrack.getInfo().uri, container != null ? container.getRequester().getIdLong() : 0L, playingTrack.getPosition() ); musicManager.getScheduler().getQueue().stream() .map(AudioCache::new) .forEach(queue::add); }