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.
|
* caching they can do so after this method returned and prior to calling start.
|
||||||
* This method also registers a new
|
* This method also registers a new
|
||||||
* {@link se.scalablesolutions.akka.camel.component.ActiveObjectComponent} at
|
* {@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) {
|
def init(context: CamelContext) {
|
||||||
this.activeObjectComponent = new ActiveObjectComponent
|
this.activeObjectComponent = new ActiveObjectComponent
|
||||||
this.activeObjectRegistry = activeObjectComponent.activeObjectRegistry
|
this.activeObjectRegistry = activeObjectComponent.activeObjectRegistry
|
||||||
this.context = context
|
this.context = context
|
||||||
this.context.setStreamCaching(true)
|
this.context.setStreamCaching(true)
|
||||||
this.context.addComponent(ActiveObjectComponent.DefaultSchema, activeObjectComponent)
|
this.context.addComponent(ActiveObjectComponent.InternalSchema, activeObjectComponent)
|
||||||
this.template = context.createProducerTemplate
|
this.template = context.createProducerTemplate
|
||||||
_initialized = true
|
_initialized = true
|
||||||
log.info("Camel context initialized")
|
log.info("Camel context initialized")
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ private[camel] class ConsumerActorRoute(endpointUri: String, id: String, uuid: B
|
||||||
* @author Martin Krasser
|
* @author Martin Krasser
|
||||||
*/
|
*/
|
||||||
private[camel] class ConsumerMethodRoute(val endpointUri: String, id: String, method: String) extends ConsumerRoute(endpointUri, id) {
|
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,15 +16,14 @@ object ActiveObjectComponent {
|
||||||
/**
|
/**
|
||||||
* Default schema name for active object endpoint URIs.
|
* 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
|
* Camel component for exchanging messages with active objects. This component
|
||||||
* requires that active objects are added to <code>activeObjectRegistry</code>
|
* tries to obtain the active object from the <code>activeObjectRegistry</code>
|
||||||
* before creating routes that access these objects. The registry key is the bean
|
* first. If it's not there it tries to obtain it from the CamelContext's registry.
|
||||||
* name of the active object used in the endpoint URI.
|
*
|
||||||
*
|
|
||||||
* @see org.apache.camel.component.bean.BeanComponent
|
* @see org.apache.camel.component.bean.BeanComponent
|
||||||
*
|
*
|
||||||
* @author Martin Krasser
|
* @author Martin Krasser
|
||||||
|
|
@ -69,8 +68,10 @@ class ActiveObjectHolder(activeObjectRegistry: Map[String, AnyRef], context: Cam
|
||||||
/**
|
/**
|
||||||
* Obtains an active object from <code>activeObjectRegistry</code>.
|
* Obtains an active object from <code>activeObjectRegistry</code>.
|
||||||
*/
|
*/
|
||||||
override def getBean: AnyRef =
|
override def getBean: AnyRef = {
|
||||||
activeObjectRegistry.get(getName)
|
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") {
|
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 CamelContextManager.template
|
||||||
import ExchangePattern._
|
import ExchangePattern._
|
||||||
|
|
||||||
scenario("in-out exchange with proxy created from interface and method returning String") {
|
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")
|
assert(result === "m2impl: x y")
|
||||||
}
|
}
|
||||||
|
|
||||||
scenario("in-out exchange with proxy created from class and method returning String") {
|
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")
|
assert(result === "m2base: x y")
|
||||||
}
|
}
|
||||||
|
|
||||||
scenario("in-out exchange with proxy created from class and method returning void") {
|
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
|
assert(result === "x") // returns initial body
|
||||||
}
|
}
|
||||||
|
|
||||||
scenario("in-only exchange with proxy created from class and method returning String") {
|
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) = {
|
def process(exchange: Exchange) = {
|
||||||
exchange.getIn.setBody("x")
|
exchange.getIn.setBody("x")
|
||||||
exchange.getIn.setHeader("test", "y")
|
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") {
|
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) = {
|
def process(exchange: Exchange) = {
|
||||||
exchange.getIn.setBody("x")
|
exchange.getIn.setBody("x")
|
||||||
exchange.getIn.setHeader("test", "y")
|
exchange.getIn.setHeader("test", "y")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue