camel icon indicating copy to clipboard operation
camel copied to clipboard

[CAMEL-17130] camel-file - Use NIO

Open rnetuka opened this issue 2 years ago • 9 comments

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.

rnetuka avatar Jun 10 '22 14:06 rnetuka

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

github-actions[bot] avatar Jun 10 '22 14:06 github-actions[bot]

@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. 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).

orpiske avatar Jun 10 '22 14:06 orpiske

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

bmarcj avatar Jun 10 '22 19:06 bmarcj

@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. 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

davsclaus avatar Jun 14 '22 05:06 davsclaus

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

davsclaus avatar Jun 14 '22 05:06 davsclaus

@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. 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.

orpiske avatar Jun 14 '22 07:06 orpiske

There are merge conflicts - can you update the PR thanks

davsclaus avatar Jun 16 '22 19:06 davsclaus

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)

github-actions[bot] avatar Jul 08 '22 15:07 github-actions[bot]

In FileConsumer filtering filenames before creating GenericFile would make big performance benefit when searching single file on network shares with thousand of files.

gitokus avatar Sep 12 '22 12:09 gitokus

@rnetuka can you please rebase?

oscerd avatar Nov 02 '22 18:11 oscerd

closing old and outdated PRs

davsclaus avatar Mar 08 '23 12:03 davsclaus