use of java.util.concurrent.FutureTask in project AntennaPod by AntennaPod.
the class RemotePSMP method endPlayback.
@Override
protected Future<?> endPlayback(boolean hasEnded, boolean wasSkipped, boolean shouldContinue, boolean toStoppedState) {
Log.d(TAG, "endPlayback() called");
boolean isPlaying = playerStatus == PlayerStatus.PLAYING;
if (playerStatus != PlayerStatus.INDETERMINATE) {
setPlayerStatus(PlayerStatus.INDETERMINATE, media);
}
if (media != null && wasSkipped) {
// current position only really matters when we skip
int position = getPosition();
if (position >= 0) {
media.setPosition(position);
}
}
final Playable currentMedia = media;
Playable nextMedia = null;
if (shouldContinue) {
nextMedia = callback.getNextInQueue(currentMedia);
boolean playNextEpisode = isPlaying && nextMedia != null && UserPreferences.isFollowQueue();
if (playNextEpisode) {
Log.d(TAG, "Playback of next episode will start immediately.");
} else if (nextMedia == null) {
Log.d(TAG, "No more episodes available to play");
} else {
Log.d(TAG, "Loading next episode, but not playing automatically.");
}
if (nextMedia != null) {
callback.onPlaybackEnded(nextMedia.getMediaType(), !playNextEpisode);
// setting media to null signals to playMediaObject() that we're taking care of post-playback processing
media = null;
playMediaObject(nextMedia, false, true, /*TODO for now we always stream*/
playNextEpisode, playNextEpisode);
}
}
if (shouldContinue || toStoppedState) {
boolean shouldPostProcess = true;
if (nextMedia == null) {
try {
castMgr.stop();
shouldPostProcess = false;
} catch (CastException | TransientNetworkDisconnectionException | NoConnectionException e) {
Log.e(TAG, "Unable to stop playback", e);
callback.onPlaybackEnded(null, true);
stop();
}
}
if (shouldPostProcess) {
// Otherwise we rely on the chromecast callback to tell us the playback has stopped.
callback.onPostPlayback(currentMedia, hasEnded, wasSkipped, nextMedia != null);
}
} else if (isPlaying) {
callback.onPlaybackPause(currentMedia, currentMedia != null ? currentMedia.getPosition() : INVALID_TIME);
}
FutureTask<?> future = new FutureTask<>(() -> {
}, null);
future.run();
return future;
}
use of java.util.concurrent.FutureTask in project AntennaPod by AntennaPod.
the class FeedSearcher method performSearch.
/**
* Search through a feed, or all feeds, for episodes that match the query in either the title,
* chapter, or show notes. The search is first performed on titles, then chapters, and finally
* show notes. The list of resulting episodes also describes where the first match occurred
* (title, chapters, or show notes).
*
* @param context
* @param query search query
* @param selectedFeed feed to search, 0 to search through all feeds
* @return list of episodes containing the query
*/
public static List<SearchResult> performSearch(final Context context, final String query, final long selectedFeed) {
final int[] values = { 2, 1, 0, 0 };
final String[] subtitles = { context.getString(R.string.found_in_title_label), context.getString(R.string.found_in_chapters_label), context.getString(R.string.found_in_shownotes_label), context.getString(R.string.found_in_shownotes_label) };
List<SearchResult> result = new ArrayList<>();
List<FutureTask<List<FeedItem>>> tasks = new ArrayList<>();
tasks.add(DBTasks.searchFeedItemTitle(context, selectedFeed, query));
tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query));
tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query));
tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query));
for (FutureTask<List<FeedItem>> task : tasks) {
task.run();
}
try {
for (int i = 0; i < tasks.size(); i++) {
FutureTask<List<FeedItem>> task = tasks.get(i);
List<FeedItem> items = task.get();
for (FeedItem item : items) {
if (result.isEmpty() || !isDuplicate(result, item)) {
result.add(new SearchResult(item, values[i], subtitles[i]));
}
}
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
Collections.sort(result, new SearchResultValueComparator());
return result;
}
use of java.util.concurrent.FutureTask in project cubrid-manager by CUBRID.
the class MultiHostConnectionDialog method handleConnection.
private void handleConnection() {
for (TableItem item : table.getItems()) {
Object obj = item.getData(KEY_CONNECTION);
if (obj instanceof ConnectionTaskContainer) {
ConnectionTaskContainer container = (ConnectionTaskContainer) obj;
FutureTask<Integer> task = new FutureTask<Integer>(container);
runner.put(task, container);
Display.getDefault().syncExec(task);
}
}
// new Thread(new Runnable() {
//
// @Override
// public void run() {
// while (runner.size() > 0) {
// FutureTask<Integer> tmp = null;
// for (Entry<FutureTask<Integer>, ConnectionTaskContainer> entry : runner.entrySet()) {
// try {
// FutureTask<Integer> task = entry.getKey();
// int retVal = task.get(1, TimeUnit.SECONDS);
// ConnectionTaskContainer con = entry.getValue();
// tmp = task;
// break;
// } catch (Exception e) {
// e.printStackTrace();
// continue;
// }
// }
// runner.remove(tmp);
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
// }).start();
}
use of java.util.concurrent.FutureTask in project apex-core by apache.
the class Node method checkpoint.
void checkpoint(long windowId) {
if (!context.stateless) {
if (operator instanceof Operator.CheckpointNotificationListener) {
((Operator.CheckpointNotificationListener) operator).beforeCheckpoint(windowId);
}
StorageAgent ba = context.getValue(OperatorContext.STORAGE_AGENT);
if (ba != null) {
try {
checkpointStats = new Stats.CheckpointStats();
checkpointStats.checkpointStartTime = System.currentTimeMillis();
ba.save(operator, id, windowId);
if (ba instanceof AsyncStorageAgent) {
AsyncStorageAgent asyncStorageAgent = (AsyncStorageAgent) ba;
if (!asyncStorageAgent.isSyncCheckpoint()) {
if (PROCESSING_MODE != ProcessingMode.EXACTLY_ONCE) {
CheckpointWindowInfo checkpointWindowInfo = new CheckpointWindowInfo();
checkpointWindowInfo.windowId = windowId;
checkpointWindowInfo.applicationWindowCount = applicationWindowCount;
checkpointWindowInfo.checkpointWindowCount = checkpointWindowCount;
CheckpointHandler checkpointHandler = new CheckpointHandler();
checkpointHandler.agent = asyncStorageAgent;
checkpointHandler.operatorId = id;
checkpointHandler.windowId = windowId;
checkpointHandler.stats = checkpointStats;
FutureTask<Stats.CheckpointStats> futureTask = new FutureTask<>(checkpointHandler);
taskQueue.add(new Pair<>(futureTask, checkpointWindowInfo));
executorService.submit(futureTask);
checkpoint = null;
checkpointStats = null;
return;
} else {
asyncStorageAgent.flush(id, windowId);
}
}
}
checkpointStats.checkpointTime = System.currentTimeMillis() - checkpointStats.checkpointStartTime;
} catch (IOException ie) {
try {
logger.warn("Rolling back checkpoint {} for Operator {} due to the exception {}", Codec.getStringWindowId(windowId), operator, ie);
ba.delete(id, windowId);
} catch (IOException ex) {
logger.warn("Error while rolling back checkpoint", ex);
}
throw new RuntimeException(ie);
}
}
}
calculateNextCheckpointWindow();
dagCheckpointOffsetCount = 0;
checkpoint = new Checkpoint(windowId, applicationWindowCount, checkpointWindowCount);
if (operator instanceof Operator.CheckpointListener) {
((Operator.CheckpointListener) operator).checkpointed(windowId);
}
}
use of java.util.concurrent.FutureTask in project geode by apache.
the class IndexManager method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
sb.append(ind).append(getLineSeparator());
}
return sb.toString();
}
Aggregations