src/solaris/classes/sun/nio/fs/LinuxWatchService.java

Print this page




  85     {
  86         // delegate to poller
  87         return poller.register(dir, events, modifiers);
  88     }
  89 
  90     @Override
  91     void implClose() throws IOException {
  92         // delegate to poller
  93         poller.close();
  94     }
  95 
  96     /**
  97      * WatchKey implementation
  98      */
  99     private static class LinuxWatchKey extends AbstractWatchKey {
 100         // inotify descriptor
 101         private final int ifd;
 102         // watch descriptor
 103         private volatile int wd;
 104 
 105         LinuxWatchKey(LinuxWatchService watcher, int ifd, int wd) {
 106             super(watcher);
 107             this.ifd = ifd;
 108             this.wd = wd;
 109         }
 110 
 111         int descriptor() {
 112             return wd;
 113         }
 114 
 115         void invalidate(boolean remove) {
 116             if (remove) {
 117                 try {
 118                     inotifyRmWatch(ifd, wd);
 119                 } catch (UnixException x) {
 120                     // ignore
 121                 }
 122             }
 123             wd = -1;
 124         }
 125 
 126         @Override


 249             // register with inotify (replaces existing mask if already registered)
 250             int wd = -1;
 251             try {
 252                 NativeBuffer buffer =
 253                     NativeBuffers.asNativeBuffer(dir.getByteArrayForSysCalls());
 254                 try {
 255                     wd = inotifyAddWatch(ifd, buffer.address(), mask);
 256                 } finally {
 257                     buffer.release();
 258                 }
 259             } catch (UnixException x) {
 260                 if (x.errno() == ENOSPC) {
 261                     return new IOException("User limit of inotify watches reached");
 262                 }
 263                 return x.asIOException(dir);
 264             }
 265 
 266             // ensure watch descriptor is in map
 267             LinuxWatchKey key = wdToKey.get(wd);
 268             if (key == null) {
 269                 key = new LinuxWatchKey(watcher, ifd, wd);
 270                 wdToKey.put(wd, key);
 271             }
 272             return key;
 273         }
 274 
 275         // cancel single key
 276         @Override
 277         void implCancelKey(WatchKey obj) {
 278             LinuxWatchKey key = (LinuxWatchKey)obj;
 279             if (key.isValid()) {
 280                 wdToKey.remove(key.descriptor());
 281                 key.invalidate(true);
 282             }
 283         }
 284 
 285         // close watch service
 286         @Override
 287         void implCloseAll() {
 288             // invalidate all keys
 289             for (Map.Entry<Integer,LinuxWatchKey> entry: wdToKey.entrySet()) {




  85     {
  86         // delegate to poller
  87         return poller.register(dir, events, modifiers);
  88     }
  89 
  90     @Override
  91     void implClose() throws IOException {
  92         // delegate to poller
  93         poller.close();
  94     }
  95 
  96     /**
  97      * WatchKey implementation
  98      */
  99     private static class LinuxWatchKey extends AbstractWatchKey {
 100         // inotify descriptor
 101         private final int ifd;
 102         // watch descriptor
 103         private volatile int wd;
 104 
 105         LinuxWatchKey(UnixPath dir, LinuxWatchService watcher, int ifd, int wd) {
 106             super(dir, watcher);
 107             this.ifd = ifd;
 108             this.wd = wd;
 109         }
 110 
 111         int descriptor() {
 112             return wd;
 113         }
 114 
 115         void invalidate(boolean remove) {
 116             if (remove) {
 117                 try {
 118                     inotifyRmWatch(ifd, wd);
 119                 } catch (UnixException x) {
 120                     // ignore
 121                 }
 122             }
 123             wd = -1;
 124         }
 125 
 126         @Override


 249             // register with inotify (replaces existing mask if already registered)
 250             int wd = -1;
 251             try {
 252                 NativeBuffer buffer =
 253                     NativeBuffers.asNativeBuffer(dir.getByteArrayForSysCalls());
 254                 try {
 255                     wd = inotifyAddWatch(ifd, buffer.address(), mask);
 256                 } finally {
 257                     buffer.release();
 258                 }
 259             } catch (UnixException x) {
 260                 if (x.errno() == ENOSPC) {
 261                     return new IOException("User limit of inotify watches reached");
 262                 }
 263                 return x.asIOException(dir);
 264             }
 265 
 266             // ensure watch descriptor is in map
 267             LinuxWatchKey key = wdToKey.get(wd);
 268             if (key == null) {
 269                 key = new LinuxWatchKey(dir, watcher, ifd, wd);
 270                 wdToKey.put(wd, key);
 271             }
 272             return key;
 273         }
 274 
 275         // cancel single key
 276         @Override
 277         void implCancelKey(WatchKey obj) {
 278             LinuxWatchKey key = (LinuxWatchKey)obj;
 279             if (key.isValid()) {
 280                 wdToKey.remove(key.descriptor());
 281                 key.invalidate(true);
 282             }
 283         }
 284 
 285         // close watch service
 286         @Override
 287         void implCloseAll() {
 288             // invalidate all keys
 289             for (Map.Entry<Integer,LinuxWatchKey> entry: wdToKey.entrySet()) {