本文整理了Java中com.weibo.api.motan.rpc.URL
类的一些代码示例,展示了URL
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URL
类的具体详情如下:
包路径:com.weibo.api.motan.rpc.URL
类名称:URL
[英]```
Desc a reffer or a service.
所有获取URL的parameter时(即带参数的getXXX方法),都必须返回对象,避免不经意的修改引发错误,因为
有些地方需要根据是否含这个参数来进行操作。
对于getXXX,当不带defaultValue时,如果不存在就返回null
[中]```
Desc a reffer or a service.
所有获取URL的parameter时(即带参数的getXXX方法),都必须返回对象,避免不经意的修改引发错误,因为
有些地方需要根据是否含这个参数来进行操作。
对于getXXX,当不带defaultValue时,如果不存在就返回null
代码示例来源:origin: weibocom/motan
public NettyClient(URL url) {
super(url);
maxClientConnection = url.getIntParameter(URLParamType.maxClientConnection.getName(),
URLParamType.maxClientConnection.getIntValue());
timeMonitorFuture = scheduledExecutor.scheduleWithFixedDelay(
new TimeoutMonitor("timeout_monitor_" + url.getHost() + "_" + url.getPort()),
MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD, MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD,
TimeUnit.MILLISECONDS);
}
代码示例来源:origin: weibocom/motan
protected ResteasyWebTarget innerCreateClient(URL url) {
ResteasyClient client = new ResteasyClientBuilder().build();
String contextpath = url.getParameter("contextpath", "/");
if (!contextpath.startsWith("/"))
contextpath = "/" + contextpath;
return client.target("http://" + url.getHost() + ":" + url.getPort() + contextpath);
}
代码示例来源:origin: weibocom/motan
/**
* protocol key: protocol://host:port/group/interface/version
*
* @param url
* @return
*/
public static String getProtocolKey(URL url) {
return url.getProtocol() + MotanConstants.PROTOCOL_SEPARATOR + url.getServerPortStr() + MotanConstants.PATH_SEPARATOR
+ url.getGroup() + MotanConstants.PATH_SEPARATOR + url.getPath() + MotanConstants.PATH_SEPARATOR + url.getVersion();
}
代码示例来源:origin: weibocom/motan
/**
* 根据url获取cluster信息,cluster 信息包括协议和path(rpc服务中的接口类)。
*
* @param url
* @return
*/
public static String getUrlClusterInfo(URL url) {
return url.getProtocol() + "-" + url.getPath();
}
代码示例来源:origin: weibocom/motan
public String toSimpleString() {
return getUri() + "?group=" + getGroup();
}
代码示例来源:origin: weibocom/motan
@Override
protected <T> Exporter<T> createExporter(Provider<T> provider, URL url) {
String ipPort = url.getServerPortStr();
GrpcServer server = serverMap.get(ipPort);
if (server == null) {
boolean shareChannel =
url.getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
int workerQueueSize = url.getIntParameter(URLParamType.workerQueueSize.getName(), URLParamType.workerQueueSize.getIntValue());
int minWorkerThread = 0, maxWorkerThread = 0;
if (shareChannel) {
minWorkerThread =
url.getIntParameter(URLParamType.minWorkerThread.getName(), MotanConstants.NETTY_SHARECHANNEL_MIN_WORKDER);
maxWorkerThread =
url.getIntParameter(URLParamType.maxWorkerThread.getName(), MotanConstants.NETTY_SHARECHANNEL_MAX_WORKDER);
} else {
minWorkerThread =
url.getIntParameter(URLParamType.minWorkerThread.getName(), MotanConstants.NETTY_NOT_SHARECHANNEL_MIN_WORKDER);
maxWorkerThread =
url.getIntParameter(URLParamType.maxWorkerThread.getName(), MotanConstants.NETTY_NOT_SHARECHANNEL_MAX_WORKDER);
}
ExecutorService executor =
new StandardThreadExecutor(minWorkerThread, maxWorkerThread, workerQueueSize, new DefaultThreadFactory("GrpcServer-"
+ url.getServerPortStr(), true));
server = new GrpcServer(url.getPort(), shareChannel, executor);
serverMap.putIfAbsent(ipPort, server);
server = serverMap.get(ipPort);
}
return new GrpcExporter<T>(provider, url, server);
}
代码示例来源:origin: weibocom/motan
private List<URL> mergeResult(URL url, Map<String, Integer> weights) {
List<URL> finalResult = new ArrayList<URL>();
if (weights.size() > 1) {
// 将所有group及权重拼接成一个rule的URL,并作为第一个元素添加到最终结果中
URL ruleUrl = new URL("rule", url.getHost(), url.getPort(), url.getPath());
StringBuilder weightsBuilder = new StringBuilder(64);
for (Map.Entry<String, Integer> entry : weights.entrySet()) {
weightsBuilder.append(entry.getKey()).append(':').append(entry.getValue()).append(',');
}
ruleUrl.addParameter(URLParamType.weights.getName(), weightsBuilder.deleteCharAt(weightsBuilder.length() - 1).toString());
finalResult.add(ruleUrl);
}
for (String key : weights.keySet()) {
if (groupServiceCache.containsKey(key)) {
finalResult.addAll(groupServiceCache.get(key));
} else {
URL urlTemp = url.createCopy();
urlTemp.addParameter(URLParamType.group.getName(), key);
finalResult.addAll(discoverOneGroup(urlTemp));
registry.subscribeService(urlTemp, this);
}
}
return finalResult;
}
代码示例来源:origin: weibocom/motan
public NettyClient(URL url) {
super(url);
timeMonitorFuture = scheduledExecutor.scheduleWithFixedDelay(
new TimeoutMonitor("timeout_monitor_" + url.getHost() + "_" + url.getPort()),
MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD, MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD,
TimeUnit.MILLISECONDS);
}
代码示例来源:origin: weibocom/motan
@Override
public Response request(Request request) throws TransportException {
int timeout = nettyClient.getUrl().getMethodParameter(request.getMethodName(), request.getParamtersDesc(), URLParamType.requestTimeout.getName(), URLParamType.requestTimeout.getIntValue());
if (timeout <= 0) {
throw new MotanFrameworkException("NettyClient init Error: timeout(" + timeout + ") <= 0 is forbid.", MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
MotanFrameworkUtil.logRequestEvent(request.getRequestId(), "after send rpc request " + nettyClient.getUrl().getServerPortStr(), System.currentTimeMillis());
response.addListener(new FutureListener() {
@Override
+ nettyClient.getUrl().getUri() + " local=" + localAddress + " "
+ MotanFrameworkUtil.toString(request), writeFuture.cause());
} else {
throw new MotanServiceException("NettyChannel send request to server Timeout: url="
+ nettyClient.getUrl().getUri() + " local=" + localAddress + " "
+ MotanFrameworkUtil.toString(request));
代码示例来源:origin: weibocom/motan
private List<URL> createSubscribeUrl(URL subscribeUrl) {
URL url = this.getUrl();
List result = new ArrayList(directUrls.size());
for (URL directUrl : directUrls) {
URL tmp = subscribeUrl.createCopy();
tmp.setHost(directUrl.getHost());
tmp.setPort(directUrl.getPort());
result.add(tmp);
}
return result;
}
代码示例来源:origin: weibocom/motan
/**
* 根据motan的url生成consul的serivce id。 serviceid 包括ip+port+rpc服务的接口类名
*
* @param url
* @return
*/
public static String convertConsulSerivceId(URL url) {
if (url == null) {
return null;
}
return convertServiceId(url.getHost(), url.getPort(), url.getPath());
}
代码示例来源:origin: weibocom/motan
public static String toNodePath(URL url, ZkNodeType nodeType) {
return toNodeTypePath(url, nodeType) + MotanConstants.PATH_SEPARATOR + url.getServerPortStr();
}
}
代码示例来源:origin: weibocom/motan
workerGroup = new NioEventLoopGroup();
boolean shareChannel = url.getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
url.getIntParameter(URLParamType.maxServerConnection.getName(), URLParamType.maxServerConnection.getIntValue());
int workerQueueSize = url.getIntParameter(URLParamType.workerQueueSize.getName(), 500);
minWorkerThread = url.getIntParameter(URLParamType.minWorkerThread.getName(), MotanConstants.NETTY_SHARECHANNEL_MIN_WORKDER);
maxWorkerThread = url.getIntParameter(URLParamType.maxWorkerThread.getName(), MotanConstants.NETTY_SHARECHANNEL_MAX_WORKDER);
} else {
minWorkerThread =
url.getIntParameter(URLParamType.minWorkerThread.getName(), MotanConstants.NETTY_NOT_SHARECHANNEL_MIN_WORKDER);
maxWorkerThread =
url.getIntParameter(URLParamType.maxWorkerThread.getName(), MotanConstants.NETTY_NOT_SHARECHANNEL_MAX_WORKDER);
final int maxContentLength = url.getIntParameter(URLParamType.maxContentLength.getName(), URLParamType.maxContentLength.getIntValue());
final NettyHttpRequestHandler handler =
new NettyHttpRequestHandler(this, messageHandler, new ThreadPoolExecutor(minWorkerThread, maxWorkerThread, 15,
f = b.bind(url.getPort()).sync();
channel = f.channel();
} catch (InterruptedException e) {
代码示例来源:origin: weibocom/motan
private synchronized void initServerBootstrap() {
boolean shareChannel = url.getBooleanParameter(URLParamType.shareChannel.getName(),
URLParamType.shareChannel.getBooleanValue());
final int maxContentLength = url.getIntParameter(URLParamType.maxContentLength.getName(),
URLParamType.maxContentLength.getIntValue());
int maxServerConnection = url.getIntParameter(URLParamType.maxServerConnection.getName(),
URLParamType.maxServerConnection.getIntValue());
int workerQueueSize = url.getIntParameter(URLParamType.workerQueueSize.getName(),
URLParamType.workerQueueSize.getIntValue());
minWorkerThread = url.getIntParameter(URLParamType.minWorkerThread.getName(),
MotanConstants.NETTY_SHARECHANNEL_MIN_WORKDER);
maxWorkerThread = url.getIntParameter(URLParamType.maxWorkerThread.getName(),
MotanConstants.NETTY_SHARECHANNEL_MAX_WORKDER);
} else {
minWorkerThread = url.getIntParameter(URLParamType.minWorkerThread.getName(),
MotanConstants.NETTY_NOT_SHARECHANNEL_MIN_WORKDER);
maxWorkerThread = url.getIntParameter(URLParamType.maxWorkerThread.getName(),
MotanConstants.NETTY_NOT_SHARECHANNEL_MAX_WORKDER);
new DefaultThreadFactory("NettyServer-" + url.getServerPortStr(), true));
standardThreadExecutor.prestartAllCoreThreads();
代码示例来源:origin: weibocom/motan
/**
* 默认策略当接口线程池占用达到3/4或者空闲小于150时,限制单个方法请求不能超过总线程数的1/2 需要自定义方法并发限制可以通过actives参数配置
*/
@Override
public void init(Caller<?> caller) {
if (caller instanceof Provider) {
String port = String.valueOf(caller.getUrl().getPort());
totalCount = portTotalMap.get(port);
if (totalCount == null) {
portTotalMap.putIfAbsent(port, new AtomicInteger());
totalCount = portTotalMap.get(port);
}
maxThread = caller.getUrl().getIntParameter(URLParamType.maxWorkerThread.getName(), URLParamType.maxWorkerThread.getIntValue());
totalLimit = maxThread > 600 ? maxThread - 150 : maxThread * 3 / 4;
int active = caller.getUrl().getIntParameter(URLParamType.actives.getName(), URLParamType.actives.getIntValue());
if (active > 0) {
methodLimit = active;
} else {
methodLimit = maxThread / 2;
}
isProvider = true;
}
}
代码示例来源:origin: weibocom/motan
public AbstractClient(URL url) {
this.url = url;
this.codec =
ExtensionLoader.getExtensionLoader(Codec.class).getExtension(
url.getParameter(URLParamType.codec.getName(), URLParamType.codec.getValue()));
LoggerUtil.info("init nettyclient. url:" + url.getHost() + "-" + url.getPath() + ", use codec:" + codec.getClass().getSimpleName());
}
代码示例来源:origin: weibocom/motan
channel.getUrl().getParameter(URLParamType.serialize.getName(), URLParamType.serialize.getValue()));
Boolean usegz = channel.getUrl().getBooleanParameter(URLParamType.usegz.getName(), URLParamType.usegz.getBooleanValue());
int minGzSize = channel.getUrl().getIntParameter(URLParamType.mingzSize.getName(), URLParamType.mingzSize.getIntValue());
return encode(compress(body, usegz, minGzSize), flag, request.getRequestId());
代码示例来源:origin: weibocom/motan
public FailbackRegistry(URL url) {
super(url);
long retryPeriod = url.getIntParameter(URLParamType.registryRetryPeriod.getName(), URLParamType.registryRetryPeriod.getIntValue());
retryExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
retry();
} catch (Exception e) {
LoggerUtil.warn(String.format("[%s] False when retry in failback registry", registryClassName), e);
}
}
}, retryPeriod, retryPeriod, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: weibocom/motan
String ipPort = url.getServerPortStr();
String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
url.getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
url = url.createCopy();
url.setPath(""); // 共享server端口,由于有多个interfaces存在,所以把path设置为空
代码示例来源:origin: weibocom/motan
public String getParameter(String name, String defaultValue) {
String value = getParameter(name);
if (value == null) {
return defaultValue;
}
return value;
}
内容来源于网络,如有侵权,请联系作者删除!