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 @@ -24,7 +24,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
Expand Down Expand Up @@ -185,7 +184,7 @@ public void execute(Runnable command) {
private boolean shutdownAggregateExecutorService;
private final long timeout;
private final int cacheSize;
private final ConcurrentMap<Processor, Processor> errorHandlers;
private final Map<Processor, Processor> errorHandlers;
private final boolean shareUnitOfWork;

public MulticastProcessor(CamelContext camelContext, Route route, Collection<Processor> processors) {
Expand All @@ -196,7 +195,7 @@ public MulticastProcessor(CamelContext camelContext, Route route, Collection<Pro
AggregationStrategy aggregationStrategy) {
this(camelContext, route, processors, aggregationStrategy, false, null,
false, false, false, 0, null,
false, false, CamelContextHelper.getMaximumCachePoolSize(camelContext));
false, false, 0);
}

public MulticastProcessor(CamelContext camelContext, Route route, Collection<Processor> processors,
Expand Down Expand Up @@ -225,9 +224,9 @@ public MulticastProcessor(CamelContext camelContext, Route route, Collection<Pro
this.parallelAggregate = parallelAggregate;
this.processorExchangeFactory = camelContext.getCamelContextExtension()
.getProcessorExchangeFactory().newProcessorExchangeFactory(this);
this.cacheSize = cacheSize;
if (cacheSize >= 0) {
this.errorHandlers = (ConcurrentMap) LRUCacheFactory.newLRUCache(cacheSize);
this.cacheSize = cacheSize == 0 ? CamelContextHelper.getMaximumCachePoolSize(camelContext) : cacheSize;
if (this.cacheSize > 0) {
this.errorHandlers = LRUCacheFactory.newLRUCache(this.cacheSize);
} else {
// no cache
this.errorHandlers = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ void ensureEvictionOrdering() {
assertTrue(consumed.contains("Two"));
}

@ParameterizedTest
@ValueSource(ints = { 0, -1 })
void validateCacheSize(int maximumCacheSize) {
assertThrows(IllegalArgumentException.class, () -> new SimpleLRUCache<>(16, maximumCacheSize, x -> {
}));
}

@ParameterizedTest
@ValueSource(ints = { 1, 2, 5, 10, 20, 50, 100, 1_000 })
void concurrentPut(int maximumCacheSize) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class SimpleLRUCache<K, V> extends ConcurrentHashMap<K, V> {

public SimpleLRUCache(int initialCapacity, int maximumCacheSize, Consumer<V> evicted) {
super(initialCapacity, DEFAULT_LOAD_FACTOR);
if (maximumCacheSize <= 0) {
throw new IllegalArgumentException("The maximum cache size must be greater than 0");
}
this.maximumCacheSize = maximumCacheSize;
this.evict = Objects.requireNonNull(evicted);
}
Expand Down