OSGI component is in satisfied state but not in active while we include Java Watch service in it
Hi All,
I have a osgi component and i have added java watch service (as a listener to watch directories) in it. So once bundle is installed, component goes to satisfied state.(but main bundle will be in active state)
Because of this, other components will be disabled. I am forced to enable them manually.
If I remove watch service from osgi component, it works fine. Please let me know if i am missing anything.
Code:
@Activate
@Modified
protected void activate(final Map<String, Object> properties) {
WatchService watchService = null;
WatchKey key = null;
try {
watchService = FileSystems.getDefault().newWatchService();
if ( StringUtils.isNotEmpty("somePath")) {
Path path = Paths.get("somePath");
path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY);
while ((key = watchService.take()) != null) {
for (WatchEvent<?> event : key.pollEvents()) {
// do some action
}
key.reset();
}
} else {
watchService.close();
}
} catch (IOException | InterruptedException e) {
logger.error("Exception {}", e);
}
}
second issue is, deactivate is not working.
code:
@Deactivate
protected final void deactivate(final Map<String, String> properties) {
logger.info("inside deactivate");
//disable watch event
}