lifecycle of components

2012-10-02 Thread Tim Dudgeon
Are there any tricks or patterns to use when it comes to needing to 
manage the lifecyle of components used in Camel routes.
For instance if I write a custom Processor that creates something like a 
PreparedStatement how can I make sure its is close()'d when the 
CamelContext shuts down.


Thanks
Tim


Re: lifecycle of components

2012-10-02 Thread Claus Ibsen
On Tue, Oct 2, 2012 at 3:38 PM, Tim Dudgeon  wrote:
> Are there any tricks or patterns to use when it comes to needing to manage
> the lifecyle of components used in Camel routes.
> For instance if I write a custom Processor that creates something like a
> PreparedStatement how can I make sure its is close()'d when the CamelContext
> shuts down.
>

See
http://camel.apache.org/lifecycle.html

You can implement the Service interface, or extend ServiceSupport.
Then you have callbacks when its started/stopped etc.

> Thanks
> Tim



-- 
Claus Ibsen
-
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen


Re: lifecycle of components

2012-10-04 Thread Tim Dudgeon

Thanks, Got it working with a Processor.
start() seems to be called twice. Is this expected?

Is it possible to use this for beans? It seems not?
e.g. if a route has this
.bean(new MyBean(), 'foo')
and MyBean implements Service then the start() method is not called. So 
using a Processor is the only option?


Tim


On 02/10/2012 15:03, Claus Ibsen wrote:

On Tue, Oct 2, 2012 at 3:38 PM, Tim Dudgeon  wrote:

Are there any tricks or patterns to use when it comes to needing to manage
the lifecyle of components used in Camel routes.
For instance if I write a custom Processor that creates something like a
PreparedStatement how can I make sure its is close()'d when the CamelContext
shuts down.


See
http://camel.apache.org/lifecycle.html

You can implement the Service interface, or extend ServiceSupport.
Then you have callbacks when its started/stopped etc.


Thanks
Tim







Re: lifecycle of components

2012-10-05 Thread Claus Ibsen
On Thu, Oct 4, 2012 at 12:56 PM, Tim Dudgeon  wrote:
> Thanks, Got it working with a Processor.
> start() seems to be called twice. Is this expected?
>

You can extend ServiceSupport then it keeps track of its state. Then
use the doStart / doStop methods.

> Is it possible to use this for beans? It seems not?
> e.g. if a route has this
> .bean(new MyBean(), 'foo')
> and MyBean implements Service then the start() method is not called. So
> using a Processor is the only option?
>

We could look into adding support for that since you are implementing
a Camel interface, then invoking those callbacks would be expected.
Fell free to create a JIRA ticket.

> Tim
>
>
>
> On 02/10/2012 15:03, Claus Ibsen wrote:
>>
>> On Tue, Oct 2, 2012 at 3:38 PM, Tim Dudgeon  wrote:
>>>
>>> Are there any tricks or patterns to use when it comes to needing to
>>> manage
>>> the lifecyle of components used in Camel routes.
>>> For instance if I write a custom Processor that creates something like a
>>> PreparedStatement how can I make sure its is close()'d when the
>>> CamelContext
>>> shuts down.
>>>
>> See
>> http://camel.apache.org/lifecycle.html
>>
>> You can implement the Service interface, or extend ServiceSupport.
>> Then you have callbacks when its started/stopped etc.
>>
>>> Thanks
>>> Tim
>>
>>
>>
>



-- 
Claus Ibsen
-
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen


Re: lifecycle of components

2012-10-08 Thread Claus Ibsen
On Fri, Oct 5, 2012 at 4:23 PM, Claus Ibsen  wrote:
> On Thu, Oct 4, 2012 at 12:56 PM, Tim Dudgeon  wrote:
>> Thanks, Got it working with a Processor.
>> start() seems to be called twice. Is this expected?
>>
>
> You can extend ServiceSupport then it keeps track of its state. Then
> use the doStart / doStop methods.
>
>> Is it possible to use this for beans? It seems not?
>> e.g. if a route has this
>> .bean(new MyBean(), 'foo')
>> and MyBean implements Service then the start() method is not called. So
>> using a Processor is the only option?
>>
>
> We could look into adding support for that since you are implementing
> a Camel interface, then invoking those callbacks would be expected.
> Fell free to create a JIRA ticket.
>

I logged a ticket
https://issues.apache.org/jira/browse/CAMEL-5690

>> Tim
>>
>>
>>
>> On 02/10/2012 15:03, Claus Ibsen wrote:
>>>
>>> On Tue, Oct 2, 2012 at 3:38 PM, Tim Dudgeon  wrote:

 Are there any tricks or patterns to use when it comes to needing to
 manage
 the lifecyle of components used in Camel routes.
 For instance if I write a custom Processor that creates something like a
 PreparedStatement how can I make sure its is close()'d when the
 CamelContext
 shuts down.

>>> See
>>> http://camel.apache.org/lifecycle.html
>>>
>>> You can implement the Service interface, or extend ServiceSupport.
>>> Then you have callbacks when its started/stopped etc.
>>>
 Thanks
 Tim
>>>
>>>
>>>
>>
>
>
>
> --
> Claus Ibsen
> -
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cib...@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen



-- 
Claus Ibsen
-
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen