fixed properties for untyped actors
This commit is contained in:
parent
4318ad5e43
commit
71ec0bdcfb
4 changed files with 71 additions and 6 deletions
|
|
@ -80,7 +80,9 @@ class ActorFactoryBean extends AbstractFactoryBean[AnyRef] with Logging with App
|
|||
case TYPED_ACTOR_TAG => val typedActor = createTypedInstance()
|
||||
setProperties(AspectInitRegistry.initFor(typedActor).targetInstance)
|
||||
typedActor
|
||||
case UNTYPED_ACTOR_TAG => createUntypedInstance()
|
||||
case UNTYPED_ACTOR_TAG => val untypedActor = createUntypedInstance()
|
||||
setProperties(untypedActor.actor)
|
||||
untypedActor
|
||||
case _ => throw new IllegalArgumentException("Unknown actor type")
|
||||
}
|
||||
ref
|
||||
|
|
|
|||
|
|
@ -3,10 +3,45 @@ package se.scalablesolutions.akka.spring.foo;
|
|||
import se.scalablesolutions.akka.actor.UntypedActor;
|
||||
import se.scalablesolutions.akka.actor.ActorRef;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
|
||||
/**
|
||||
* test class
|
||||
*/
|
||||
public class PingActor extends UntypedActor {
|
||||
public class PingActor extends UntypedActor implements ApplicationContextAware {
|
||||
|
||||
private String stringFromVal;
|
||||
private String stringFromRef;
|
||||
|
||||
private boolean gotApplicationContext = false;
|
||||
|
||||
|
||||
public void setApplicationContext(ApplicationContext context) {
|
||||
gotApplicationContext = true;
|
||||
}
|
||||
|
||||
public boolean gotApplicationContext() {
|
||||
return gotApplicationContext;
|
||||
}
|
||||
|
||||
public String getStringFromVal() {
|
||||
return stringFromVal;
|
||||
}
|
||||
|
||||
public void setStringFromVal(String s) {
|
||||
stringFromVal = s;
|
||||
}
|
||||
|
||||
public String getStringFromRef() {
|
||||
return stringFromRef;
|
||||
}
|
||||
|
||||
public void setStringFromRef(String s) {
|
||||
stringFromRef = s;
|
||||
}
|
||||
|
||||
|
||||
private String longRunning() {
|
||||
try {
|
||||
|
|
@ -31,3 +66,4 @@ public class PingActor extends UntypedActor {
|
|||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,13 @@
|
|||
<property name="stringFromRef" ref="string"/>
|
||||
</akka:typed-actor>
|
||||
|
||||
<akka:untyped-actor id="untypedActor"
|
||||
implementation="se.scalablesolutions.akka.spring.foo.PingActor"
|
||||
scope="singleton">
|
||||
<property name="stringFromVal" value="akka rocks"/>
|
||||
<property name="stringFromRef" ref="string"/>
|
||||
</akka:untyped-actor>
|
||||
|
||||
<bean id="string" class="java.lang.String">
|
||||
<constructor-arg value="spring rocks"/>
|
||||
</bean>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
*/
|
||||
package se.scalablesolutions.akka.spring
|
||||
|
||||
import se.scalablesolutions.akka.actor.ActorRegistry;
|
||||
import se.scalablesolutions.akka.actor.{ActorRegistry, ActorRef}
|
||||
import se.scalablesolutions.akka.spring.foo.PingActor
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext
|
||||
|
|
@ -64,17 +65,36 @@ class ActorFactoryBeanTest extends Spec with ShouldMatchers with BeforeAndAfterA
|
|||
assert(target.getStringFromVal === entry.value)
|
||||
}
|
||||
|
||||
it("should create an application context and verify dependency injection") {
|
||||
it("should create an application context and verify dependency injection for tryped") {
|
||||
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
|
||||
val ta = ctx.getBean("typedActor").asInstanceOf[PojoInf];
|
||||
assert(ta.isInitInvoked)
|
||||
assert(ta.getStringFromVal == "akka rocks")
|
||||
assert(ta.getStringFromRef == "spring rocks")
|
||||
assert(ta.getStringFromVal === "akka rocks")
|
||||
assert(ta.getStringFromRef === "spring rocks")
|
||||
assert(ta.gotApplicationContext)
|
||||
ctx.close
|
||||
}
|
||||
|
||||
it("should create an application context and verify dependency injection for untyped actors") {
|
||||
var ctx = new ClassPathXmlApplicationContext("appContext.xml")
|
||||
val uta = ctx.getBean("untypedActor").asInstanceOf[ActorRef]
|
||||
val ping = uta.actor.asInstanceOf[PingActor]
|
||||
assert(ping.getStringFromVal === "akka rocks")
|
||||
assert(ping.getStringFromRef === "spring rocks")
|
||||
assert(ping.gotApplicationContext)
|
||||
ctx.close
|
||||
}
|
||||
|
||||
it("should stop the created typed actor when scope is singleton and the context is closed") {
|
||||
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
|
||||
val target = ctx.getBean("untypedActor").asInstanceOf[ActorRef]
|
||||
target.start
|
||||
assert(target.isRunning)
|
||||
ctx.close
|
||||
assert(!target.isRunning)
|
||||
}
|
||||
|
||||
it("should stop the created untyped actor when scope is singleton and the context is closed") {
|
||||
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
|
||||
val target = ctx.getBean("bean-singleton").asInstanceOf[SampleBeanIntf]
|
||||
assert(!target.down)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue