Configure dispatcher in Akka typed actor


(Politrons) #1

I´m working with Akka typed, and I´m not able checking in the official documentation(https://doc.akka.io/docs/akka/current/typed/actors.html#actors), which I found really short, how to configure the Dispatcher in the Actor typed.

Here an example of my code

private int actorTimeout = Integer.parseInt(getProperty("environment.actor.timeout", "10"));

    @Autowired
    private AkkaTypedDAO akkaTypedDAO;

    private ActorSystem<AkkaTypedDTO> system;

    @PostConstruct
    private void initActor() {
        system = ActorSystem.create(akkaTypedDAO.daoWithSupervisor, "AkkaTypedDAO");
    }

    private final Behavior<CommandAkkaTyped> service = Actor.immutable((ctx, msg) -> {
        sendToDAO(msg.id).thenApply(either -> {
            msg.replyTo.tell(either);
            return either;
        });
        return Actor.same();
    });

    public final Behavior<CommandAkkaTyped> serviceWithSupervisor = Actor.supervise(service).onFailure(Exception.class, restart());

    private CompletionStage<Either<ConnectorErrorVO, EntityDaoDTO>> sendToDAO(MUSIn<AkkaTypedPayLoad> id) {
        return AskPattern.ask(system,
                (ActorRef<Either<ConnectorErrorVO, EntityDaoDTO>> replyTo) -> new AkkaTypedDTO(new EntityDaoDTO(musIn), replyTo),
                new Timeout(actorTimeout, TimeUnit.SECONDS), system.scheduler());
    }

Checking the new API in case I want to create passing the Props I have to pass quite a lot more classes.

def create[T](
  guardianBehavior: Behavior[T],
  name: String,
  guardianProps: Optional[Props],
  config: Optional[Config],
  classLoader: Optional[ClassLoader],
  executionContext: Optional[ExecutionContext]): ActorSystem[T] = {
  import scala.compat.java8.OptionConverters._
  apply(guardianBehavior, name, guardianProps.asScala.getOrElse(EmptyProps), config.asScala, 
  classLoader.asScala, executionContext.asScala)
}

When I create my ActorSystem how can I configure the dispatcher for my Actor.immutable?


(Patrik Nordwall) #2

Sorry for late reply. I was looking at uncategorized posts now and found this. For future reference the documentation nowadays has a page about this.