Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ Enriches a message with data from a secondary resource
<xs:element name="errorHandler" nillable="true" type="xs:anyType">
<xs:annotation>
<xs:documentation xml:lang="en"><![CDATA[
Camel error handling.
Error handler settings
]]></xs:documentation>
</xs:annotation>
</xs:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.camel.impl.engine;

import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -40,7 +39,7 @@
* Base implementation for {@link org.apache.camel.spi.EndpointRegistry},
* {@link org.apache.camel.spi.TransformerRegistry}, and {@link org.apache.camel.spi.ValidatorRegistry}.
*/
public class AbstractDynamicRegistry<K, V> extends AbstractMap<K, V> implements StaticService {
public class AbstractDynamicRegistry<K, V> extends ConcurrentHashMap<K, V> implements StaticService {
Comment thread
orpiske marked this conversation as resolved.

protected final CamelContext context;
protected final RouteController routeController;
Expand Down Expand Up @@ -210,6 +209,11 @@ public Collection<V> getReadOnlyValues() {
return Collections.unmodifiableCollection(answer);
}

@Override
public Collection<V> values() {
return Collections.unmodifiableCollection(super.values());
}

public Map<String, V> getReadOnlyMap() {
if (isEmpty()) {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
*/
package org.apache.camel.impl;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.ServiceStatus;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.engine.DefaultEndpointRegistry;
import org.apache.camel.impl.engine.SimpleCamelContext;
import org.apache.camel.spi.EndpointRegistry;
import org.apache.camel.support.NormalizedUri;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -68,4 +76,50 @@ public void configure() throws Exception {
assertTrue(reg.isStatic("file:error"));
}

//Testing the issue https://issues.apache.org/jira/browse/CAMEL-19295
@Test
public void testConcurrency() throws InterruptedException {

SimpleCamelContext context = new SimpleCamelContext();
context.start();

ProducerTemplate producerTemplate = context.createProducerTemplate();
EndpointRegistry<NormalizedUri> endpointRegistry = context.getEndpointRegistry();

int nThreads = 4;
ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
int iterations = 500;

for (int j = 0; j < iterations; j++) {
CountDownLatch allThreadCompletionSemaphore = new CountDownLatch(nThreads);
for (int i = 0; i < nThreads; i++) {

executorService.submit(() -> {

producerTemplate.requestBody("controlbus:route?routeId=route1&action=ACTION_STATUS&loggingLevel=off", null,
ServiceStatus.class);
producerTemplate.requestBody("controlbus:route?routeId=route2&action=ACTION_STATUS&loggingLevel=off", null,
ServiceStatus.class);
producerTemplate.requestBody("controlbus:route?routeId=route3&action=ACTION_STATUS&loggingLevel=off", null,
ServiceStatus.class);
producerTemplate.requestBody("controlbus:route?routeId=route4&action=ACTION_STATUS&loggingLevel=off", null,
ServiceStatus.class);
producerTemplate.requestBody("controlbus:route?routeId=route5&action=ACTION_STATUS&loggingLevel=off", null,
ServiceStatus.class);

allThreadCompletionSemaphore.countDown();

});
Comment thread
orpiske marked this conversation as resolved.
}

allThreadCompletionSemaphore.await();

assertTrue(endpointRegistry.values().toArray() != null);

}

executorService.shutdown();

}

}