NIO watchservice for UNIX sys/classes/gpio files
Asked Answered
A

1

6

Is it possible to set the JAVA NIO WatchService on files in the /sys/class/gpio/gpioX device tree to supervise changes there ?

It would be nice idea to detect changes on the GPIO files (i.e. the GPIO -inputs) directly from within Java, but I fear that is not supported.

A confirmation that it's not supported (and perhaps why) would be sufficient.

Announce answered 12/5, 2015 at 12:21 Comment(1)
Any luck with this? Do you need any more info?Addax
A
6

The linux implementation of the Java 7 NIO FileWatcher uses inotify. Inotify is a linux kernel subsystem to notice filesystem changes. It has restrictions and doesn't work on /proc, /sys and network shares. Please read inotify limitations on wiki :

Inotify does report some but not all events in sysfs and procfs.

Notification via inotify requires the kernel to be aware of all relevant filesystem events, which is not always possible for networked filesystems such as NFS where changes made by one client are not immediately broadcast to other clients.

and a bit more:

inotify missing events
Java WatchService doesn't work on some folders
Java WatchService not generating events while watching mapped drives

Addax answered 16/2, 2016 at 20:1 Comment(2)
That's pretty interesting. I figured that it wouldn't work on things like /proc and /sys, but I'd expect network filesystems to be able to implement it assuming the protocol permits for it.Pooley
@Trejkaz it's sad but true. kernel can't control network filesystem. FYI: i've improved my answerAddax

© 2022 - 2024 — McMap. All rights reserved.