POJO Lifecycle within Camel? (Stuck trying to make my own Dynamic Router)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

POJO Lifecycle within Camel? (Stuck trying to make my own Dynamic Router)

Conrad Pilloud
I want to implement a variation on the EIP pattern Dynamic Router (DR) (and sadly don't have time to wait for CAMEL-8 ).  

The idea is to allow an administrator-type user to add/subtract endpoints and routes at run-time.  Like DR pattern, the idea is to have a dynamic rulebase that this adminstrator person manipulates/maintains through some UI.  I'm envisioning some kind of DR POJO that runs asynchronously in Camel, awaiting requests from the administrator person to affect the rulebase and then manipulating the CamelContext to achieve the desired new configuration.

The problem I'm currently stuck on is that I don't really understand the Camel Architecture well enough to manage the lifecycle of my POJO and pass it control to do its thing.  I can get it instantiated as a CamelContextAware implementer via Spring, but that's about as far as I've gotten.

Cheers
Conrad
Reply | Threaded
Open this post in threaded view
|

Re: POJO Lifecycle within Camel? (Stuck trying to make my own Dynamic Router)

jstrachan
2008/8/29 Conrad Pilloud <[hidden email]>:

>
> I want to implement a variation on the EIP pattern Dynamic Router (DR) (and
> sadly don't have time to wait for
> https://issues.apache.org/activemq/browse/CAMEL-8 CAMEL-8  :-().
>
> The idea is to allow an administrator-type user to add/subtract endpoints
> and routes at run-time.  Like DR pattern, the idea is to have a dynamic
> rulebase that this adminstrator person manipulates/maintains through some
> UI.  I'm envisioning some kind of DR POJO that runs asynchronously in Camel,
> awaiting requests from the administrator person to affect the rulebase and
> then manipulating the CamelContext to achieve the desired new configuration.
>
> The problem I'm currently stuck on is that I don't really understand the
> Camel Architecture well enough to manage the lifecycle of my POJO and pass
> it control to do its thing.  I can get it instantiated as a
> CamelContextAware implementer via Spring, but that's about as far as I've
> gotten.

Its kinda up to you; when folks use Spring then we delegate to Spring
to manage lifecycles. So you could just rely on Spring
ApplicationContexts to denote the lifecycle of your beans.

--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: POJO Lifecycle within Camel? (Stuck trying to make my own Dynamic Router)

Conrad Pilloud
In reply to this post by Conrad Pilloud
I had the big "A ha!" moment over the weekend as I was driving across Nebraska.  My Dynamic Router (DR) POJO only needs to "be alive" when responding to requests from the administrator person; Elements within Camel "are alive" when processing a message.  So... just like the DR EIP pattern suggests, I'll implement a Control Channel as a static Camel Route which receives requests from the administrator and then creates/destroys/manages a separate set of dynamic Camel Routes.  I just need my POJO to implement Processor IF and set up the static route to pass the administrative requests to it.
Cheers
Conrad


Conrad Pilloud wrote
I want to implement a variation on the EIP pattern Dynamic Router (DR) (and sadly don't have time to wait for CAMEL-8 ).  

The idea is to allow an administrator-type user to add/subtract endpoints and routes at run-time.  Like DR pattern, the idea is to have a dynamic rulebase that this adminstrator person manipulates/maintains through some UI.  I'm envisioning some kind of DR POJO that runs asynchronously in Camel, awaiting requests from the administrator person to affect the rulebase and then manipulating the CamelContext to achieve the desired new configuration.

The problem I'm currently stuck on is that I don't really understand the Camel Architecture well enough to manage the lifecycle of my POJO and pass it control to do its thing.  I can get it instantiated as a CamelContextAware implementer via Spring, but that's about as far as I've gotten.

Cheers
Conrad
Reply | Threaded
Open this post in threaded view
|

Re: POJO Lifecycle within Camel? (Stuck trying to make my own Dynamic Router)

jstrachan
2008/9/2 Conrad Pilloud <[hidden email]>:

>
> I had the big "A ha!" moment over the weekend as I was driving across
> Nebraska.  My Dynamic Router (DR) POJO only needs to "be alive" when
> responding to requests from the administrator person; Elements within Camel
> "are alive" when processing a message.  So... just like the DR EIP pattern
> suggests, I'll implement a Control Channel as a static Camel Route which
> receives requests from the administrator and then creates/destroys/manages a
> separate set of dynamic Camel Routes.  I just need my POJO to implement
> Processor IF and set up the static route to pass the administrative requests
> to it.

BTW you could write your DR POJO without implementing Processor and
just use the bean binding to inject message headers & body objects
into your method calls...
http://activemq.apache.org/camel/bean-integration.html

also if you use

from("...").bean(MyClass.class);

then Camel will use Spring/Guice to instantiate and inject your bean -
which can then be either a singleton or per request bean; using
Spring's scopes etc.

--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com