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 extends Actor> actorClass() {
return (Class extends Actor>) applicationContext.getType(actorBeanName);
}
}