rpc.turbo.transport.client.MethodRouter Maven / Gradle / Ivy
The newest version!
package rpc.turbo.transport.client;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import rpc.turbo.invoke.InvokerUtils;
import rpc.turbo.loadbalance.LoadBalance;
import rpc.turbo.loadbalance.Weightable;
/**
*
* @author Hank
*
*/
final class MethodRouter {
private final Method method;
private final String serviceMethodName;
private final LoadBalance loadBalance;
MethodRouter(String serviceMethodName, LoadBalance loadBalance) {
this.method = InvokerUtils.toMethod(serviceMethodName);
this.serviceMethodName = serviceMethodName;
this.loadBalance = loadBalance;
}
void setConnectors(Collection connectors) {
if (connectors == null || connectors.size() == 0) {
loadBalance.setWeightables(Collections.emptyList());
return;
}
List supported = connectors.stream()//
.filter(t -> t.isSupport(serviceMethodName))//
.collect(Collectors.toList());
loadBalance.setWeightables(supported);
}
ConnectorContext selectConnector() {
return (ConnectorContext) loadBalance.select();
}
Method getMethod() {
return method;
}
String getServiceMethodName() {
return serviceMethodName;
}
}