public GrpcURL clearParameters() { return new GrpcURL(protocol, username, password, host, port, path, new HashMap<String, String>()); }
public GrpcURL setAddress(String address) { int i = address.lastIndexOf(':'); String host; int port = this.port; if (i >= 0) { host = address.substring(0, i); port = Integer.parseInt(address.substring(i + 1)); } else { host = address; } return new GrpcURL(protocol, username, password, host, port, path, getParameters()); }
public GrpcURL addParametersIfAbsent(Map<String, String> parameters) { if (parameters == null || parameters.size() == 0) { return this; } Map<String, String> map = new HashMap<String, String>(parameters); map.putAll(getParameters()); return new GrpcURL(protocol, username, password, host, port, path, map); }
public GrpcURL setPath(String path) { return new GrpcURL(protocol, username, password, host, port, path, getParameters()); }
public GrpcURL setUsername(String username) { return new GrpcURL(protocol, username, password, host, port, path, getParameters()); }
public GrpcURL setProtocol(String protocol) { return new GrpcURL(protocol, username, password, host, port, path, getParameters()); }
public GrpcURL setPassword(String password) { return new GrpcURL(protocol, username, password, host, port, path, getParameters()); }
public GrpcURL setHost(String host) { return new GrpcURL(protocol, username, password, host, port, path, getParameters()); }
public GrpcURL setPort(int port) { return new GrpcURL(protocol, username, password, host, port, path, getParameters()); }
public GrpcURL addParameter(String key, String value) { if (key == null || key.length() == 0 || value == null || value.length() == 0) { return this; } // 如果没有修改,直接返回。 if (value.equals(getParameters().get(key))) { // value != null return this; } Map<String, String> map = new HashMap<String, String>(getParameters()); map.put(key, value); return new GrpcURL(protocol, username, password, host, port, path, map); }
private GrpcEngine getGrpcEngine(String registryAddress, int registryPort) { String key = registryAddress + ":" + registryPort; LOCK.lock(); try { GrpcEngine engine = ENGINES.get(key); if (engine != null) { return engine; } Preconditions.checkNotNull(registryAddress, "registryAddress is not Null", registryAddress); Preconditions.checkState(registryPort != 0, "RegistryPort can not be zero", registryPort); GrpcURL registryUrl = new GrpcURL(Constants.REGISTRY_PROTOCOL, registryAddress, registryPort); engine = new GrpcEngine(registryUrl); ENGINES.put(key, engine); return engine; } finally { LOCK.unlock(); } }
public GrpcURL removeParameters(String... keys) { if (keys == null || keys.length == 0) { return this; } Map<String, String> map = new HashMap<String, String>(getParameters()); for (String key : keys) { map.remove(key); } if (map.size() == getParameters().size()) { return this; } return new GrpcURL(protocol, username, password, host, port, path, map); }
public GrpcURL addParameterIfAbsent(String key, String value) { if (key == null || key.length() == 0 || value == null || value.length() == 0) { return this; } if (hasParameter(key)) { return this; } Map<String, String> map = new HashMap<String, String>(getParameters()); map.put(key, value); return new GrpcURL(protocol, username, password, host, port, path, map); }
public GrpcURL addParameters(Map<String, String> parameters) { if (parameters == null || parameters.size() == 0) { return this; } boolean hasAndEqual = true; for (Map.Entry<String, String> entry : parameters.entrySet()) { String value = getParameters().get(entry.getKey()); if (value == null && entry.getValue() != null || !value.equals(entry.getValue())) { hasAndEqual = false; break; } } // 如果没有修改,直接返回。 if (hasAndEqual) return this; Map<String, String> map = new HashMap<String, String>(getParameters()); map.putAll(parameters); return new GrpcURL(protocol, username, password, host, port, path, map); }
return new GrpcURL(protocol, username, password, host, port, path, parameters);
int rpcPort = providerUrl.getPort(); int registryRpcPort = providerUrl.getParameter(Constants.REGISTRY_RPC_PORT_KEY, rpcPort); salukiMonitor.collect(new GrpcURL(Constants.MONITOR_PROTOCOL, host, //
String host = refUrl.getHost(); Integer port = refUrl.getPort(); clientServerMonitor.collect(new GrpcURL(Constants.MONITOR_PROTOCOL, host, port, // service + "/" + method, //
public synchronized void export() { Map<GrpcURL, Object> providerUrls = Maps.newHashMap(); for (RpcServiceSingleConfig<Object> singleServiceConfig : singleServiceConfigs) { String serviceName = singleServiceConfig.getServiceName(); Object serviceRef = singleServiceConfig.getRef(); Map<String, String> params = Maps.newHashMap(); this.addGroup(singleServiceConfig, params); this.addVersion(singleServiceConfig, params); this.addApplication(params); this.addInterval(params); this.addRegistryRpcPort(params); this.addHttpPort(params); GrpcURL providerUrl = new GrpcURL(Constants.REMOTE_PROTOCOL, super.getHost(), super.getRealityRpcPort(), serviceName, params); providerUrls.put(providerUrl, serviceRef); } try { internalServer = super.getGrpcEngine().getServer(providerUrls, super.getRealityRpcPort()).start(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } }
this.addHttpPort(params); this.addValidatorGroups(params); GrpcURL refUrl = new GrpcURL(Constants.REMOTE_PROTOCOL, super.getHost(), super.getHttpPort(), serviceName, params); ref = super.getGrpcEngine().getClient(refUrl);