Created
February 27, 2018 02:17
-
-
Save legatoo/66ff6a6b209fb5311a0764ffc393b3fe to your computer and use it in GitHub Desktop.
SpringExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.AbstractExtensionId; | |
import akka.actor.ExtendedActorSystem; | |
import akka.actor.Extension; | |
import akka.actor.Props; | |
import akka.routing.FromConfig; | |
import org.springframework.context.ApplicationContext; | |
/** | |
* An Akka Extension to provide access to Spring managed Actor Beans. | |
*/ | |
public class SpringExtension extends | |
AbstractExtensionId<SpringExtension.SpringExt> { | |
/** | |
* The identifier used to access the SpringExtension. | |
*/ | |
public static SpringExtension SpringExtProvider = new SpringExtension(); | |
/** | |
* Is used by Akka to instantiate the Extension identified by this | |
* ExtensionId, internal use only. | |
*/ | |
@Override | |
public SpringExt createExtension(ExtendedActorSystem system) { | |
return new SpringExt(); | |
} | |
/** | |
* The Extension implementation. | |
*/ | |
public static class SpringExt implements Extension { | |
private volatile ApplicationContext applicationContext; | |
/** | |
* Used to initialize the Spring application context for the extension. | |
* @param applicationContext | |
*/ | |
public void initialize(ApplicationContext applicationContext) { | |
this.applicationContext = applicationContext; | |
} | |
/** | |
* Create a Props for the specified actorBeanName using the | |
* SpringActorProducer class. | |
* | |
* @param actorBeanName The name of the actor bean to create Props for | |
* @return a Props that will create the named actor bean using Spring | |
*/ | |
public Props props(String actorBeanName) { | |
return Props.create(SpringActorProducer.class, | |
applicationContext, actorBeanName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment