FAQ
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.

Search Discussions

  • Claus Ibsen at Mar 26, 2015 at 8:19 am
    What version of Camel do you use?

    On Thu, Mar 26, 2015 at 8:40 AM, Atanas Shindov
    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/
  • Atanas Shindov at Mar 26, 2015 at 8:22 am
    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 at Mar 26, 2015 at 8:26 am
    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
    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/
  • Atanas Shindov at Mar 26, 2015 at 8:31 am
    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.
  • Atanas Shindov at Mar 26, 2015 at 11:42 am
    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 at Mar 26, 2015 at 8:31 pm
    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
    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 at Mar 26, 2015 at 9:28 pm
    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 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
    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 at Mar 27, 2015 at 11:49 am
    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 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 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
    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/
  • Atanas Shindov at Mar 27, 2015 at 3:10 pm
    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.
  • Atanas Shindov at Apr 28, 2015 at 3:03 pm
    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 at Apr 28, 2015 at 6:02 pm
    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
    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/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedMar 26, '15 at 7:40a
activeApr 28, '15 at 6:02p
posts12
users2
websitecamel.apache.org

2 users in discussion

Atanas Shindov: 6 posts Claus Ibsen: 6 posts

People

Translate

site design / logo © 2021 Grokbase