What is the best way for callback when some file changed

Answered

Dear all please tell me the best way to handle (callback), when some file changed in project. 
My current usage like this:

public void activateListeners(Project project) {
// Project Message Bus
MessageBus messageBus = project.getMessageBus();
// Virtual File change handlers
messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
for (VFileEvent event : events) {
System.out.println("Project Service After Event Invoked ..." + event);
}
}
});
}

Same question here
Thanks in advance

2 comments
Comment actions Permalink

The equivalent with asynchronous listener will be: 

VirtualFileManager.getInstance().addAsyncFileListener(new AsyncFileListener() {
@Nullable
@Override
public ChangeApplier prepareChange(@NotNull List<? extends VFileEvent> events) {
for (VFileEvent event : events) {
System.out.println("Project Service After Event Invoked ..." + event);
}
return null;
}
}, new Disposable() {
@Override
public void dispose() {
System.out.println("Disposing .......");
}
});
1

Please sign in to leave a comment.