You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Atanas Shindov <at...@gmail.com> on 2015/03/26 08:40:32 UTC

Route removal triggers endpoint shutdown

Hello,

I have a custom singleton endpoint which manages a resource used by all
consumers created by this endpoint. I open and close the resource in the
start() and stop() methods of the endpoint assuming that this way I would
prevent illegal states, i.e. the resource is closed, but a consumer is still
active and tries to read it.

However, I found out that Camel shutdowns an endpoint when a route is
removed which reads from the endpoint. This is a problem when there are more
than one routes reading from this endpoint as it results in the following
sequence:

[routes 1 & 2 are consuming from endpoint X]
1. route 1 is removed
- producer 1 is stopped.
- consumer 1 is stopped.
*2. endpoint X is stopped.*
3. route 2 is still active and consumer 2 tires to access the closed
resource.

A comment above the
ServiceHelper.stopAndShutdownServices(route.getEndpoint()) invocation inside
the org.apache.camel.impl.RouteService.doShutdown() method where the
shutdown happens says:

"// endpoints should only be stopped when Camel is shutting down
// see more details in the warmUp method"

However, this is not the case. Is this a bug or I'm missing something?



--
View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route removal triggers endpoint shutdown

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah if you isolate that code to your own endpoints - then yeah you
wont cause side effects in others.
And then you can do your cleanup code in the shutdown if your endpoint
needs such code.

On Tue, Apr 28, 2015 at 5:02 PM, Atanas Shindov
<at...@gmail.com> wrote:
> Hi, Claus,
>
> I saw that the "fix" won't make it into the product. Do you see any risks
> with the workaround below:
>
> // descendant of DefaultEndpoint
>
>     public void stop() throws Exception {
>         if (isSingleton() &&
> !org.apache.camel.support.ServiceSupport.class.cast(getCamelContext()).isStopping())
> {
>             return;
>         }
>
>         super.stop();
>     }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5766437.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Route removal triggers endpoint shutdown

Posted by Atanas Shindov <at...@gmail.com>.
Hi, Claus,

I saw that the "fix" won't make it into the product. Do you see any risks
with the workaround below:

// descendant of DefaultEndpoint

    public void stop() throws Exception {
        if (isSingleton() &&
!org.apache.camel.support.ServiceSupport.class.cast(getCamelContext()).isStopping())
{
            return;
        }

        super.stop();
    }



--
View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5766437.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route removal triggers endpoint shutdown

Posted by Atanas Shindov <at...@gmail.com>.
Thanks, Claus. I will go ahead and change my logic so that I keep the state
in the component.



--
View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764917.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route removal triggers endpoint shutdown

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I logged a ticket to not forget about this
https://issues.apache.org/jira/browse/CAMEL-8562

On Thu, Mar 26, 2015 at 10:26 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> But that said, we could likely take a look if we could detect if the
> route endpoint is used by other routes, and avoid shutting it down, as
> we have that logic for endpoints used within the route.
>
> You are welcome to log a JIRA ticket then we can take a stab at improving this.
>
> On Thu, Mar 26, 2015 at 9:31 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> You should favor to keep state on the component and then delegate from
>> endpoints on add/remove etc, then you can keep track of what are in
>> use and when there is no users of the resource, you can cleanup.
>>
>> This is what other camel components does, such as seda / jetty etc.
>>
>> On Thu, Mar 26, 2015 at 12:42 PM, Atanas Shindov
>> <at...@gmail.com> wrote:
>>> Hi Claus,
>>>
>>> I just checked the 2.15 code and it's the same:
>>>
>>> /// endpoints should only be stopped when Camel is shutting down
>>> // see more details in the warmUp method
>>> ServiceHelper.stopAndShutdownServices(route.getEndpoint());/
>>>
>>> Looks like you are still closing an endpoint on route removal?
>>>
>>>
>>>
>>> --
>>> View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764821.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8: http://fabric8.io/
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Route removal triggers endpoint shutdown

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

But that said, we could likely take a look if we could detect if the
route endpoint is used by other routes, and avoid shutting it down, as
we have that logic for endpoints used within the route.

You are welcome to log a JIRA ticket then we can take a stab at improving this.

On Thu, Mar 26, 2015 at 9:31 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> You should favor to keep state on the component and then delegate from
> endpoints on add/remove etc, then you can keep track of what are in
> use and when there is no users of the resource, you can cleanup.
>
> This is what other camel components does, such as seda / jetty etc.
>
> On Thu, Mar 26, 2015 at 12:42 PM, Atanas Shindov
> <at...@gmail.com> wrote:
>> Hi Claus,
>>
>> I just checked the 2.15 code and it's the same:
>>
>> /// endpoints should only be stopped when Camel is shutting down
>> // see more details in the warmUp method
>> ServiceHelper.stopAndShutdownServices(route.getEndpoint());/
>>
>> Looks like you are still closing an endpoint on route removal?
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764821.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Route removal triggers endpoint shutdown

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You should favor to keep state on the component and then delegate from
endpoints on add/remove etc, then you can keep track of what are in
use and when there is no users of the resource, you can cleanup.

This is what other camel components does, such as seda / jetty etc.

On Thu, Mar 26, 2015 at 12:42 PM, Atanas Shindov
<at...@gmail.com> wrote:
> Hi Claus,
>
> I just checked the 2.15 code and it's the same:
>
> /// endpoints should only be stopped when Camel is shutting down
> // see more details in the warmUp method
> ServiceHelper.stopAndShutdownServices(route.getEndpoint());/
>
> Looks like you are still closing an endpoint on route removal?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764821.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Route removal triggers endpoint shutdown

Posted by Atanas Shindov <at...@gmail.com>.
Hi Claus,

I just checked the 2.15 code and it's the same:

/// endpoints should only be stopped when Camel is shutting down
// see more details in the warmUp method
ServiceHelper.stopAndShutdownServices(route.getEndpoint());/

Looks like you are still closing an endpoint on route removal?



--
View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764821.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route removal triggers endpoint shutdown

Posted by Atanas Shindov <at...@gmail.com>.
I guess you are referring to this entry:

"Removing a route now also remove its static Endpoint's from the
EndpointRegistry (if those endpoints are not shared and used by other
routes). Mind that any dynamic endpoint created during routing from dynamic
EIPs such as recipient list, routing slip, dynamic router etc, are not
removed from the EndpointRegistry when the route is removed."

I will give it a try, thanks. :)



--
View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764802.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route removal triggers endpoint shutdown

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Check the release notes for 2.15 which has improvements in this area
http://camel.apache.org/camel-2150-release.html

On Thu, Mar 26, 2015 at 9:20 AM, Atanas Shindov
<at...@gmail.com> wrote:
> 2.12.1
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764800.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Route removal triggers endpoint shutdown

Posted by Atanas Shindov <at...@gmail.com>.
2.12.1



--
View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796p5764800.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Route removal triggers endpoint shutdown

Posted by Claus Ibsen <cl...@gmail.com>.
What version of Camel do you use?

On Thu, Mar 26, 2015 at 8:40 AM, Atanas Shindov
<at...@gmail.com> wrote:
> Hello,
>
> I have a custom singleton endpoint which manages a resource used by all
> consumers created by this endpoint. I open and close the resource in the
> start() and stop() methods of the endpoint assuming that this way I would
> prevent illegal states, i.e. the resource is closed, but a consumer is still
> active and tries to read it.
>
> However, I found out that Camel shutdowns an endpoint when a route is
> removed which reads from the endpoint. This is a problem when there are more
> than one routes reading from this endpoint as it results in the following
> sequence:
>
> [routes 1 & 2 are consuming from endpoint X]
> 1. route 1 is removed
> - producer 1 is stopped.
> - consumer 1 is stopped.
> *2. endpoint X is stopped.*
> 3. route 2 is still active and consumer 2 tires to access the closed
> resource.
>
> A comment above the
> ServiceHelper.stopAndShutdownServices(route.getEndpoint()) invocation inside
> the org.apache.camel.impl.RouteService.doShutdown() method where the
> shutdown happens says:
>
> "// endpoints should only be stopped when Camel is shutting down
> // see more details in the warmUp method"
>
> However, this is not the case. Is this a bug or I'm missing something?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-removal-triggers-endpoint-shutdown-tp5764796.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/