Skip to content
Snippets Groups Projects
Commit 62ff0fa1 authored by Ludovic Claude's avatar Ludovic Claude
Browse files

Improve init of actor system

parent caba9c6d
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package eu.hbp.mip.akka; ...@@ -2,6 +2,7 @@ package eu.hbp.mip.akka;
import akka.actor.ActorRef; import akka.actor.ActorRef;
import akka.actor.ActorSystem; import akka.actor.ActorSystem;
import akka.cluster.pubsub.DistributedPubSub;
import akka.cluster.pubsub.DistributedPubSubMediator; import akka.cluster.pubsub.DistributedPubSubMediator;
import akka.pattern.Patterns; import akka.pattern.Patterns;
import akka.util.Timeout; import akka.util.Timeout;
...@@ -10,6 +11,7 @@ import ch.chuv.lren.woken.messages.query.QueryResult; ...@@ -10,6 +11,7 @@ import ch.chuv.lren.woken.messages.query.QueryResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -33,9 +35,6 @@ public abstract class WokenClientController { ...@@ -33,9 +35,6 @@ public abstract class WokenClientController {
@Value("#{'${akka.woken.path:/user/entrypoint}'}") @Value("#{'${akka.woken.path:/user/entrypoint}'}")
private String wokenPath; private String wokenPath;
@Autowired
private ActorRef wokenMediator;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <A, B> B askWoken(A message, int waitInSeconds) throws Exception { protected <A, B> B askWoken(A message, int waitInSeconds) throws Exception {
LOGGER.info("Akka is trying to reach remote " + wokenPath); LOGGER.info("Akka is trying to reach remote " + wokenPath);
...@@ -43,7 +42,7 @@ public abstract class WokenClientController { ...@@ -43,7 +42,7 @@ public abstract class WokenClientController {
DistributedPubSubMediator.Send queryMessage = new DistributedPubSubMediator.Send(wokenPath, message, false); DistributedPubSubMediator.Send queryMessage = new DistributedPubSubMediator.Send(wokenPath, message, false);
Timeout timeout = new Timeout(Duration.create(waitInSeconds, "seconds")); Timeout timeout = new Timeout(Duration.create(waitInSeconds, "seconds"));
Future<Object> future = Patterns.ask(wokenMediator, queryMessage, timeout); Future<Object> future = Patterns.ask(wokenMediator(), queryMessage, timeout);
return (B) Await.result(future, timeout.duration()); return (B) Await.result(future, timeout.duration());
} }
...@@ -75,10 +74,14 @@ public abstract class WokenClientController { ...@@ -75,10 +74,14 @@ public abstract class WokenClientController {
DistributedPubSubMediator.Send queryMessage = new DistributedPubSubMediator.Send(wokenPath, query, false); DistributedPubSubMediator.Send queryMessage = new DistributedPubSubMediator.Send(wokenPath, query, false);
return Patterns.ask(wokenMediator, queryMessage, waitInSeconds); return Patterns.ask(wokenMediator(), queryMessage, waitInSeconds);
} }
protected ExecutionContext getExecutor() { protected ExecutionContext getExecutor() {
return actorSystem.dispatcher(); return actorSystem.dispatcher();
} }
private ActorRef wokenMediator() {
return DistributedPubSub.get(actorSystem).mediator();
}
} }
...@@ -53,6 +53,7 @@ public class AkkaConfiguration { ...@@ -53,6 +53,7 @@ public class AkkaConfiguration {
} }
@Bean @Bean
@DependsOn("actorSystem")
public Cluster wokenCluster() { public Cluster wokenCluster() {
Cluster cluster = Cluster.get(actorSystem()); Cluster cluster = Cluster.get(actorSystem());
LOGGER.info("Connect to Woken cluster nodes at " + String.join(",", wokenPath())); LOGGER.info("Connect to Woken cluster nodes at " + String.join(",", wokenPath()));
...@@ -120,11 +121,4 @@ public class AkkaConfiguration { ...@@ -120,11 +121,4 @@ public class AkkaConfiguration {
return config.getStringList("akka.cluster.seed-nodes"); return config.getStringList("akka.cluster.seed-nodes");
} }
@Bean
@Lazy
@DependsOn("wokenCluster")
public ActorRef wokenMediator() {
return DistributedPubSub.get(actorSystem()).mediator();
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment