How to instantiate an actor system from spring.

60 views
Skip to first unread message

Maatary Okouya

unread,
Jun 9, 2015, 5:50:11 PM6/9/15
to akka...@googlegroups.com
Hi, I do not wished to instantiate actor from the bean, but just an actor system. 


The only solution i see so far is to wrap, the actor system in an ActorSystemBen and provide a getActorsystem method to it. The point is, from this bean i can call  ActorSystem()  apply method. 


Is there something more elegant or better ?


Best, 

M

Brian Topping

unread,
Jun 10, 2015, 5:11:28 AM6/10/15
to akka...@googlegroups.com
https://github.com/akka/akka/tree/master/akka-osgi/src/main/scala/akka/osgi shows how to instantiate an ActorSystem under OSGI, which is similar to Spring in that it can be considered a dependency injected framework with a lifecycle. You should be able to map this code with little difficulty.

Brian

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Guido Medina

unread,
Jun 10, 2015, 7:21:54 AM6/10/15
to akka...@googlegroups.com
If you are starting Spring within Tomcat I would recommend you to have the Spring programmatic-ally created and instantiated via @WebListener, then create your @Bean method returning your singleton ActorSystem, within your method you can tweak aspects like configuration, where to load it from, etc etc

Maatary Okouya

unread,
Jun 10, 2015, 9:05:26 AM6/10/15
to akka...@googlegroups.com
Many thanks, closely looking into it.

But so far what I see is that over all the idea is the same as what I came up with. Wrapping your actor system in a class that can be handled by the framework.

I don't see what exact subtle information it provides if it is not things particular to Osgi.

Any particular point that I I don't see?

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/IWGAPnU4gdc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Maatary Okouya

unread,
Jun 10, 2015, 9:11:35 AM6/10/15
to akka...@googlegroups.com
I'm not a a spring expert, I just learned it quickly on the spot for the sake of the project I have inherited.
I am not familiar with the bean method.
In the project yes I can see that they do what you say, meaning instant intuit via a web listener.
However I have no idea what is a bean method, where should it go. What does it has to do with the prommatically created spring.
If you could please detail a bit the step and then point me to some doc, tutorial that would be great.

--

Guido Medina

unread,
Jun 10, 2015, 9:35:01 AM6/10/15
to akka...@googlegroups.com
Pay attention to the WebListener class and @Configuration annotation, my recommendation would be to use both on the same class, create a static spring context which is the one you will use later to locate the spring beans including the ActorSystem which will have a signature like:

@Bean
public ActorSystem actorSystem() {
   
....
}


Source: http://www.codejava.net/frameworks/spring/bootstrapping-a-spring-web-mvc-application-programmatically

Guido Medina

unread,
Jun 10, 2015, 9:45:38 AM6/10/15
to akka...@googlegroups.com
A better example:

 
@Configuration
public class SpringWebAppInitializer implements WebApplicationInitializer {

   
// Ugly but you don't have many options here, maybe a volatile?
   
// Just make sure you don't use this context before it is initialized,
   
// timing will be an issue, I have been there.
   
public static AnnotationConfigWebApplicationContext APPLICATION_CONTEXT = null;

   
@Override
   
public void onStartup(ServletContext container) throws ServletException {
        APPLICATION_CONTEXT
= new AnnotationConfigWebApplicationContext();
       
// Basically point to the same class that is also a web application initializer.
        appContext
.register(SpringWebAppInitializer.class);
   
}
 
   
@Bean
   
public ActorSystem actorSystem() {
       
...
   
}
}

Maatary Okouya

unread,
Jun 10, 2015, 10:21:22 AM6/10/15
to akka...@googlegroups.com
Thank guido. Looking into it. 

Reply all
Reply to author
Forward
0 new messages