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

请教关于RpcClient#create的问题 #1

Open
baihezhuo opened this issue Dec 14, 2018 · 0 comments
Open

请教关于RpcClient#create的问题 #1

baihezhuo opened this issue Dec 14, 2018 · 0 comments

Comments

@baihezhuo
Copy link

大神您好,请教一下创建一个rpc代理,也就是demo中:rpcClient.create(HelloService.class) 这个方法里面,关于代理对象ObjectProxy#invoke方法里,有一段代码不是很明白:
RpcClientHandler handler = ConnectManager.getInstance().chooseHandler();
这里我看到是从列表中size取模选择一个可用的handler返回,但是没有明白为什么ConnectManager是单例模式,是不是这个代码不支持多个不同的provider(可能服务地址和接口不同的情况),我怕理解错误,向大神请教一下,虽然仅仅是一个demo easy rpc 但是也 获益良多 感谢分享~

public RpcClientHandler chooseHandler() {
CopyOnWriteArrayList handlers = (CopyOnWriteArrayList) this.connectedHandlers.clone();
int size = handlers.size();
while (isRunning && size <= 0) {
try {
boolean available = waitingForHandler();
if (available) {
handlers = (CopyOnWriteArrayList) this.connectedHandlers.clone();
size = handlers.size();
}
} catch (InterruptedException e) {
LOGGER.error("Waiting for available node is interrupted! ", e);
throw new RuntimeException("Can't connect any servers!", e);
}
}
int index = (roundRobin.getAndAdd(1) + size) % size;
return handlers.get(index);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant