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 2013/07/17 13:39:41 UTC
[1/8] git commit: CAMEL-6510: Added unit test
Updated Branches:
refs/heads/camel-2.10.x c48f06780 -> e9f2a1f86
refs/heads/camel-2.11.x c66e94c3e -> 8bae7e645
refs/heads/master c095e270f -> 3f1f901a0
CAMEL-6510: Added unit test
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6fbf115f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6fbf115f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6fbf115f
Branch: refs/heads/master
Commit: 6fbf115fadebf966c8b24894afa3e8fddae61892
Parents: c095e27
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 11:52:53 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 11:52:53 2013 +0200
----------------------------------------------------------------------
.../AggregateStrategyServiceTest.java | 46 +++++++++++++++++
.../MyAggregationStrategyService.java | 52 ++++++++++++++++++++
2 files changed, 98 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6fbf115f/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateStrategyServiceTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateStrategyServiceTest.java b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateStrategyServiceTest.java
new file mode 100644
index 0000000..06771f2
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateStrategyServiceTest.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.aggregator;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class AggregateStrategyServiceTest extends ContextTestSupport {
+
+ public void testAggregate() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("StartedStartedABC");
+
+ template.sendBody("direct:start", "A");
+ template.sendBody("direct:start", "B");
+ template.sendBody("direct:start", "C");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .aggregate(constant(true), new MyAggregationStrategyService())
+ .completionSize(3)
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6fbf115f/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyAggregationStrategyService.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyAggregationStrategyService.java b/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyAggregationStrategyService.java
new file mode 100644
index 0000000..e1ad7cc
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyAggregationStrategyService.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.aggregator;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.support.ServiceSupport;
+
+public class MyAggregationStrategyService extends ServiceSupport implements AggregationStrategy {
+
+ private boolean started;
+
+ @Override
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ if (oldExchange == null) {
+ return newExchange;
+ }
+
+ String body = oldExchange.getIn().getBody(String.class);
+ String newBody = newExchange.getIn().getBody(String.class);
+ body = body + newBody;
+ if (started) {
+ body = "Started" + body;
+ }
+ newExchange.getIn().setBody(body);
+ return newExchange;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ started = true;
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ started = false;
+ }
+}
[6/8] git commit: CAMEL-6452: Added shutdown method to FileUtil to
allow cleaning up temp dir and shutdown hook. Thanks to Sanjay Deshmukh for
the patch
Posted by da...@apache.org.
CAMEL-6452: Added shutdown method to FileUtil to allow cleaning up temp dir and shutdown hook. Thanks to Sanjay Deshmukh for the patch
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8bae7e64
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8bae7e64
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8bae7e64
Branch: refs/heads/camel-2.11.x
Commit: 8bae7e6450658c1197324b55787a1a5b73ded3b8
Parents: 31a27b1
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 12:11:12 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 13:34:40 2013 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/util/FileUtil.java | 26 ++++++++++++++------
.../org/apache/camel/util/FileUtilTest.java | 9 +++++++
2 files changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8bae7e64/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index 39952e5..339a5da 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.util;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -31,7 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * File utilities
+ * File utilities.
*/
public final class FileUtil {
@@ -45,12 +44,11 @@ public final class FileUtil {
private static final String USER_DIR_KEY = "user.dir";
private static final File USER_DIR = new File(System.getProperty(USER_DIR_KEY));
private static File defaultTempDir;
-
-
+ private static Thread shutdownHook;
+
private FileUtil() {
// Utils method
}
-
public static File getUserDir() {
return USER_DIR;
@@ -309,17 +307,31 @@ public final class FileUtil {
defaultTempDir = f;
// create shutdown hook to remove the temp dir
- Thread hook = new Thread() {
+ shutdownHook = new Thread() {
@Override
public void run() {
removeDir(defaultTempDir);
}
};
- Runtime.getRuntime().addShutdownHook(hook);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
return defaultTempDir;
}
+ /**
+ * Shutdown and cleanup the temporary directory and removes any shutdown hooks in use.
+ */
+ public static synchronized void shutdown() {
+ if (defaultTempDir != null && defaultTempDir.exists()) {
+ removeDir(defaultTempDir);
+ }
+
+ if (shutdownHook != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdownHook);
+ shutdownHook = null;
+ }
+ }
+
private static void removeDir(File d) {
String[] list = d.list();
if (list == null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/8bae7e64/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
index 46adfdf..e9a6431 100644
--- a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
@@ -204,4 +204,13 @@ public class FileUtilTest extends TestCase {
assertTrue("A new file should be created " + file, FileUtil.createNewFile(file));
}
+ public void testShutdown() throws Exception {
+ File tmpFile = FileUtil.createTempFile(null, null);
+ File tmpDir = tmpFile.getParentFile();
+ assertTrue(tmpDir.exists());
+
+ FileUtil.shutdown();
+ assertFalse(tmpDir.exists());
+ }
+
}
[5/8] git commit: CAMEL-6505: GenericFileMessage fixed copyFrom to
copy the generic file also.
Posted by da...@apache.org.
CAMEL-6505: GenericFileMessage fixed copyFrom to copy the generic file also.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/31a27b19
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/31a27b19
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/31a27b19
Branch: refs/heads/camel-2.11.x
Commit: 31a27b19deb084a7ef5114b57968fe69308598c4
Parents: c66e94c
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 12:04:39 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 13:34:31 2013 +0200
----------------------------------------------------------------------
.../apache/camel/component/file/GenericFileMessage.java | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/31a27b19/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
index bcf1e1a..206d928 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file;
+import org.apache.camel.Message;
import org.apache.camel.impl.DefaultMessage;
/**
@@ -50,6 +51,16 @@ public class GenericFileMessage<T> extends DefaultMessage {
}
@Override
+ @SuppressWarnings("unchecked")
+ public void copyFrom(Message that) {
+ super.copyFrom(that);
+
+ if (that instanceof GenericFileMessage) {
+ setGenericFile(((GenericFileMessage) that).getGenericFile());
+ }
+ }
+
+ @Override
public String toString() {
// only output the filename as body can be big
return file != null ? file.getFileName() : null;
[7/8] git commit: CAMEL-6505: GenericFileMessage fixed copyFrom to
copy the generic file also.
Posted by da...@apache.org.
CAMEL-6505: GenericFileMessage fixed copyFrom to copy the generic file also.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7c6b566a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7c6b566a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7c6b566a
Branch: refs/heads/camel-2.10.x
Commit: 7c6b566abee9d5689e2f32a2ba1355cd9d18f06e
Parents: c48f067
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 12:04:39 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 13:34:53 2013 +0200
----------------------------------------------------------------------
.../apache/camel/component/file/GenericFileMessage.java | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7c6b566a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
index bcf1e1a..206d928 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file;
+import org.apache.camel.Message;
import org.apache.camel.impl.DefaultMessage;
/**
@@ -50,6 +51,16 @@ public class GenericFileMessage<T> extends DefaultMessage {
}
@Override
+ @SuppressWarnings("unchecked")
+ public void copyFrom(Message that) {
+ super.copyFrom(that);
+
+ if (that instanceof GenericFileMessage) {
+ setGenericFile(((GenericFileMessage) that).getGenericFile());
+ }
+ }
+
+ @Override
public String toString() {
// only output the filename as body can be big
return file != null ? file.getFileName() : null;
[3/8] git commit: CAMEL-6452: Added shutdown method to FileUtil to
allow cleaning up temp dir and shutdown hook. Thanks to Sanjay Deshmukh for
the patch
Posted by da...@apache.org.
CAMEL-6452: Added shutdown method to FileUtil to allow cleaning up temp dir and shutdown hook. Thanks to Sanjay Deshmukh for the patch
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f0180cac
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f0180cac
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f0180cac
Branch: refs/heads/master
Commit: f0180cac9e9649564e7ddad551649a452f4b225b
Parents: 1a4baee
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 12:11:12 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 12:11:12 2013 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/util/FileUtil.java | 26 ++++++++++++++------
.../org/apache/camel/util/FileUtilTest.java | 9 +++++++
2 files changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f0180cac/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index 39952e5..339a5da 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.util;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -31,7 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * File utilities
+ * File utilities.
*/
public final class FileUtil {
@@ -45,12 +44,11 @@ public final class FileUtil {
private static final String USER_DIR_KEY = "user.dir";
private static final File USER_DIR = new File(System.getProperty(USER_DIR_KEY));
private static File defaultTempDir;
-
-
+ private static Thread shutdownHook;
+
private FileUtil() {
// Utils method
}
-
public static File getUserDir() {
return USER_DIR;
@@ -309,17 +307,31 @@ public final class FileUtil {
defaultTempDir = f;
// create shutdown hook to remove the temp dir
- Thread hook = new Thread() {
+ shutdownHook = new Thread() {
@Override
public void run() {
removeDir(defaultTempDir);
}
};
- Runtime.getRuntime().addShutdownHook(hook);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
return defaultTempDir;
}
+ /**
+ * Shutdown and cleanup the temporary directory and removes any shutdown hooks in use.
+ */
+ public static synchronized void shutdown() {
+ if (defaultTempDir != null && defaultTempDir.exists()) {
+ removeDir(defaultTempDir);
+ }
+
+ if (shutdownHook != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdownHook);
+ shutdownHook = null;
+ }
+ }
+
private static void removeDir(File d) {
String[] list = d.list();
if (list == null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/f0180cac/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
index 46adfdf..e9a6431 100644
--- a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
@@ -204,4 +204,13 @@ public class FileUtilTest extends TestCase {
assertTrue("A new file should be created " + file, FileUtil.createNewFile(file));
}
+ public void testShutdown() throws Exception {
+ File tmpFile = FileUtil.createTempFile(null, null);
+ File tmpDir = tmpFile.getParentFile();
+ assertTrue(tmpDir.exists());
+
+ FileUtil.shutdown();
+ assertFalse(tmpDir.exists());
+ }
+
}
[2/8] git commit: CAMEL-6505: GenericFileMessage fixed copyFrom to
copy the generic file also.
Posted by da...@apache.org.
CAMEL-6505: GenericFileMessage fixed copyFrom to copy the generic file also.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1a4baeed
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1a4baeed
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1a4baeed
Branch: refs/heads/master
Commit: 1a4baeedfbad78a204bc43cf1b261137fea7cf96
Parents: 6fbf115
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 12:04:39 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 12:04:39 2013 +0200
----------------------------------------------------------------------
.../apache/camel/component/file/GenericFileMessage.java | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1a4baeed/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
index 161e8e3..703c832 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file;
+import org.apache.camel.Message;
import org.apache.camel.impl.DefaultMessage;
/**
@@ -50,6 +51,16 @@ public class GenericFileMessage<T> extends DefaultMessage {
}
@Override
+ @SuppressWarnings("unchecked")
+ public void copyFrom(Message that) {
+ super.copyFrom(that);
+
+ if (that instanceof GenericFileMessage) {
+ setGenericFile(((GenericFileMessage) that).getGenericFile());
+ }
+ }
+
+ @Override
public String toString() {
// only output the filename as body can be big
if (file != null) {
[8/8] git commit: CAMEL-6452: Added shutdown method to FileUtil to
allow cleaning up temp dir and shutdown hook. Thanks to Sanjay Deshmukh for
the patch
Posted by da...@apache.org.
CAMEL-6452: Added shutdown method to FileUtil to allow cleaning up temp dir and shutdown hook. Thanks to Sanjay Deshmukh for the patch
Conflicts:
camel-core/src/main/java/org/apache/camel/util/FileUtil.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e9f2a1f8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e9f2a1f8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e9f2a1f8
Branch: refs/heads/camel-2.10.x
Commit: e9f2a1f86518d319c904283c04e90d57f243b823
Parents: 7c6b566
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 12:11:12 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 13:39:04 2013 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/util/FileUtil.java | 22 +++++++++++++++++---
.../org/apache/camel/util/FileUtilTest.java | 9 ++++++++
2 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e9f2a1f8/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index 7b9e5e0..001fa1b 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -30,7 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * File utilities
+ * File utilities.
*/
public final class FileUtil {
@@ -39,8 +39,10 @@ public final class FileUtil {
private static final transient Logger LOG = LoggerFactory.getLogger(FileUtil.class);
private static final int RETRY_SLEEP_MILLIS = 10;
private static File defaultTempDir;
+ private static Thread shutdownHook;
private FileUtil() {
+ // Utils method
}
/**
@@ -296,17 +298,31 @@ public final class FileUtil {
defaultTempDir = f;
// create shutdown hook to remove the temp dir
- Thread hook = new Thread() {
+ shutdownHook = new Thread() {
@Override
public void run() {
removeDir(defaultTempDir);
}
};
- Runtime.getRuntime().addShutdownHook(hook);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
return defaultTempDir;
}
+ /**
+ * Shutdown and cleanup the temporary directory and removes any shutdown hooks in use.
+ */
+ public static synchronized void shutdown() {
+ if (defaultTempDir != null && defaultTempDir.exists()) {
+ removeDir(defaultTempDir);
+ }
+
+ if (shutdownHook != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdownHook);
+ shutdownHook = null;
+ }
+ }
+
private static void removeDir(File d) {
String[] list = d.list();
if (list == null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/e9f2a1f8/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
index 46adfdf..e9a6431 100644
--- a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
@@ -204,4 +204,13 @@ public class FileUtilTest extends TestCase {
assertTrue("A new file should be created " + file, FileUtil.createNewFile(file));
}
+ public void testShutdown() throws Exception {
+ File tmpFile = FileUtil.createTempFile(null, null);
+ File tmpDir = tmpFile.getParentFile();
+ assertTrue(tmpDir.exists());
+
+ FileUtil.shutdown();
+ assertFalse(tmpDir.exists());
+ }
+
}
[4/8] git commit: CAMEL-6476: Introducing StreamCachingStrategy SPI
to make it easier to configure and allow 3rd party to plugin custom
strategies. Work in progress.
Posted by da...@apache.org.
CAMEL-6476: Introducing StreamCachingStrategy SPI to make it easier to configure and allow 3rd party to plugin custom strategies. Work in progress.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3f1f901a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3f1f901a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3f1f901a
Branch: refs/heads/master
Commit: 3f1f901a0cb6c52f8e7a10768fe1114f0a294b32
Parents: f0180ca
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 17 13:05:49 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 17 13:05:49 2013 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/CamelContext.java | 13 +++-
.../converter/stream/CachedOutputStream.java | 12 ++--
.../apache/camel/impl/DefaultCamelContext.java | 13 ++++
.../impl/DefaultStreamCachingStrategy.java | 68 ++++++++++++++++++++
.../apache/camel/spi/StreamCachingStrategy.java | 29 +++++++++
.../java/org/apache/camel/util/FileUtil.java | 33 ++++++----
6 files changed, 147 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3f1f901a/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 9e747c5..6db32ba 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -51,6 +51,7 @@ import org.apache.camel.spi.Registry;
import org.apache.camel.spi.RouteStartupOrder;
import org.apache.camel.spi.ServicePool;
import org.apache.camel.spi.ShutdownStrategy;
+import org.apache.camel.spi.StreamCachingStrategy;
import org.apache.camel.spi.TypeConverterRegistry;
import org.apache.camel.spi.UuidGenerator;
import org.apache.camel.util.LoadPropertiesException;
@@ -1207,9 +1208,19 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
*/
Map<String, Properties> findComponents() throws LoadPropertiesException, IOException;
-
/**
* Returns the HTML documentation for the given camel component
*/
String getComponentDocumentation(String componentName) throws IOException;
+
+ /**
+ * Gets the {@link StreamCachingStrategy} to use.
+ */
+ StreamCachingStrategy getStreamCachingStrategy();
+
+ /**
+ * Sets a custom {@link StreamCachingStrategy} to use.
+ */
+ void setStreamCachingStrategy(StreamCachingStrategy streamCachingStrategy);
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3f1f901a/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java b/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
index a2cf0a1..f12a111 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
@@ -55,7 +55,7 @@ public class CachedOutputStream extends OutputStream {
public static final String TEMP_DIR = "CamelCachedOutputStreamOutputDirectory";
public static final String CIPHER_TRANSFORMATION = "CamelCachedOutputStreamCipherTransformation";
private static final transient Logger LOG = LoggerFactory.getLogger(CachedOutputStream.class);
-
+
private OutputStream currentStream;
private boolean inMemory = true;
private int totalLength;
@@ -68,12 +68,12 @@ public class CachedOutputStream extends OutputStream {
private String cipherTransformation;
private CipherPair ciphers;
-
public CachedOutputStream(Exchange exchange) {
this(exchange, true);
}
public CachedOutputStream(Exchange exchange, boolean closedOnCompletion) {
+ // TODO: these options should be on StreamCachingStrategy
String bufferSize = exchange.getContext().getProperty(BUFFER_SIZE);
String hold = exchange.getContext().getProperty(THRESHOLD);
String dir = exchange.getContext().getProperty(TEMP_DIR);
@@ -86,6 +86,8 @@ public class CachedOutputStream extends OutputStream {
}
if (dir != null) {
this.outputDir = exchange.getContext().getTypeConverter().convertTo(File.class, dir);
+ } else {
+ this.outputDir = exchange.getContext().getStreamCachingStrategy().getTemporaryDirectory();
}
this.cipherTransformation = exchange.getContext().getProperty(CIPHER_TRANSFORMATION);
@@ -222,11 +224,7 @@ public class CachedOutputStream extends OutputStream {
flush();
ByteArrayOutputStream bout = (ByteArrayOutputStream)currentStream;
- if (outputDir == null) {
- tempFile = FileUtil.createTempFile("cos", ".tmp");
- } else {
- tempFile = FileUtil.createTempFile("cos", ".tmp", outputDir);
- }
+ tempFile = FileUtil.createTempFile("cos", ".tmp", outputDir);
LOG.trace("Creating temporary stream cache file: {}", tempFile);
http://git-wip-us.apache.org/repos/asf/camel/blob/3f1f901a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 9063095..e4017be 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -119,6 +119,7 @@ import org.apache.camel.spi.RouteContext;
import org.apache.camel.spi.RouteStartupOrder;
import org.apache.camel.spi.ServicePool;
import org.apache.camel.spi.ShutdownStrategy;
+import org.apache.camel.spi.StreamCachingStrategy;
import org.apache.camel.spi.TypeConverterRegistry;
import org.apache.camel.spi.UuidGenerator;
import org.apache.camel.support.ServiceSupport;
@@ -195,6 +196,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
private FactoryFinderResolver factoryFinderResolver = new DefaultFactoryFinderResolver();
private FactoryFinder defaultFactoryFinder;
private PropertiesComponent propertiesComponent;
+ private StreamCachingStrategy streamCachingStrategy = new DefaultStreamCachingStrategy();
private final Map<String, FactoryFinder> factories = new HashMap<String, FactoryFinder>();
private final Map<String, RouteService> routeServices = new LinkedHashMap<String, RouteService>();
private final Map<String, RouteService> suspendedRouteServices = new LinkedHashMap<String, RouteService>();
@@ -1679,6 +1681,9 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
threshold = StreamCache.DEFAULT_SPOOL_THRESHOLD;
}
log.info("Stream caching is enabled, and using {} kb as threshold for overflow and spooling to disk store.", threshold / 1024);
+
+ // stream caching is in use so enable the strategy
+ addService(streamCachingStrategy);
}
// start routes
@@ -2660,6 +2665,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
this.uuidGenerator = uuidGenerator;
}
+ public StreamCachingStrategy getStreamCachingStrategy() {
+ return streamCachingStrategy;
+ }
+
+ public void setStreamCachingStrategy(StreamCachingStrategy streamCachingStrategy) {
+ this.streamCachingStrategy = streamCachingStrategy;
+ }
+
@Override
public String getProperty(String name) {
String value = getProperties().get(name);
http://git-wip-us.apache.org/repos/asf/camel/blob/3f1f901a/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
new file mode 100644
index 0000000..3333d77
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.io.File;
+
+import org.apache.camel.spi.StreamCachingStrategy;
+import org.apache.camel.util.FileUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultStreamCachingStrategy extends org.apache.camel.support.ServiceSupport implements StreamCachingStrategy {
+
+ // TODO: Add options to configure more stuff like overflow size et all
+ // TODO: Add JMX management
+ // TODO: Maybe use #syntax# for default temp dir so ppl can easily configure this
+
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultStreamCachingStrategy.class);
+ private File temporaryDirectory;
+
+ public void setTemporaryDirectory(File path) {
+ this.temporaryDirectory = path;
+ }
+
+ public File getTemporaryDirectory() {
+ return temporaryDirectory;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ // create random temporary directory if none has been created
+ if (temporaryDirectory == null) {
+ temporaryDirectory = FileUtil.createNewTempDir();
+ LOG.info("Created temporary directory {}", temporaryDirectory);
+ } else {
+ if (!temporaryDirectory.exists()) {
+ boolean created = temporaryDirectory.mkdirs();
+ if (!created) {
+ LOG.warn("Cannot create temporary directory {}", temporaryDirectory);
+ } else {
+ LOG.info("Created temporary directory {}", temporaryDirectory);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (temporaryDirectory != null) {
+ LOG.info("Removing temporary directory {}", temporaryDirectory);
+ FileUtil.removeDir(temporaryDirectory);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3f1f901a/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
new file mode 100644
index 0000000..cc5ad2e
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import java.io.File;
+
+/**
+ * Strategy for using <a href="http://camel.apache.org/stream-caching.html">stream caching</a>.
+ */
+public interface StreamCachingStrategy {
+
+ void setTemporaryDirectory(File path);
+
+ File getTemporaryDirectory();
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3f1f901a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index 339a5da..22b691d 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -285,6 +285,24 @@ public final class FileUtil {
return defaultTempDir;
}
+ defaultTempDir = createNewTempDir();
+
+ // create shutdown hook to remove the temp dir
+ shutdownHook = new Thread() {
+ @Override
+ public void run() {
+ removeDir(defaultTempDir);
+ }
+ };
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+
+ return defaultTempDir;
+ }
+
+ /**
+ * Creates a new temporary directory in the <tt>java.io.tmpdir</tt> directory.
+ */
+ public static File createNewTempDir() {
String s = System.getProperty("java.io.tmpdir");
File checkExists = new File(s);
if (!checkExists.exists()) {
@@ -304,18 +322,7 @@ public final class FileUtil {
f = new File(s, "camel-tmp-" + x);
}
- defaultTempDir = f;
-
- // create shutdown hook to remove the temp dir
- shutdownHook = new Thread() {
- @Override
- public void run() {
- removeDir(defaultTempDir);
- }
- };
- Runtime.getRuntime().addShutdownHook(shutdownHook);
-
- return defaultTempDir;
+ return f;
}
/**
@@ -332,7 +339,7 @@ public final class FileUtil {
}
}
- private static void removeDir(File d) {
+ public static void removeDir(File d) {
String[] list = d.list();
if (list == null) {
list = new String[0];