APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.nio.fs

pack-priv Class LinuxWatchService

extends AbstractWatchService
Class Inheritance
Imports
java.nio.file.*, java.util.*, java.io.IOException, jdk.internal.misc.Unsafe

Linux implementation of WatchService based on inotify. In summary a background thread polls inotify plus a socket used for the wakeup mechanism. Requests to add or remove a watch, or close the watch service, cause the thread to wakeup and process the request. Events are processed by the thread which causes it to signal/queue the corresponding watch keys.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
LinuxWatchService.LinuxWatchKey

WatchKey implementation

private static class
LinuxWatchService.Poller

Background thread to read from inotify

Field Summary

Modifier and TypeField and Description
private final LinuxWatchService.Poller
private static final Unsafe

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static native void
configureBlocking(int fd, boolean blocking)

private static native int[]
private static native int
pack-priv void
implClose()

Implements abstract sun.nio.fs.AbstractWatchService.implClose.

Closes this watch service.

private static native int
inotifyAddWatch(int fd, long pathAddress, int mask)

private static native int
private static native void
inotifyRmWatch(int fd, int wd)

private static native int
poll(int fd1, int fd2)

pack-priv WatchKey
register(Path dir, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers)

Implements abstract sun.nio.fs.AbstractWatchService.register.

Register the given object with this watch service

private static native void
socketpair(int[] sv)

Inherited from sun.nio.fs.AbstractWatchService:
closecloseLockenqueueKeyisOpenpollpolltake

Field Detail

pollerback to summary
private final LinuxWatchService.Poller poller
unsafeback to summary
private static final Unsafe unsafe

Constructor Detail

LinuxWatchServiceback to summary
pack-priv LinuxWatchService(UnixFileSystem fs) throws IOException

Method Detail

configureBlockingback to summary
private static native void configureBlocking(int fd, boolean blocking) throws UnixException
eventOffsetsback to summary
private static native int[] eventOffsets()
eventSizeback to summary
private static native int eventSize()
implCloseback to summary
pack-priv void implClose() throws IOException

Implements abstract sun.nio.fs.AbstractWatchService.implClose.

Doc from sun.nio.fs.AbstractWatchService.implClose.

Closes this watch service. This method is invoked by the close method to perform the actual work of closing the watch service.

Annotations
@Override
inotifyAddWatchback to summary
private static native int inotifyAddWatch(int fd, long pathAddress, int mask) throws UnixException
inotifyInitback to summary
private static native int inotifyInit() throws UnixException
inotifyRmWatchback to summary
private static native void inotifyRmWatch(int fd, int wd) throws UnixException
pollback to summary
private static native int poll(int fd1, int fd2) throws UnixException
registerback to summary
pack-priv WatchKey register(Path dir, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException

Implements abstract sun.nio.fs.AbstractWatchService.register.

Doc from sun.nio.fs.AbstractWatchService.register.

Register the given object with this watch service

Annotations
@Override
socketpairback to summary
private static native void socketpair(int[] sv) throws UnixException
sun.nio.fs back to summary

private Class LinuxWatchService.LinuxWatchKey

extends AbstractWatchKey
Class Inheritance

WatchKey implementation

Field Summary

Modifier and TypeField and Description
private final int
private volatile int
Inherited from sun.nio.fs.AbstractWatchKey:
MAX_EVENT_LIST_SIZEOVERFLOW_EVENT

Constructor Summary

AccessConstructor and Description
pack-priv
LinuxWatchKey(UnixPath dir, LinuxWatchService watcher, int ifd, int wd)

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements java.nio.file.WatchKey.cancel.

Cancels the registration with the watch service.

pack-priv int
pack-priv void
invalidate(boolean remove)

public boolean
isValid()

Implements java.nio.file.WatchKey.isValid.

Tells whether or not this watch key is valid.

Inherited from sun.nio.fs.AbstractWatchKey:
pollEventsresetsignalsignalEventwatchablewatcher

Field Detail

ifdback to summary
private final int ifd
wdback to summary
private volatile int wd

Constructor Detail

LinuxWatchKeyback to summary
pack-priv LinuxWatchKey(UnixPath dir, LinuxWatchService watcher, int ifd, int wd)

Method Detail

cancelback to summary
public void cancel()

Implements java.nio.file.WatchKey.cancel.

Doc from java.nio.file.WatchKey.cancel.

Cancels the registration with the watch service. Upon return the watch key will be invalid. If the watch key is enqueued, waiting to be retrieved from the watch service, then it will remain in the queue until it is removed. Pending events, if any, remain pending and may be retrieved by invoking the pollEvents method after the key is cancelled.

If this watch key has already been cancelled then invoking this method has no effect. Once cancelled, a watch key remains forever invalid.

Annotations
@Override
descriptorback to summary
pack-priv int descriptor()
invalidateback to summary
pack-priv void invalidate(boolean remove)
isValidback to summary
public boolean isValid()

Implements java.nio.file.WatchKey.isValid.

Doc from java.nio.file.WatchKey.isValid.

Tells whether or not this watch key is valid.

A watch key is valid upon creation and remains until it is cancelled, or its watch service is closed.

Annotations
@Override
sun.nio.fs back to summary

private Class LinuxWatchService.Poller

extends AbstractPoller
Class Inheritance

Background thread to read from inotify

Field Summary

Modifier and TypeField and Description
private final long
private static final int
private final UnixFileSystem
private final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int[]
private static final int
SIZEOF_INOTIFY_EVENT

struct inotify_event { int wd; uint32_t mask; uint32_t len; char name __flexarr; // present if len > 0 } act_t;

private final int[]
private final LinuxWatchService
private final Map<Integer, LinuxWatchService.LinuxWatchKey>

Constructor Summary

AccessConstructor and Description
pack-priv
Poller(UnixFileSystem fs, LinuxWatchService watcher, int ifd, int[] sp)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
implCancelKey(WatchKey obj)

Implements abstract sun.nio.fs.AbstractPoller.implCancelKey.

Executed by poller thread to cancel key

pack-priv void
implCloseAll()

Implements abstract sun.nio.fs.AbstractPoller.implCloseAll.

Executed by poller thread to shutdown and cancel all keys

pack-priv Object
implRegister(Path obj, Set<? extends WatchEvent.Kind<?>> events, WatchEvent.Modifier... modifiers)

Implements abstract sun.nio.fs.AbstractPoller.implRegister.

Executed by poller thread to register directory for changes

private WatchEvent.Kind<?>
maskToEventKind(int mask)

map inotify event to WatchEvent.Kind

private void
processEvent(int wd, int mask, final UnixPath name)

Process event from inotify

public void
run()

Implements java.lang.Runnable.run.

Poller main loop

pack-priv void
wakeup()

Implements abstract sun.nio.fs.AbstractPoller.wakeup.

Wakeup poller thread so that it can service pending requests

Inherited from sun.nio.fs.AbstractPoller:
cancelcloseprocessRequestsregisterstart

Field Detail

addressback to summary
private final long address
BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
fsback to summary
private final UnixFileSystem fs
ifdback to summary
private final int ifd
IN_ATTRIBback to summary
private static final int IN_ATTRIB
IN_CREATEback to summary
private static final int IN_CREATE
IN_DELETEback to summary
private static final int IN_DELETE
IN_IGNOREDback to summary
private static final int IN_IGNORED
IN_MODIFYback to summary
private static final int IN_MODIFY
IN_MOVED_FROMback to summary
private static final int IN_MOVED_FROM
IN_MOVED_TOback to summary
private static final int IN_MOVED_TO
IN_Q_OVERFLOWback to summary
private static final int IN_Q_OVERFLOW
IN_UNMOUNTback to summary
private static final int IN_UNMOUNT
OFFSETOF_LENback to summary
private static final int OFFSETOF_LEN
OFFSETOF_MASKback to summary
private static final int OFFSETOF_MASK
OFFSETOF_NAMEback to summary
private static final int OFFSETOF_NAME
OFFSETOF_WDback to summary
private static final int OFFSETOF_WD
offsetsback to summary
private static final int[] offsets
SIZEOF_INOTIFY_EVENTback to summary
private static final int SIZEOF_INOTIFY_EVENT

struct inotify_event { int wd; uint32_t mask; uint32_t len; char name __flexarr; // present if len > 0 } act_t;

socketpairback to summary
private final int[] socketpair
watcherback to summary
private final LinuxWatchService watcher
wdToKeyback to summary
private final Map<Integer, LinuxWatchService.LinuxWatchKey> wdToKey

Constructor Detail

Pollerback to summary
pack-priv Poller(UnixFileSystem fs, LinuxWatchService watcher, int ifd, int[] sp)

Method Detail

implCancelKeyback to summary
pack-priv void implCancelKey(WatchKey obj)

Implements abstract sun.nio.fs.AbstractPoller.implCancelKey.

Doc from sun.nio.fs.AbstractPoller.implCancelKey.

Executed by poller thread to cancel key

Annotations
@Override
implCloseAllback to summary
pack-priv void implCloseAll()

Implements abstract sun.nio.fs.AbstractPoller.implCloseAll.

Doc from sun.nio.fs.AbstractPoller.implCloseAll.

Executed by poller thread to shutdown and cancel all keys

Annotations
@Override
implRegisterback to summary
pack-priv Object implRegister(Path obj, Set<? extends WatchEvent.Kind<?>> events, WatchEvent.Modifier... modifiers)

Implements abstract sun.nio.fs.AbstractPoller.implRegister.

Doc from sun.nio.fs.AbstractPoller.implRegister.

Executed by poller thread to register directory for changes

Annotations
@Override
maskToEventKindback to summary
private WatchEvent.Kind<?> maskToEventKind(int mask)

map inotify event to WatchEvent.Kind

processEventback to summary
private void processEvent(int wd, int mask, final UnixPath name)

Process event from inotify

runback to summary
public void run()

Implements java.lang.Runnable.run.

Poller main loop

Annotations
@Override
wakeupback to summary
pack-priv void wakeup() throws IOException

Implements abstract sun.nio.fs.AbstractPoller.wakeup.

Doc from sun.nio.fs.AbstractPoller.wakeup.

Wakeup poller thread so that it can service pending requests

Annotations
@Override