You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/06/06 11:57:40 UTC
[camel] 01/03: CAMEL-13618: camel3 - Move FileWatcherReloadStrategy
out of camel-core
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 38145ab8bd1722d0d21b8733b4030e031a919174
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jun 6 13:11:32 2019 +0200
CAMEL-13618: camel3 - Move FileWatcherReloadStrategy out of camel-core
---
.../camel/impl/engine/DefaultProcessorFactory.java | 5 +++++
.../apache/camel/impl/FileWatcherReloadStrategy.java | 20 +++++++++++++++++---
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultProcessorFactory.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultProcessorFactory.java
index 69e93a0..f31e7a2 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultProcessorFactory.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultProcessorFactory.java
@@ -25,7 +25,9 @@ import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.NamedNode;
import org.apache.camel.NoFactoryAvailableException;
import org.apache.camel.Processor;
+import org.apache.camel.Producer;
import org.apache.camel.processor.SendDynamicProcessor;
+import org.apache.camel.processor.UnitOfWorkProducer;
import org.apache.camel.spi.FactoryFinder;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.RouteContext;
@@ -96,6 +98,9 @@ public class DefaultProcessorFactory implements ProcessorFactory {
if (exchangePattern != null) {
answer.setPattern(exchangePattern);
}
+ } else if ("UnitOfWorkProducer".equals(definitionName)) {
+ Producer producer = (Producer) args.get("producer");
+ return new UnitOfWorkProducer(producer);
}
return answer;
diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java b/core/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java
index 2a3fabb..e027286 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/FileWatcherReloadStrategy.java
@@ -18,14 +18,17 @@ package org.apache.camel.impl;
import java.io.File;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.camel.Component;
import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
+import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.Processor;
import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedResource;
-import org.apache.camel.processor.UnitOfWorkProducer;
import org.apache.camel.support.DefaultProducer;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.util.IOHelper;
@@ -97,11 +100,22 @@ public class FileWatcherReloadStrategy extends ReloadStrategySupport {
if (dir.exists() && dir.isDirectory()) {
log.info("Starting ReloadStrategy to watch directory: {}", dir);
+ // must have camel-file on classpath
+ Component file = getCamelContext().getComponent("file", true);
+ if (file == null) {
+ throw new IllegalArgumentException("FileWatcherReloadStrategy requires camel-file JAR to be on the classpath");
+ }
+
// only include xml files
endpoint = getCamelContext().getEndpoint("file:" + dir + "?delay=" + delay + "&recursive=" + isRecursive
+ "&include=.*xml$&readLock=none&noop=true&idempotentKey=${file:name}-${file:modified}");
- // must wrap in unit of work
- task = new UnitOfWorkProducer(new UpdatedFileProcessor(endpoint));
+
+ // must wrap in unit of work producer
+ Map<String, Object> args = new HashMap<>(1);
+ args.put("producer", new UpdatedFileProcessor(endpoint));
+ task = getCamelContext().adapt(ExtendedCamelContext.class).getProcessorFactory()
+ .createProcessor(getCamelContext(), "UnitOfWorkProducer", args);
+
consumer = endpoint.createConsumer(task);
ServiceHelper.startService(endpoint);