scala.concurrent.ExecutionContext Java Examples

The following examples show how to use scala.concurrent.ExecutionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AkkaActorGateway.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Retries to send asynchronously a message up to numberRetries times. The response to this
 * message is returned as a future. The message is re-sent if the number of retries is not yet
 * exceeded and if an exception occurred while sending it.
 *
 * @param message Message to be sent
 * @param numberRetries Number of times to retry sending the message
 * @param timeout Timeout for each sending attempt
 * @param executionContext ExecutionContext which is used to send the message multiple times
 * @return Future of the response to the sent message
 */
@Override
public Future<Object> retry(
		Object message,
		int numberRetries,
		FiniteDuration timeout,
		ExecutionContext executionContext) {

	Object newMessage = decorator.decorate(message);

	return AkkaUtils.retry(
		actor,
		newMessage,
		numberRetries,
		executionContext,
		timeout);
}
 
Example #2
Source File: ActorGatewayResultPartitionConsumableNotifier.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public ActorGatewayResultPartitionConsumableNotifier(
	ExecutionContext executionContext,
	ActorGateway jobManager,
	FiniteDuration jobManagerMessageTimeout) {

	this.executionContext = Preconditions.checkNotNull(executionContext);
	this.jobManager = Preconditions.checkNotNull(jobManager);
	this.jobManagerMessageTimeout = Preconditions.checkNotNull(jobManagerMessageTimeout);
}
 
Example #3
Source File: GradingResponsePoller.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
public GradingResponsePoller(Scheduler scheduler, ExecutionContext executor, ProgrammingSubmissionService submissionService, BasicAuthHeader sealtielClientAuthHeader, MessageService messageService, long interval) {
    this.scheduler = scheduler;
    this.executor = executor;
    this.submissionService = submissionService;
    this.sealtielClientAuthHeader = sealtielClientAuthHeader;
    this.messageService = messageService;
    this.interval = interval;
    this.isConnected = false;
}
 
Example #4
Source File: AsyncSQLConnectionImpl.java    From AsyncDao with MIT License 4 votes vote down vote up
public AsyncSQLConnectionImpl(Connection connection, ConnectionPool pool, ExecutionContext executionContext) {
    this.connection = connection;
    this.pool = pool;
    this.executionContext = executionContext;
}
 
Example #5
Source File: AsyncController.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@Inject
public AsyncController(ActorSystem actorSystem, ExecutionContext exec) {
    this.actorSystem = actorSystem;
    this.exec = exec;
}
 
Example #6
Source File: AsyncController.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@Inject
public AsyncController(ActorSystem actorSystem, ExecutionContext exec) {
    this.actorSystem = actorSystem;
    this.exec = exec;
}
 
Example #7
Source File: Executors.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutionContext prepare() {
	return this;
}
 
Example #8
Source File: TestBaseUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static ExecutionContext defaultExecutionContext() {
	return ExecutionContext$.MODULE$.global();
}
 
Example #9
Source File: RabbitMQClientActor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private CompletionStage<Status.Status> connect(final Connection connection, final Duration createChannelTimeout,
        final Duration internalReconnectTimeout) {

    final CompletableFuture<Status.Status> future = new CompletableFuture<>();
    if (rmqConnectionActor == null) {
        // complete the future if something went wrong during creation of the connection-factory-factory
        final RabbitMQExceptionHandler rabbitMQExceptionHandler =
                new RabbitMQExceptionHandler(throwable -> future.complete(new Status.Failure(throwable)));

        final Optional<ConnectionFactory> connectionFactoryOpt =
                tryToCreateConnectionFactory(rabbitConnectionFactoryFactory, connection, rabbitMQExceptionHandler);

        if (connectionFactoryOpt.isPresent()) {
            final ConnectionFactory connectionFactory = connectionFactoryOpt.get();

            final Props props = com.newmotion.akka.rabbitmq.ConnectionActor.props(connectionFactory,
                    FiniteDuration.apply(internalReconnectTimeout.getSeconds(), TimeUnit.SECONDS),
                    (rmqConnection, connectionActorRef) -> {
                        log.info("Established RMQ connection: {}", rmqConnection);
                        return null;
                    });

            rmqConnectionActor = startChildActorConflictFree(RMQ_CONNECTION_ACTOR_NAME, props);
            rmqPublisherActor = startRmqPublisherActor();

            // create publisher channel
            final CreateChannel createChannel = CreateChannel.apply(
                    ChannelActor.props((channel, channelActor) -> {
                        log.info("Did set up publisher channel: {}. Telling the publisher actor the new channel",
                                channel);
                        // provide the new channel to the publisher after the channel was connected (also includes reconnects)
                        if (rmqPublisherActor != null) {
                            final ChannelCreated channelCreated = new ChannelCreated(channelActor);
                            rmqPublisherActor.tell(channelCreated, channelActor);
                        }
                        return null;
                    }),
                    Option.apply(PUBLISHER_CHANNEL));


            final Scheduler scheduler = getContext().system().scheduler();
            final ExecutionContext dispatcher = getContext().dispatcher();
            Patterns.ask(rmqConnectionActor, createChannel, createChannelTimeout).handle((reply, throwable) -> {
                if (throwable != null) {
                    future.complete(new Status.Failure(throwable));
                } else {
                    // waiting for "final RabbitMQExceptionHandler rabbitMQExceptionHandler" to get its chance to
                    // complete the future with an Exception before we report Status.Success right now
                    // so delay this by 1 second --
                    // with Java 9 this could be done more elegant with "orTimeout" or "completeOnTimeout" methods:
                    scheduler.scheduleOnce(Duration.ofSeconds(1L),
                            () -> future.complete(new Status.Success("channel created")),
                            dispatcher);
                }
                return null;
            });
        }
    } else {
        log.debug("Connection <{}> is already open.", connectionId());
        future.complete(new Status.Success("already connected"));
    }
    return future;

}
 
Example #10
Source File: PatternsAdapter.java    From ari-proxy with GNU Affero General Public License v3.0 4 votes vote down vote up
public static <T> PipeableFuture<T> pipeTo(Future<T> future, ActorRef replyTo, ExecutionContext executionContext) {
	return Patterns.pipe(CustomFutureConverters.toScala(future), executionContext).to(replyTo);
}
 
Example #11
Source File: VertxEventLoopExecutionContext.java    From AsyncDao with MIT License 4 votes vote down vote up
@Override
public ExecutionContext prepare() {
  // No preparation required.
  return this;
}
 
Example #12
Source File: VertxEventLoopExecutionContext.java    From AsyncDao with MIT License 4 votes vote down vote up
public static ExecutionContext create(Vertx vertx) {
  return new VertxEventLoopExecutionContext(vertx);
}
 
Example #13
Source File: ScalaUtils.java    From AsyncDao with MIT License 4 votes vote down vote up
public static <T> Future<Void> scalaToVertxVoid(scala.concurrent.Future<T> future, ExecutionContext ec) {
    Future<Void> fut = Future.future();
    future.onComplete(new AbstractFunction1<Try<T>, Void>() {
        @Override
        public Void apply(Try<T> v1) {
            if (v1.isSuccess()) {
                fut.complete();
            } else {
                fut.fail(v1.failed().get());
            }
            return null;
        }
    }, ec);
    return fut;
}
 
Example #14
Source File: ScalaUtils.java    From AsyncDao with MIT License 4 votes vote down vote up
public static <T> Future<T> scalaToVertx(scala.concurrent.Future<T> future, ExecutionContext ec) {
    Future<T> fut = Future.future();
    future.onComplete(new AbstractFunction1<Try<T>, Void>() {
        @Override
        public Void apply(Try<T> v1) {
            if (v1.isSuccess()) {
                fut.complete(v1.get());
            } else {
                fut.fail(v1.failed().get());
            }
            return null;
        }
    }, ec);
    return fut;
}
 
Example #15
Source File: TestBaseUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static ExecutionContext defaultExecutionContext() {
	return ExecutionContext$.MODULE$.global();
}
 
Example #16
Source File: Executors.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutionContext prepare() {
	return this;
}
 
Example #17
Source File: TestBaseUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static ExecutionContext defaultExecutionContext() {
	return ExecutionContext$.MODULE$.global();
}
 
Example #18
Source File: ExecutionGraphTestUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public SimpleActorGateway(ExecutionContext executionContext){
	super(executionContext);
}
 
Example #19
Source File: DummyActorGateway.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public Future<Object> retry(Object message, int numberRetries, FiniteDuration timeout, ExecutionContext executionContext) {
	return null;
}
 
Example #20
Source File: BaseTestingActorGateway.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public Future<Object> retry(Object message, int numberRetries, FiniteDuration timeout, ExecutionContext executionContext) {
	return ask(message, timeout);
}
 
Example #21
Source File: BaseTestingActorGateway.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public BaseTestingActorGateway(ExecutionContext executionContext) {
	this.executionContext = executionContext;
}
 
Example #22
Source File: Executors.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutionContext prepare() {
	return this;
}
 
Example #23
Source File: ActorGateway.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Retries to send asynchronously a message up to numberRetries times. The response to this
 * message is returned as a future. The message is re-sent if the number of retries is not yet
 * exceeded and if an exception occurred while sending it.
 *
 * @param message Message to be sent
 * @param numberRetries Number of times to retry sending the message
 * @param timeout Timeout for each sending attempt
 * @param executionContext ExecutionContext which is used to send the message multiple times
 * @return Future of the response to the sent message
 */
Future<Object> retry(
		Object message,
		int numberRetries,
		FiniteDuration timeout,
		ExecutionContext executionContext);
 
Example #24
Source File: Executors.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Return a direct execution context. The direct execution context executes the runnable directly
 * in the calling thread.
 *
 * @return Direct execution context.
 */
public static ExecutionContext directExecutionContext() {
	return DirectExecutionContext.INSTANCE;
}
 
Example #25
Source File: Executors.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Return a direct execution context. The direct execution context executes the runnable directly
 * in the calling thread.
 *
 * @return Direct execution context.
 */
public static ExecutionContext directExecutionContext() {
	return DirectExecutionContext.INSTANCE;
}
 
Example #26
Source File: Executors.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Return a direct execution context. The direct execution context executes the runnable directly
 * in the calling thread.
 *
 * @return Direct execution context.
 */
public static ExecutionContext directExecutionContext() {
	return DirectExecutionContext.INSTANCE;
}