Support for Spring supervision of bean-based actors
There is a discussion in the mailing-list (http://h.yandex.net/?http%3A%2F%2Fgroups.google.com%2Fgroup%2Fakka-user%2Fbrowse_thread%2Fthread%2F3eb02532e6b9a91a%29) and I've decided to create a ticket.
I use akka 1.1.2. There is an example of Supervisor Hierarchies configuration in Spring: http://akka.io/docs/akka-modules/1.1.2/modules/spring.html#supervisor-hierarchies. It is unclear from the example whether
When I start the application I get the following error:
MyActor class:
I'm not sure that it is a bug. Then is it possible to implement this feature? Precisely how am I supposed to instantiate and supervise actors having non-default constructor using Spring? May be there is some way to define a supervisor and after that declaratively link actors to it in Spring.
I use akka 1.1.2. There is an example of Supervisor Hierarchies configuration in Spring: http://akka.io/docs/akka-modules/1.1.2/modules/spring.html#supervisor-hierarchies. It is unclear from the example whether
implementation
attribute of the akka:untyped-actor
is a required attribute. I have the following example configuration based on Spring beans:<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:akka="http://akka.io/schema/akka"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://akka.io/schema/akka
http://akka.io/akka-1.0.xsd">
<bean id="myActorBean"
class="MyActor"
scope="prototype">
<constructor-arg value="Test"/>
</bean>
<akka:supervision id="supervisor">
<akka:restart-strategy failover="AllForOne"
retries="3"
timerange="4000">
<akka:trap-exits>
<akka:trap-exit>java.io.IOException</akka:trap-exit>
<akka:trap-exit>java.lang.NullPointerException</akka:trap-exit>
</akka:trap-exits>
</akka:restart-strategy>
<akka:untyped-actors>
<akka:untyped-actor id="myActor"
ref="myActorBean"
autostart="true"
lifecycle="temporary"/>
</akka:untyped-actors>
</akka:supervision>
</beans>
When I start the application I get the following error:
Jun 29, 2011 3:33:51 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@207f5580: startup date [Wed Jun 29 15:33:51 MSD 2011]; root of context hierarchy
Jun 29, 2011 3:33:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [test.xml]
Jun 29, 2011 3:33:53 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2d20dbf3: defining beans [myActorBean,supervisor]; root of factory hierarchy
Jun 29, 2011 3:33:53 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2d20dbf3: defining beans [myActorBean,supervisor]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'supervisor': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Class name can't be null or empty string [null]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.yandex.etl.EntryPoint$delayedInit$body.apply(EntryPoint.scala:17)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
at scala.App$class.main(App.scala:60)
at com.yandex.etl.EntryPoint$.main(EntryPoint.scala:12)
at com.yandex.etl.EntryPoint.main(EntryPoint.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.IllegalArgumentException: Class name can't be null or empty string [null]
at akka.spring.StringReflect.<init>(StringReflect.scala:20)
at akka.spring.StringReflect$.string2StringReflect(StringReflect.scala:12)
at akka.spring.SupervisionFactoryBean.createSupervise(SupervisionFactoryBean.scala:84)
at akka.spring.SupervisionFactoryBean$$anonfun$1.apply(SupervisionFactoryBean.scala:48)
at akka.spring.SupervisionFactoryBean$$anonfun$1.apply(SupervisionFactoryBean.scala:48)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
at scala.collection.immutable.List.map(List.scala:45)
at akka.spring.SupervisionFactoryBean.createInstanceForUntypedActors(SupervisionFactoryBean.scala:48)
at akka.spring.SupervisionFactoryBean.createInstance(SupervisionFactoryBean.scala:32)
at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:130)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 27 more
MyActor class:
class MyActor(val name: String) extends Actor {
def receive = {
case msg => EventHandler.info(self, "Received message: %s" format msg)
}
}
I'm not sure that it is a bug. Then is it possible to implement this feature? Precisely how am I supposed to instantiate and supervise actors having non-default constructor using Spring? May be there is some way to define a supervisor and after that declaratively link actors to it in Spring.
Leave a comment
As far as I understand from
SupervisionFactoryBean.scala:84
, only implementation
attribute of untyped-actor
is supported and it is a required attribute. So this is not a bug but a feature request. Without such feature it is impossible to define supervised untyped actors in Spring and at the same time to provide constructor arguments.
on 2011-08-04 20:14 *
By viktorklang
Won't make it into 1.2 without an external patch within 12h so pushing it into 2.0