Support for using ActiveObjectComponent without Camel service
This commit is contained in:
parent
8b4c1118f5
commit
6a17cbcfc5
5 changed files with 18 additions and 16 deletions
|
|
@ -0,0 +1 @@
|
|||
class=se.scalablesolutions.akka.camel.component.ActiveObjectComponent
|
||||
|
|
@ -94,14 +94,14 @@ trait CamelContextLifecycle extends Logging {
|
|||
* caching they can do so after this method returned and prior to calling start.
|
||||
* This method also registers a new
|
||||
* {@link se.scalablesolutions.akka.camel.component.ActiveObjectComponent} at
|
||||
* <code>context</code> under the name actobj.
|
||||
* <code>context</code> under a name defined by ActiveObjectComponent.InternalSchema.
|
||||
*/
|
||||
def init(context: CamelContext) {
|
||||
this.activeObjectComponent = new ActiveObjectComponent
|
||||
this.activeObjectRegistry = activeObjectComponent.activeObjectRegistry
|
||||
this.context = context
|
||||
this.context.setStreamCaching(true)
|
||||
this.context.addComponent(ActiveObjectComponent.DefaultSchema, activeObjectComponent)
|
||||
this.context.addComponent(ActiveObjectComponent.InternalSchema, activeObjectComponent)
|
||||
this.template = context.createProducerTemplate
|
||||
_initialized = true
|
||||
log.info("Camel context initialized")
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ private[camel] class ConsumerActorRoute(endpointUri: String, id: String, uuid: B
|
|||
* @author Martin Krasser
|
||||
*/
|
||||
private[camel] class ConsumerMethodRoute(val endpointUri: String, id: String, method: String) extends ConsumerRoute(endpointUri, id) {
|
||||
protected override def targetUri = "%s:%s?method=%s" format (ActiveObjectComponent.DefaultSchema, id, method)
|
||||
protected override def targetUri = "%s:%s?method=%s" format (ActiveObjectComponent.InternalSchema, id, method)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,14 +16,13 @@ object ActiveObjectComponent {
|
|||
/**
|
||||
* Default schema name for active object endpoint URIs.
|
||||
*/
|
||||
val DefaultSchema = "actobj"
|
||||
val InternalSchema = "active-object-internal"
|
||||
}
|
||||
|
||||
/**
|
||||
* Camel component for exchanging messages with active objects. This component
|
||||
* requires that active objects are added to <code>activeObjectRegistry</code>
|
||||
* before creating routes that access these objects. The registry key is the bean
|
||||
* name of the active object used in the endpoint URI.
|
||||
* tries to obtain the active object from the <code>activeObjectRegistry</code>
|
||||
* first. If it's not there it tries to obtain it from the CamelContext's registry.
|
||||
*
|
||||
* @see org.apache.camel.component.bean.BeanComponent
|
||||
*
|
||||
|
|
@ -69,8 +68,10 @@ class ActiveObjectHolder(activeObjectRegistry: Map[String, AnyRef], context: Cam
|
|||
/**
|
||||
* Obtains an active object from <code>activeObjectRegistry</code>.
|
||||
*/
|
||||
override def getBean: AnyRef =
|
||||
activeObjectRegistry.get(getName)
|
||||
override def getBean: AnyRef = {
|
||||
val bean = activeObjectRegistry.get(getName)
|
||||
if (bean eq null) super.getBean else bean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,27 +28,27 @@ class ActiveObjectComponentFeatureTest extends FeatureSpec with BeforeAndAfterAl
|
|||
}
|
||||
|
||||
feature("Communicate with an active object from a Camel application using active object endpoint URIs") {
|
||||
import ActiveObjectComponent.DefaultSchema
|
||||
import ActiveObjectComponent.InternalSchema
|
||||
import CamelContextManager.template
|
||||
import ExchangePattern._
|
||||
|
||||
scenario("in-out exchange with proxy created from interface and method returning String") {
|
||||
val result = template.requestBodyAndHeader("%s:intf?method=m2" format DefaultSchema, "x", "test", "y")
|
||||
val result = template.requestBodyAndHeader("%s:intf?method=m2" format InternalSchema, "x", "test", "y")
|
||||
assert(result === "m2impl: x y")
|
||||
}
|
||||
|
||||
scenario("in-out exchange with proxy created from class and method returning String") {
|
||||
val result = template.requestBodyAndHeader("%s:base?method=m2" format DefaultSchema, "x", "test", "y")
|
||||
val result = template.requestBodyAndHeader("%s:base?method=m2" format InternalSchema, "x", "test", "y")
|
||||
assert(result === "m2base: x y")
|
||||
}
|
||||
|
||||
scenario("in-out exchange with proxy created from class and method returning void") {
|
||||
val result = template.requestBodyAndHeader("%s:base?method=m5" format DefaultSchema, "x", "test", "y")
|
||||
val result = template.requestBodyAndHeader("%s:base?method=m5" format InternalSchema, "x", "test", "y")
|
||||
assert(result === "x") // returns initial body
|
||||
}
|
||||
|
||||
scenario("in-only exchange with proxy created from class and method returning String") {
|
||||
val result = template.send("%s:base?method=m2" format DefaultSchema, InOnly, new Processor {
|
||||
val result = template.send("%s:base?method=m2" format InternalSchema, InOnly, new Processor {
|
||||
def process(exchange: Exchange) = {
|
||||
exchange.getIn.setBody("x")
|
||||
exchange.getIn.setHeader("test", "y")
|
||||
|
|
@ -60,7 +60,7 @@ class ActiveObjectComponentFeatureTest extends FeatureSpec with BeforeAndAfterAl
|
|||
}
|
||||
|
||||
scenario("in-only exchange with proxy created from class and method returning void") {
|
||||
val result = template.send("%s:base?method=m5" format DefaultSchema, InOnly, new Processor {
|
||||
val result = template.send("%s:base?method=m5" format InternalSchema, InOnly, new Processor {
|
||||
def process(exchange: Exchange) = {
|
||||
exchange.getIn.setBody("x")
|
||||
exchange.getIn.setHeader("test", "y")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue