Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-14639

DefaultHttpRegistry thread safety

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.23.1
    • Fix Version/s: 3.2.0, 2.25.1
    • Component/s: camel-servlet
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      Currently DefaultHttpRegistry uses common HashSets for storing
      HttpConsumers and CamelServlets. So when you are trying to register more
      consumers in paralel it can lead to missing consumer in hashset due to its
      nature. Another case is when you are registering consumers and servlets in
      paralel. This case can lead to ConcurrentModificationException.

       

      private final Set<HttpConsumer> consumers;
      private final Set<CamelServlet> providers;
      
      public DefaultHttpRegistry() {
          consumers = new HashSet<>();
          providers = new HashSet<>();
      }
      
      public void register(HttpConsumer consumer) {
          if (LOG.isDebugEnabled()) {
              LOG.debug("Registering consumer for path {} providers present: {}",
              consumer.getPath(), providers.size());
          }
          consumers.add(consumer);
          for (CamelServlet provider : providers) {
              provider.connect(consumer);
          }
      }
      
      public void register(CamelServlet provider) {
          if (LOG.isDebugEnabled()) {
              LOG.debug("Registering CamelServlet with name {} consumers present: {}", provider.getServletName(), consumers.size());
          }
          providers.add(provider);
          for (HttpConsumer consumer : consumers) {
              provider.connect(consumer);
          }
      }
      

      I know there's possibility to use own http registry in camel route starting
      with servlet. But you have to register it to servlet-component, then
      implement custom servlet because inits DefaultHttpRegistry in it's init
      method.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              JNk Jiri Novak
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: