All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chanhohang.akka.spring.SpringActorProducer Maven / Gradle / Ivy

package com.github.chanhohang.akka.spring;

import akka.actor.Actor;
import akka.actor.IndirectActorProducer;

import org.springframework.context.ApplicationContext;

/**
 * Spring Actor Producer that can create Actor with Spring Dependency Injection.
 */
public class SpringActorProducer implements IndirectActorProducer {
  final ApplicationContext applicationContext;
  final String actorBeanName;

  public SpringActorProducer(ApplicationContext applicationContext, String actorBeanName) {
    this.applicationContext = applicationContext;
    this.actorBeanName = actorBeanName;
  }

  @Override
  public Actor produce() {
    return (Actor) applicationContext.getBean(actorBeanName);
  }

  @SuppressWarnings("unchecked")
  @Override
  public Class actorClass() {
    return (Class) applicationContext.getType(actorBeanName);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy