vitojeng
(Vito Jeng)
May 14, 2019, 3:10pm
1
Hi,
I use Directory.walk(path) to traverse all subdirectories.
It works perfectly.
But some subdirectories may encounter permission issue and throw an exception:
java.io.UncheckedIOException: java.nio.file.AccessDeniedException: /full/path/name
I want to use supervision strategies(resume) so that the stream can continue the process.
But it seems with no luck. Follow is the sample code:
val decider: Supervision.Decider = {
case _: UncheckedIOException => Supervision.Resume
case _ => Supervision.Stop
}
implicit val actorSystem = ActorSystem("FileIOExample")
val actorMaterializerSettings = ActorMaterializerSettings(actorSystem).withSupervisionStrategy(decider)
implicit val actorMaterializer = ActorMaterializer(actorMaterializerSettings)
implicit val ec = actorSystem.dispatcher
Directory.walk(Paths.get("/")).to {
Sink.foreach(f =>
println(f)
)
}.run()
Do I miss something? Thanks a lot.
Ivano
(Ivano Pagano)
May 16, 2019, 7:14am
2
Supervision in akka-streams is trickier than in Actors
If you look at the note at the paragraph beginning , you’ll discover that each stage might or might not support supervision.
The point is that you need to check out if the Directory.walk
stage is one of the “lucky guys”, and read the docs to learn if and how it might handle supervision
ennru
(Enno)
May 16, 2019, 8:13am
3
Hi @Ivano
Thank you for your question and investigation about Directory.walk
. You’re right that operator doesn’t have supervision built in right now.
It is a very thin wrapper of Files.walk
so you might want to take a copy to experiment with add supervision.
It would be great if you would come up with a Pull Request to improve it in Alpakka!
Cheers,
Enno.
Ivano
(Ivano Pagano)
May 16, 2019, 11:58am
4
Well maybe @vitojeng will be more interested into that, I was just giving a hint to the current situation.
I currently have no time to dedicate, sadly.
vitojeng
(Vito Jeng)
May 20, 2019, 7:26am
5
Thank you @Ivano , very helpful!
I would take a look when I have time.
Also thanks @ennru for the explanation.