Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class LockClientNotifier {
...
private void observeAndNotifyClients() {
while (active) {
try {
final WatchKey wk;
try {
wk = ws.take();
} catch (final Exception ex) {
break;
}
final List<WatchEvent<?>> events = wk.pollEvents();
for (final WatchEvent<?> event : events) {
final boolean created = event.kind().equals(StandardWatchEventKind.ENTRY_CREATE);
final boolean deleted = event.kind().equals(StandardWatchEventKind.ENTRY_DELETE);
final WatchContext context = (WatchContext) event.context();
final Path path = (created) ? context.getPath() : context.getOldPath();
if (path != null && path.getFileName().toString().endsWith(PathFactory.LOCK_FILE_EXTENSION)) {
final org.uberfire.backend.vfs.Path vfsLockPath = Paths.convert(path);
final org.uberfire.backend.vfs.Path vfsPath = PathFactory.fromLock(vfsLockPath);
if (created) {
final String lockedBy = ioService.readAllString(path);
lockEvent.fire(new LockInfo(true,
lockedBy,
vfsPath,
vfsLockPath));
} else if (deleted) {
lockEvent.fire(new LockInfo(false,
null,
vfsPath,
vfsLockPath));
}
}
}
if (!wk.reset()) {
break;
}
} catch (final Exception ignored) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment