scala.concurrent.ExecutionContextExecutor Java Examples

The following examples show how to use scala.concurrent.ExecutionContextExecutor. 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: UnitTest.java    From deployment-examples with MIT License 6 votes vote down vote up
@Test
public void testAsync() {
    final ActorSystem actorSystem = ActorSystem.create("test");
    try {
        final ExecutionContextExecutor ec = actorSystem.dispatcher();
        final AsyncController controller = new AsyncController(actorSystem, ec);
        final CompletionStage<Result> future = controller.message();

        // Block until the result is completed
        await().until(() -> {
            assertThat(future.toCompletableFuture()).isCompletedWithValueMatching(result -> {
                return contentAsString(result).equals("Hi!");
            });
        });
    } finally {
        actorSystem.terminate();
    }
}
 
Example #2
Source File: Slave.java    From akka-tutorial with Apache License 2.0 6 votes vote down vote up
private void handle(AddressMessage message) {
	
	// Cancel any running connect schedule, because got a new address
	if (this.connectSchedule != null) {
		this.connectSchedule.cancel();
		this.connectSchedule = null;
	}

	// Find the shepherd actor in the remote actor system
	final ActorSelection selection = this.getContext().getSystem().actorSelection(String.format("%s/user/%s", message.address, Shepherd.DEFAULT_NAME));

	// Register the local actor system by periodically sending subscription messages (until an acknowledgement was received)
	final Scheduler scheduler = this.getContext().getSystem().scheduler();
	final ExecutionContextExecutor dispatcher = this.getContext().getSystem().dispatcher();
	this.connectSchedule = scheduler.schedule(
			Duration.Zero(),
			Duration.create(5, TimeUnit.SECONDS),
			() -> selection.tell(new Shepherd.SubscriptionMessage(), this.getSelf()),
			dispatcher
	);
}
 
Example #3
Source File: SandalphonThreadsScheduler.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Inject
public SandalphonThreadsScheduler(ActorSystem actorSystem, SandalphonConfiguration config, ProgrammingSubmissionService programmingSubmissionService, @Named("sealtiel") BasicAuthHeader sealtielClientAuthHeader, MessageService messageService) {
    Scheduler scheduler = actorSystem.scheduler();
    ExecutionContextExecutor context = actorSystem.dispatcher();

    GradingResponsePoller poller = new GradingResponsePoller(scheduler, context, programmingSubmissionService, sealtielClientAuthHeader, messageService, TimeUnit.MILLISECONDS.convert(2, TimeUnit.SECONDS));

    if (config.getSealtielConfig().isPresent()) {
        scheduler.schedule(Duration.create(1, TimeUnit.SECONDS), Duration.create(3, TimeUnit.SECONDS), poller, context);
    }
}
 
Example #4
Source File: AbstractContextAwareMsgProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
protected ExecutionContextExecutor getSystemDispatcher() {
  return systemContext.getActorSystem().dispatcher();
}
 
Example #5
Source File: AsyncController.java    From deployment-examples with MIT License 2 votes vote down vote up
/**
 * @param actorSystem We need the {@link ActorSystem}'s
 * {@link Scheduler} to run code after a delay.
 * @param exec We need a Java {@link Executor} to apply the result
 * of the {@link CompletableFuture} and a Scala
 * {@link ExecutionContext} so we can use the Akka {@link Scheduler}.
 * An {@link ExecutionContextExecutor} implements both interfaces.
 */
@Inject
public AsyncController(ActorSystem actorSystem, ExecutionContextExecutor exec) {
  this.actorSystem = actorSystem;
  this.exec = exec;
}