2

So currently I am reading files with an file inbound adapter (nio locker on) and just log them.

I've tried to attach a file outbound adapter at the tail of the flow, in order to move the files to a new location (/done), but every time I encounter an error because the file is locked.

If I remove the nio-locker flag, everything is OK. Problem here is that I would like to have multiple JVM working on those files, and there is a risk that a file will picked up by two JVMs.

Thanks, Cristi

Cristi
  • 180
  • 15

1 Answers1

2

Try to expose NioFileLocker as a bean and use its name in the <locker ref=""> instead of internal <nio-locker>.

When you are ready to move the file, call that NioFileLocker bean and its unlock(File).

Let us know how it works and I guess we can revise the NioFileLocker bean registration based on the name of the <int-file:inbound-channel-adapter>.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 1
    Hello. I've thought about this as well, but I wanted to have multiple JVM (processes) scanning same directory. Given this it will mean that there is a really small chance that another JVM to pick up the file that was just unlocked in order to be moved. Don't know if there is an working solution for this. For now, I've removed the NioLocker and I will have only one JVM scanning a specific folder. – Cristi Nov 17 '17 at 18:39
  • How about this then https://stackoverflow.com/questions/35093757/move-a-file-without-releasing-lock ? – Artem Bilan Nov 17 '17 at 19:05
  • Hey. Sorry about the late response. I've tried that as well, the copy works without any issue, but the main issue (file cannot be deleted from input folder) still remains. What we've did, is make a decision and agree that only one JVM will scan a certain folder at one time (to avoid locking). – Cristi Dec 05 '17 at 08:53
  • @Artem Bilan - do that mean another application instance would still have the opportunity to scan the file when niolocker unlock – Ben Cheng Oct 25 '19 at 01:02
  • 1
    That's correct. As long as you don't remove that file and don't use a shared persistence `FileListFilter`, another instance will pick it up eventually after unlocking. We really advice to use a persistence `FileListFilter` based on `MetadataStore`: https://docs.spring.io/spring-integration/docs/current/reference/html/file.html#file-reading – Artem Bilan Oct 25 '19 at 01:19