Subscribing topic take too long. Then my code cannot run correctly.
I'm using subscribing topic. But it will not catch the event because of too slow to subscribe.
I have two code to subscribing VCS_CONFIGURATION_MANAGER.
One is a ProjectComponent which subscribe when project opened.
One is a toolWindow which subscribe when toolwindow opened.
ProjectComponent code is like this.
private volatile boolean vcsInitialized;
@Override
public void projectOpened() {
vcsInitialized = false;
System.out.println("projectOpened() -> "+myProject.getName());
myProject.getMessageBus().connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, new VcsListener() {
@Override
public void directoryMappingChanged() {
vcsInitialized = true;
System.out.println("DirectoryMappingChanged:"+myProject.getName());
}
});
}
This is watching VCS_CONFIGURATION_CHANGED.
The toolwindow code is like this.
if(<<ProjectComponentClass>>.getInstance(project).isVcsInitialized()) {
System.out.println("if isVcsInitialized");
doSomething();
} else {
System.out.println("else isVcsInitialized");
project.getMessageBus().connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, new VcsListener() {
@Override
public void directoryMappingChanged() {
System.out.println("toolWindow:directoryMappingChanged");
doSomething();
}
});
System.out.println("finish subscribe");
}
This means Toolwindow code check the ProjectComponent instance's vcsInitialized bool value.
If VCS is not initialzied, listen the VCS_CONFIGURATION_CHANGED.
But this code output like this.
projectOpened() -> intellij-plugin
else isVcsInitialized
finish subscribe
DirectoryMappingChanged:intellij-plugin
The code should outpout
toolWindow:directoryMappingChanged
(This is in VcsListener#directoryMappingChanged()).
But no output come and code does not run.
This means that when the code is subscribing the topic by
project.getMessageBus().connect().subscribe()
the event of VCS_CONFIGURATION_CHANGED is happened.
So the code cannot run.
How should I do with this??
Please sign in to leave a comment.
Looks like a wrong approach. What are you trying to achieve? Why your toolwindow optionally depends on your project component?