You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/06/10 14:19:24 UTC

[GitHub] [camel] rnetuka opened a new pull request, #7761: [CAMEL-17130] camel-file - Use NIO

rnetuka opened a new pull request, #7761:
URL: https://github.com/apache/camel/pull/7761

   Issue: https://issues.apache.org/jira/browse/CAMEL-17130
   
   Changes:
   1. There are simple Java IO -> NIO upgrades such as replace File usage with Path (in places it actually helps and doesn't make the code less readable)
   2. FileConsumer - changed pollDirectory() and listFiles() methods to stream processing
   3. FileResumeSet - completely rewritten to suit the stream processing above
   4. FileUtils - some methods oveloads for Path for convenient usage
   
   Notes:
   - I've kept File as a class that is being transferred in an Exchange. I tried to replace it with Path, but run into problems with converters. If it makes sence, we can add this change in a next step
   - the changes might not handle corner cases well, since for example File#getName() might return an empty string and Path#getFileName() return null in the same case. I suppose this doesn't pose much problem so I left it as it is.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] rnetuka commented on a diff in pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
rnetuka commented on code in PR #7761:
URL: https://github.com/apache/camel/pull/7761#discussion_r898982383


##########
components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java:
##########
@@ -423,38 +423,38 @@ private void keepLastModified(Exchange exchange, File file) {
                 last = exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Long.class);
             }
             if (last != null) {
-                boolean result = file.setLastModified(last);
+                boolean result = file.toFile().setLastModified(last);
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("Keeping last modified timestamp: {} on file: {} with result: {}", last, file, result);
                 }
             }
         }
     }
 
-    private boolean writeFileByLocalWorkPath(File source, File file) throws IOException {
+    private boolean writeFileByLocalWorkPath(Path source, Path file) throws IOException {
         LOG.trace("writeFileByFile using local work file being renamed from: {} to: {}", source, file);
         return FileUtil.renameFile(source, file, endpoint.isCopyAndDeleteOnRenameFail());
     }
 
-    private void writeFileByFile(File source, File target, Exchange exchange) throws IOException {
+    private void writeFileByFile(Path source, Path target, Exchange exchange) throws IOException {
         // in case we are using file locks as read-locks then we need to use
         // file channels for copying to support this
-        String path = source.getAbsolutePath();
+        String path = source.toAbsolutePath().toString();
         FileChannel channel
                 = exchange.getProperty(asExclusiveReadLockKey(path, Exchange.FILE_LOCK_CHANNEL_FILE), FileChannel.class);
         if (channel != null) {
-            try (FileChannel out = new FileOutputStream(target).getChannel()) {
+            try (FileChannel out = new FileOutputStream(target.toFile()).getChannel()) {

Review Comment:
   I've updated the code. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] oscerd commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
oscerd commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1301022583

   @rnetuka can you please rebase?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1179128635

   There are too many components to be tested in this PR, components were removed or the code needs a rebase: (302 likely to be tested)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1460057029

   closing old and outdated PRs


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
orpiske commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1154813026

   > > @rnetuka Nice one!
   > > I'm wondering if it would make sense to plan for, in a future work, implement a better/more modern mechanism for watching for file notifications. That way, maybe it would not be necessary to poll all the time and, instead, use something like the [WatchService](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/WatchService.html). I believe this would be more resource efficient as well, as the JVM probably hooks to the native file system modification mechanism for each OS (i.e.: like inotify on Linux or something like that).
   > 
   > There is already camel-file-watch
   
   Yeah, I know. My point is whether we can, maybe, consolidate code/features/etc where possible and opportunistically reduce duplicated feature set / code. It would make it easier to test and maintain, IMHO.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus closed pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus closed pull request #7761: [CAMEL-17130] camel-file - Use NIO
URL: https://github.com/apache/camel/pull/7761


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
davsclaus commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1154720145

   > @rnetuka Nice one!
   > 
   > I'm wondering if it would make sense to plan for, in a future work, implement a better/more modern mechanism for watching for file notifications. That way, maybe it would not be necessary to poll all the time and, instead, use something like the [WatchService](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/WatchService.html). I believe this would be more resource efficient as well, as the JVM probably hooks to the native file system modification mechanism for each OS (i.e.: like inotify on Linux or something like that).
   
   There is already camel-file-watch


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
orpiske commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1152433165

   @rnetuka Nice one!
   
   I'm wondering if it would make sense to plan for, in a future work, implement a better/more modern mechanism for watching for file notifications. That way, maybe it would not be necessary to poll all the time and, instead, use something like the [WatchService](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/WatchService.html). I believe this would be more resource efficient as well, as the JVM probably hooks to the native file system modification mechanism for each OS (i.e.: like inotify on Linux or something like that). 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] bmarcj commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
bmarcj commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1152649131

   Great idea! 
   
   Using Java's NIO features exclusively opens the door to one day using something like the filesystem provider for s3 or minio e.g.
   https://github.com/Upplication/Amazon-S3-FileSystem-NIO2


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1152413514

   :warning: This PR changes Camel components and will be tested automatically.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] bmarcj commented on a diff in pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
bmarcj commented on code in PR #7761:
URL: https://github.com/apache/camel/pull/7761#discussion_r895082545


##########
components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java:
##########
@@ -423,38 +423,38 @@ private void keepLastModified(Exchange exchange, File file) {
                 last = exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Long.class);
             }
             if (last != null) {
-                boolean result = file.setLastModified(last);
+                boolean result = file.toFile().setLastModified(last);
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("Keeping last modified timestamp: {} on file: {} with result: {}", last, file, result);
                 }
             }
         }
     }
 
-    private boolean writeFileByLocalWorkPath(File source, File file) throws IOException {
+    private boolean writeFileByLocalWorkPath(Path source, Path file) throws IOException {
         LOG.trace("writeFileByFile using local work file being renamed from: {} to: {}", source, file);
         return FileUtil.renameFile(source, file, endpoint.isCopyAndDeleteOnRenameFail());
     }
 
-    private void writeFileByFile(File source, File target, Exchange exchange) throws IOException {
+    private void writeFileByFile(Path source, Path target, Exchange exchange) throws IOException {
         // in case we are using file locks as read-locks then we need to use
         // file channels for copying to support this
-        String path = source.getAbsolutePath();
+        String path = source.toAbsolutePath().toString();
         FileChannel channel
                 = exchange.getProperty(asExclusiveReadLockKey(path, Exchange.FILE_LOCK_CHANNEL_FILE), FileChannel.class);
         if (channel != null) {
-            try (FileChannel out = new FileOutputStream(target).getChannel()) {
+            try (FileChannel out = new FileOutputStream(target.toFile()).getChannel()) {

Review Comment:
   `FileChannel.open(target)`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
davsclaus commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1154721087

   Make sure camel-ftp and camel-jsch keeps working after changing in camel-file


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
davsclaus commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1158049841

   There are merge conflicts - can you update the PR thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] gitokus commented on pull request #7761: [CAMEL-17130] camel-file - Use NIO

Posted by GitBox <gi...@apache.org>.
gitokus commented on PR #7761:
URL: https://github.com/apache/camel/pull/7761#issuecomment-1243653342

   In FileConsumer filtering filenames before creating GenericFile would make big performance benefit when processing network shares with lots of files.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org