You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jiří Novák <ho...@centrum.cz> on 2020/02/29 12:26:20 UTC

DefaultHttpRegistry thread safety

Hi guys,
have you ever considered making DefaultHttpRegistry thread safe?

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 nits DefaultHttpRegistry in it's init method. Seems to me like a lot of ceremony to have thread safe engine. Am I missing something?
 
Thanks
 
Jiri