You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Brad Johnson <br...@mediadriver.com> on 2016/08/08 01:30:54 UTC

Verify understanding...

Just wanted to verify that my understanding is correct here.  Since I'm
switching from XML to Java DSL I want to verify that when I do something
like this in the configure() method:

.filter().method(POValidator.class)
.bean(POEnricher.class)

It is only instantiating that once.  It isn't creating a new bean every
time the route is invoked.  Since I'm used to injecting these from XML and
not making static references to the classes like this I want to make sure
these are the equivalent of a bean being instantiated in a Spring or
Blueprint XML file and then injected into the the route in a <camelContext>
and not a request scoped bean.

Brad

Re: Verify understanding...

Posted by Brad Johnson <br...@mediadriver.com>.
That's what I thought but wasn't sure.  In the Blueprint I'd normally
create those outside the camel context and then reference them from the
route and that makes it fairly obvious what is happening. I'd assumed the
Java RouteBuilders was only getting called once at start up and then the
classes directly referenced were getting instantiated but did want to
verify.

Which brings an interesting question to my mind.  If I'm switching to CDI
and then use the MyFoo.class in my RouteBuilder is that MyFoo.class going
to be instantiated at that time or will that be already instantiated by
Weld?  I suppose some of that depends on the MyFoo class itself. If it has
an @Named it would likely be pre-created but I  noticed that the
specification for CDI discouraged the use of @Named and suggests it only be
used for backward compatibility.

On Thu, Aug 11, 2016 at 12:01 PM, Joseph Kampf <jo...@gmail.com>
wrote:

> The key thing to remember is the Java DSL code is not executed each time
> the route is called, it is called once to create the route.
>
> Joe
>
>
>
>
>
> On 8/8/16, 12:59 PM, "Brad Johnson" <br...@mediadriver.com> wrote:
>
> >That's what it looked like to me as well.  It calls to a delegate and then
> >makes a few other method calls.  But as far as I know the route
> >configuration is only called once and that is when that bean should get
> >instantiated.  I think.
> >
> >It's funny how very different this feels since I've been working in the
> XML
> >so long.  Sort of like learning to do everything with my left hand. But I
> >think in the end I'll be better off especially when Fuse 6.3 hits the
> >streets and a lot of the configuration goes away and convention takes
> over.
> >
> >On Mon, Aug 8, 2016 at 11:10 AM, Matt Sicker <bo...@gmail.com> wrote:
> >
> >> When I last looked at the code, doing that creates a new BeanProducer
> that
> >> caches the bean. I might be misremembering the class names, but I do
> >> remember beans being cached when used by class reference.
> >>
> >> On 7 August 2016 at 20:30, Brad Johnson <br...@mediadriver.com>
> >> wrote:
> >>
> >> > Just wanted to verify that my understanding is correct here.  Since
> I'm
> >> > switching from XML to Java DSL I want to verify that when I do
> something
> >> > like this in the configure() method:
> >> >
> >> > .filter().method(POValidator.class)
> >> > .bean(POEnricher.class)
> >> >
> >> > It is only instantiating that once.  It isn't creating a new bean
> every
> >> > time the route is invoked.  Since I'm used to injecting these from XML
> >> and
> >> > not making static references to the classes like this I want to make
> sure
> >> > these are the equivalent of a bean being instantiated in a Spring or
> >> > Blueprint XML file and then injected into the the route in a
> >> <camelContext>
> >> > and not a request scoped bean.
> >> >
> >> > Brad
> >> >
> >>
> >>
> >>
> >> --
> >> Matt Sicker <bo...@gmail.com>
> >>
>
>

Re: Verify understanding...

Posted by Joseph Kampf <jo...@gmail.com>.
The key thing to remember is the Java DSL code is not executed each time the route is called, it is called once to create the route.

Joe





On 8/8/16, 12:59 PM, "Brad Johnson" <br...@mediadriver.com> wrote:

>That's what it looked like to me as well.  It calls to a delegate and then
>makes a few other method calls.  But as far as I know the route
>configuration is only called once and that is when that bean should get
>instantiated.  I think.
>
>It's funny how very different this feels since I've been working in the XML
>so long.  Sort of like learning to do everything with my left hand. But I
>think in the end I'll be better off especially when Fuse 6.3 hits the
>streets and a lot of the configuration goes away and convention takes over.
>
>On Mon, Aug 8, 2016 at 11:10 AM, Matt Sicker <bo...@gmail.com> wrote:
>
>> When I last looked at the code, doing that creates a new BeanProducer that
>> caches the bean. I might be misremembering the class names, but I do
>> remember beans being cached when used by class reference.
>>
>> On 7 August 2016 at 20:30, Brad Johnson <br...@mediadriver.com>
>> wrote:
>>
>> > Just wanted to verify that my understanding is correct here.  Since I'm
>> > switching from XML to Java DSL I want to verify that when I do something
>> > like this in the configure() method:
>> >
>> > .filter().method(POValidator.class)
>> > .bean(POEnricher.class)
>> >
>> > It is only instantiating that once.  It isn't creating a new bean every
>> > time the route is invoked.  Since I'm used to injecting these from XML
>> and
>> > not making static references to the classes like this I want to make sure
>> > these are the equivalent of a bean being instantiated in a Spring or
>> > Blueprint XML file and then injected into the the route in a
>> <camelContext>
>> > and not a request scoped bean.
>> >
>> > Brad
>> >
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>


Re: Verify understanding...

Posted by Brad Johnson <br...@mediadriver.com>.
That's what it looked like to me as well.  It calls to a delegate and then
makes a few other method calls.  But as far as I know the route
configuration is only called once and that is when that bean should get
instantiated.  I think.

It's funny how very different this feels since I've been working in the XML
so long.  Sort of like learning to do everything with my left hand. But I
think in the end I'll be better off especially when Fuse 6.3 hits the
streets and a lot of the configuration goes away and convention takes over.

On Mon, Aug 8, 2016 at 11:10 AM, Matt Sicker <bo...@gmail.com> wrote:

> When I last looked at the code, doing that creates a new BeanProducer that
> caches the bean. I might be misremembering the class names, but I do
> remember beans being cached when used by class reference.
>
> On 7 August 2016 at 20:30, Brad Johnson <br...@mediadriver.com>
> wrote:
>
> > Just wanted to verify that my understanding is correct here.  Since I'm
> > switching from XML to Java DSL I want to verify that when I do something
> > like this in the configure() method:
> >
> > .filter().method(POValidator.class)
> > .bean(POEnricher.class)
> >
> > It is only instantiating that once.  It isn't creating a new bean every
> > time the route is invoked.  Since I'm used to injecting these from XML
> and
> > not making static references to the classes like this I want to make sure
> > these are the equivalent of a bean being instantiated in a Spring or
> > Blueprint XML file and then injected into the the route in a
> <camelContext>
> > and not a request scoped bean.
> >
> > Brad
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: Verify understanding...

Posted by Matt Sicker <bo...@gmail.com>.
When I last looked at the code, doing that creates a new BeanProducer that
caches the bean. I might be misremembering the class names, but I do
remember beans being cached when used by class reference.

On 7 August 2016 at 20:30, Brad Johnson <br...@mediadriver.com>
wrote:

> Just wanted to verify that my understanding is correct here.  Since I'm
> switching from XML to Java DSL I want to verify that when I do something
> like this in the configure() method:
>
> .filter().method(POValidator.class)
> .bean(POEnricher.class)
>
> It is only instantiating that once.  It isn't creating a new bean every
> time the route is invoked.  Since I'm used to injecting these from XML and
> not making static references to the classes like this I want to make sure
> these are the equivalent of a bean being instantiated in a Spring or
> Blueprint XML file and then injected into the the route in a <camelContext>
> and not a request scoped bean.
>
> Brad
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Verify understanding...

Posted by Claus Ibsen <cl...@gmail.com>.
Yes they are created only once.



On Mon, Aug 8, 2016 at 3:30 AM, Brad Johnson
<br...@mediadriver.com> wrote:
> Just wanted to verify that my understanding is correct here.  Since I'm
> switching from XML to Java DSL I want to verify that when I do something
> like this in the configure() method:
>
> .filter().method(POValidator.class)
> .bean(POEnricher.class)
>
> It is only instantiating that once.  It isn't creating a new bean every
> time the route is invoked.  Since I'm used to injecting these from XML and
> not making static references to the classes like this I want to make sure
> these are the equivalent of a bean being instantiated in a Spring or
> Blueprint XML file and then injected into the the route in a <camelContext>
> and not a request scoped bean.
>
> Brad



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2