@Override protected void channelRead0(ChannelHandlerContext ctx, HttpRequest httpRequest) { CompletableFuture<HttpRequest> future = CompletableFuture.completedFuture(httpRequest); Executor executor = ctx.executor(); future.thenApplyAsync(req -> buildWebContext(ctx, req), executor) .thenApplyAsync(this::executeLogic, executor) .thenApplyAsync(this::buildResponse, executor) .exceptionally(this::handleException) .thenAcceptAsync(msg -> writeResponse(ctx, future, msg), ctx.channel().eventLoop()); }
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpRequest httpRequest) { CompletableFuture<HttpRequest> future = CompletableFuture.completedFuture(httpRequest); Executor executor = ctx.executor(); future.thenApplyAsync(req -> buildWebContext(ctx, req), executor) .thenApplyAsync(this::executeLogic, executor) .thenApplyAsync(this::buildResponse, executor) .exceptionally(this::handleException) .thenAcceptAsync(msg -> writeResponse(ctx, future, msg), ctx.channel().eventLoop()); }
@Override public <U> DefaultConnectionFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn) { return adopt(delegate.thenApplyAsync(fn)); }
@Override public <U> DefaultConnectionFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn, Executor executor) { return adopt(delegate.thenApplyAsync(fn, executor)); }
@Override public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn) { return wrap(super.thenApplyAsync(fn)); }
@Override public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn, Executor executor) { return wrap(super.thenApplyAsync(fn, executor)); }
@SafeVarargs public static <T> CompletableFuture<T> allOf( T defaultValue, BinaryOperator<T> merger, CompletableFuture<T>... futures) { @SuppressWarnings("unchecked") final CompletableFuture<Void>[] accumulators = (CompletableFuture<Void>[]) Array.newInstance( CompletableFuture.class, futures.length ); final AtomicReference<T> result = new AtomicReference<>(defaultValue); for (int i = 0; i < futures.length; i++) { final CompletableFuture<T> future = futures[i]; accumulators[i] = future.thenAcceptAsync(r -> result.accumulateAndGet(r, merger)); } return CompletableFuture.allOf(accumulators) .thenApplyAsync(v -> result.get()); }
/** * Returns a Future for a GlowOfflinePlayer by UUID. If possible, the player's data (including * name) will be loaded based on the UUID. * * @param server The server of the offline player. Must not be null. * @param uuid The UUID of the player. Must not be null. * @return A {@link GlowOfflinePlayer} future. */ public static CompletableFuture<GlowOfflinePlayer> getOfflinePlayer(GlowServer server, UUID uuid) { checkNotNull(server, "server must not be null"); // NON-NLS checkNotNull(uuid, "UUID must not be null"); // NON-NLS return ProfileCache.getProfile(uuid) .thenApplyAsync((profile) -> new GlowOfflinePlayer(server, profile)); }
@Override public <U> Task<U> thenApplyAsync(Function<? super T, ? extends U> function) { final Function<? super T, ? extends U> wrap = TaskContext.wrap(function); return Task.from(super.thenApplyAsync(wrap)); }
@Override public <U> Task<U> thenApplyAsync(Function<? super T, ? extends U> function, Executor executor) { final Function<? super T, ? extends U> wrap = TaskContext.wrap(function); return Task.from(super.thenApplyAsync(wrap, executor)); }
@VisibleForTesting CompletableFuture<URL> getWebMonitorBaseUrl() { return FutureUtils.orTimeout( webMonitorLeaderRetriever.getLeaderFuture(), restClusterClientConfiguration.getAwaitLeaderTimeout(), TimeUnit.MILLISECONDS) .thenApplyAsync(leaderAddressSessionId -> { final String url = leaderAddressSessionId.f0; try { return new URL(url); } catch (MalformedURLException e) { throw new IllegalArgumentException("Could not parse URL from " + url, e); } }, executorService); } }
@Override public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor) { return ctx.makeContextAware(super.thenApplyAsync(ctx.makeContextAware(fn), executor)); }
@Override public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn, Executor executor) { return wrap(orderedFuture().thenApplyAsync(fn, executor)); }
@Override public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn) { return ctx.makeContextAware(super.thenApplyAsync(ctx.makeContextAware(fn))); }
@Override public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn) { return wrap(orderedFuture().thenApplyAsync(fn)); }
@Override public <U> Task<U> thenApply(final Function<? super T, ? extends U> fn) { final Function<? super T, ? extends U> wrap = TaskContext.wrap(fn); if (defaultExecutor != null) { return from(super.thenApplyAsync(wrap, defaultExecutor)); } return from(super.thenApply(wrap)); }
@Override @SuppressWarnings("unchecked") public CompletableFuture<String> latestVersion() { return Rest.connectHttps("service.speedment.com") .get(format("version/%s/latest", info.getRepository())) .thenApplyAsync(res -> { if (res.success()) { return res.decodeJson() .map(m -> (Map<String, String>) m) .map(m -> m.get("tag")) .orElseThrow(() -> new SpeedmentToolException( "Could not establish the latest version." )); } else { throw new SpeedmentToolException( "Received an error '" + res.getText() + "' from the GitHub API." ); } }); } }
/** * Creates a new {@link GlowOfflinePlayer} instance for the given name. * * @param name the player's name to look up. * @return a {@link GlowOfflinePlayer} future for the given name. */ public CompletableFuture<OfflinePlayer> getOfflinePlayerAsync(String name) { Player onlinePlayer = getPlayerExact(name); if (onlinePlayer != null) { return CompletableFuture.completedFuture(onlinePlayer); } return GlowPlayerProfile.getProfile(name).thenApplyAsync((profile) -> { if (profile == null) { return getOfflinePlayerFallback(name); } else { return getOfflinePlayer(profile); } }); }
@Override protected CompletableFuture<Void> prepareLeadershipAsync() { Preconditions.checkState(initializedMesosConfig != null); schedulerDriver = initializedMesosConfig.createDriver( new MesosResourceManagerSchedulerCallback(), false); // create supporting actors connectionMonitor = createConnectionMonitor(); launchCoordinator = createLaunchCoordinator(schedulerDriver, selfActor); reconciliationCoordinator = createReconciliationCoordinator(schedulerDriver); taskMonitor = createTaskMonitor(schedulerDriver); return getWorkersAsync().thenApplyAsync((tasksFromPreviousAttempts) -> { // recover state recoverWorkers(tasksFromPreviousAttempts); // begin scheduling connectionMonitor.tell(new ConnectionMonitor.Start(), selfActor); schedulerDriver.start(); LOG.info("Mesos resource manager started."); return null; }, getMainThreadExecutor()); }
private CompletableFuture<Project> readSchemaMetadata( Project project, Dbms dbms, ProgressMeasure progress) { //final DbmsType dbmsType = dbmsTypeOf(dbmsHandlerComponent, dbms); progress.setCurrentAction(describe(dbms)); LOGGER.info(describe(dbms)); final CompletableFuture<Map<String, Class<?>>> typeMappingTask = typeMappingHelper.loadFor(dbms); final Schema schema = dbms.mutator().addNewSchema(); schema.mutator().setId("schema"); schema.mutator().setName("schema"); return readTableMetadata(schema, typeMappingTask, progress) .thenApplyAsync($ -> project); }