Skip to content

Instantly share code, notes, and snippets.

@zeroows
Created February 17, 2015 07:43
Show Gist options
  • Save zeroows/ef200055e5d281393f6b to your computer and use it in GitHub Desktop.
Save zeroows/ef200055e5d281393f6b to your computer and use it in GitHub Desktop.
An actor producer that lets Spring create the Actor instances.
package tk.aalkhodiry.client.akka;
import org.springframework.context.ApplicationContext;
import akka.actor.Actor;
import akka.actor.IndirectActorProducer;
/**
* An actor producer that lets Spring create the Actor instances.
*/
public class SpringActorProducer implements IndirectActorProducer {
private final ApplicationContext applicationContext;
private 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment