Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NIO watchservice for UNIX sys/classes/gpio files

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.

like image 922
user1226230 Avatar asked May 12 '15 12:05

user1226230


1 Answers

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

like image 62
Vladislav Kysliy Avatar answered Oct 04 '22 21:10

Vladislav Kysliy