Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the problem that the service was offline for a long time without re-registration #10182

Merged
merged 1 commit into from Jun 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -46,6 +46,9 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
Expand Down Expand Up @@ -296,6 +299,15 @@ public void nodeChanged() throws Exception {

static class CuratorWatcherImpl implements CuratorWatcher {

private static final ExecutorService CURATOR_WATCHER_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName("Dubbo-CuratorWatcher-Thread");
return thread;
}
});

Comment on lines +302 to +310
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace to use org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository#getSharedExecutor.

getUrl().getOrDefaultFrameworkModel().getBeanFactory()
            .getBean(FrameworkExecutorRepository.class).getSharedExecutor();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace to use org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository#getSharedExecutor.

getUrl().getOrDefaultFrameworkModel().getBeanFactory()
            .getBean(FrameworkExecutorRepository.class).getSharedExecutor();

The FrameworkExecutorRepository class is available after 3.0 branch, but my code is master branch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get. Would you please submit a pr base on 3.0 branch after this pr merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

private CuratorFramework client;
private volatile ChildListener childListener;
private String path;
Expand All @@ -322,7 +334,17 @@ public void process(WatchedEvent event) throws Exception {
}

if (childListener != null) {
childListener.childChanged(path, client.getChildren().usingWatcher(this).forPath(path));
Runnable task = new Runnable() {
@Override
public void run() {
try {
childListener.childChanged(path, client.getChildren().usingWatcher(CuratorWatcherImpl.this).forPath(path));
} catch (Exception e) {
logger.warn("client get children error", e);
}
}
};
CURATOR_WATCHER_EXECUTOR_SERVICE.execute(task);
}
}
}
Expand Down