added config for WorkStealingDispatcher and HawtDispatcher; Tickets 200 and 377

This commit is contained in:
Michael Kober 2010-08-12 09:02:49 +02:00
parent a16e909521
commit ef79befe9a
8 changed files with 29 additions and 4 deletions

View file

@ -76,6 +76,7 @@
<xsd:attribute name="ref" type="xsd:string"/>
<xsd:attribute name="type" type="dispatcher-enum-type"/>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="aggregate" type="xsd:boolean"/>
</xsd:complexType>
<xsd:complexType name="threadpool-type">

View file

@ -55,6 +55,7 @@ object AkkaSpringConfigurationTags {
val NAME = "name"
val REF = "ref"
val TYPE = "type"
val AGGREGATE = "aggregate" // HawtDispatcher
// thread pool attributes
val QUEUE = "queue"

View file

@ -22,7 +22,7 @@ object DispatcherFactoryBean {
case REACTOR_BASED_THREAD_POOL_EVENT_DRIVEN => Dispatchers.newReactorBasedThreadPoolEventDrivenDispatcher(properties.name)
case REACTOR_BASED_SINGLE_THREAD_EVENT_DRIVEN => Dispatchers.newReactorBasedSingleThreadEventDrivenDispatcher(properties.name)
case THREAD_BASED => throw new IllegalArgumentException("not implemented yet") //FIXME
case HAWT => throw new IllegalArgumentException("not implemented yet") //FIXME
case HAWT => Dispatchers.newHawtDispatcher(properties.aggregate)
case _ => throw new IllegalArgumentException("unknown dispatcher type")
}
if ((properties.threadPool != null) && (properties.threadPool.queue != null)) {

View file

@ -28,7 +28,7 @@ trait DispatcherParser extends BeanParser {
throw new IllegalArgumentException("Referenced dispatcher not found: '" + ref + "'")
}
}
properties.name = mandatory(dispatcherElement, NAME)
properties.dispatcherType = mandatory(dispatcherElement, TYPE)
if (properties.dispatcherType == THREAD_BASED) {
if ((dispatcherElement.getParentNode.getNodeName != "akka:typed-actor") &&
@ -36,6 +36,16 @@ trait DispatcherParser extends BeanParser {
throw new IllegalArgumentException("Thread based dispatcher must be nested in typed-actor element!")
}
}
if (properties.dispatcherType == HAWT) { // no name for HawtDispatcher
properties.name = dispatcherElement.getAttribute(NAME)
if (dispatcherElement.hasAttribute(AGGREGATE)) {
properties.aggregate = dispatcherElement.getAttribute(AGGREGATE).toBoolean
}
} else {
properties.name = mandatory(dispatcherElement, NAME)
}
val threadPoolElement = DomUtils.getChildElementByTagName(dispatcherElement, THREAD_POOL_TAG);
if (threadPoolElement != null) {
if (properties.dispatcherType == REACTOR_BASED_SINGLE_THREAD_EVENT_DRIVEN ||

View file

@ -14,6 +14,7 @@ class DispatcherProperties {
var dispatcherType: String = ""
var name: String = ""
var threadPool: ThreadPoolProperties = _
var aggregate = true
/**
* Sets the properties to the given builder.

View file

@ -69,8 +69,8 @@ http://scalablesolutions.se/akka/akka-0.10.xsd">
<!-- executor-based-event-driven-work-stealing-dispatcher -->
<akka:dispatcher id="executor-based-event-driven-work-stealing-dispatcher" type="executor-based-event-driven-work-stealing" name="workStealingDispatcher" />
<!-- hawt-dispatcher
<akka:dispatcher id="hawt-dispatcher" type="hawt" name="hawtDispatcher" /> -->
<!-- hawt-dispatcher -->
<akka:dispatcher id="hawt-dispatcher" type="hawt" aggregate="false" name="test" />
<!-- thread-based-dispatcher
<akka:typed-actor id="typed-actor-with-thread-based-dispatcher"

View file

@ -101,6 +101,17 @@ class DispatcherBeanDefinitionParserTest extends Spec with ShouldMatchers {
val xml = <akka:dispatcher id="dispatcher" type="thread-based" name="myDispatcher" />
evaluating { parser.parseDispatcher(dom(xml).getDocumentElement) } should produce [IllegalArgumentException]
}
it("should be able to parse the hawt dispatcher configuration") {
// hawt
val xml = <akka:dispatcher id="dispatcher"
type="hawt"
aggregate="false" />
var props = parser.parseDispatcher(dom(xml).getDocumentElement);
assert(props != null)
assert(props.dispatcherType === "hawt")
assert(props.aggregate === false)
}
}
}

View file

@ -108,6 +108,7 @@ class DispatcherSpringFeatureTest extends FeatureSpec with ShouldMatchers {
val dispatcher = context.getBean("hawt-dispatcher").asInstanceOf[HawtDispatcher]
assert(dispatcher != null)
assert(dispatcher.toString === "HawtDispatchEventDrivenDispatcher")
assert(dispatcher.aggregate === false)
}
scenario("get a thread-based-dispatcher from context") {