本文整理了Java中com.weibo.api.motan.rpc.URL.createCopy()
方法的一些代码示例,展示了URL.createCopy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URL.createCopy()
方法的具体详情如下:
包路径:com.weibo.api.motan.rpc.URL
类名称:URL
方法名:createCopy
暂无
代码示例来源:origin: weibocom/motan
protected List<URL> getCachedUrls(URL url) {
Map<String, List<URL>> rsUrls = subscribedCategoryResponses.get(url);
if (rsUrls == null || rsUrls.size() == 0) {
return null;
}
List<URL> urls = new ArrayList<URL>();
for (List<URL> us : rsUrls.values()) {
for (URL tempUrl : us) {
urls.add(tempUrl.createCopy());
}
}
return urls;
}
代码示例来源:origin: weibocom/motan
/**
* 防止数据在外部被变更,因此copy一份
*
* @return
*/
public Map<String, List<URL>> getAllUrl() {
Map<String, List<URL>> copyMap = new HashMap<String, List<URL>>(registeredServices.size());
for (Map.Entry<String, List<URL>> entry : registeredServices.entrySet()) {
String key = entry.getKey();
List<URL> copyList = new ArrayList<URL>(entry.getValue().size());
for (URL url : entry.getValue()) {
copyList.add(url.createCopy());
}
copyMap.put(key, copyList);
}
return copyMap;
}
代码示例来源:origin: weibocom/motan
@SuppressWarnings("unchecked")
@Override
public List<URL> discover(URL url) {
if (url == null) {
LoggerUtil.warn("[{}] discover with malformed param, refUrl is null", registryClassName);
return Collections.EMPTY_LIST;
}
url = url.createCopy();
List<URL> results = new ArrayList<URL>();
Map<String, List<URL>> categoryUrls = subscribedCategoryResponses.get(url);
if (categoryUrls != null && categoryUrls.size() > 0) {
for (List<URL> urls : categoryUrls.values()) {
for (URL tempUrl : urls) {
results.add(tempUrl.createCopy());
}
}
} else {
List<URL> urlsDiscovered = doDiscover(url);
if (urlsDiscovered != null) {
for (URL u : urlsDiscovered) {
results.add(u.createCopy());
}
}
}
return results;
}
代码示例来源:origin: weibocom/motan
private URL toSubscribeUrl(URL url) {
URL subUrl = url.createCopy();
subUrl.addParameter(URLParamType.nodeType.getName(), MotanConstants.NODE_TYPE_SERVICE);
return subUrl;
}
代码示例来源:origin: weibocom/motan
public AbstractRegistry(URL url) {
this.registryUrl = url.createCopy();
// register a heartbeat switcher to perceive service state change and change available state
MotanSwitcherUtil.initSwitcher(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, false);
MotanSwitcherUtil.registerSwitcherListener(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, new SwitcherListener() {
@Override
public void onValueChanged(String key, Boolean value) {
if (key != null && value != null) {
if (value) {
available(null);
} else {
unavailable(null);
}
}
}
});
}
代码示例来源:origin: weibocom/motan
public List<URL> commandPreview(URL url, RpcCommand rpcCommand, String previewIP) {
List<URL> finalResult;
URL urlCopy = url.createCopy();
if (rpcCommand != null) {
CommandServiceManager manager = getCommandServiceManager(urlCopy);
finalResult = manager.discoverServiceWithCommand(urlCopy, new HashMap<String, Integer>(), rpcCommand, previewIP);
} else {
finalResult = discoverService(urlCopy);
}
return finalResult;
}
代码示例来源: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
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
@Override
protected void doUnsubscribe(URL url, NotifyListener listener) {
LoggerUtil.info("CommandFailbackRegistry unsubscribe. url: " + url.toSimpleString());
URL urlCopy = url.createCopy();
CommandServiceManager manager = commandManagerMap.get(urlCopy);
manager.removeNotifyListener(listener);
unsubscribeService(urlCopy, manager);
unsubscribeCommand(urlCopy, manager);
}
代码示例来源:origin: weibocom/motan
@Override
public void unregister(URL url) {
if (url == null) {
LoggerUtil.warn("[{}] unregister with malformed param, url is null", registryClassName);
return;
}
LoggerUtil.info("[{}] Url ({}) will unregister to Registry [{}]", registryClassName, url, registryUrl.getIdentity());
doUnregister(removeUnnecessaryParmas(url.createCopy()));
registeredServiceUrls.remove(url);
}
代码示例来源:origin: weibocom/motan
@Override
public void subscribe(URL url, NotifyListener listener) {
if (url == null || listener == null) {
LoggerUtil.warn("[{}] subscribe with malformed param, url:{}, listener:{}", registryClassName, url, listener);
return;
}
LoggerUtil.info("[{}] Listener ({}) will subscribe to url ({}) in Registry [{}]", registryClassName, listener, url,
registryUrl.getIdentity());
doSubscribe(url.createCopy(), listener);
}
代码示例来源:origin: weibocom/motan
@Override
public void unsubscribe(URL url, NotifyListener listener) {
if (url == null || listener == null) {
LoggerUtil.warn("[{}] unsubscribe with malformed param, url:{}, listener:{}", registryClassName, url, listener);
return;
}
LoggerUtil.info("[{}] Listener ({}) will unsubscribe from url ({}) in Registry [{}]", registryClassName, listener, url,
registryUrl.getIdentity());
doUnsubscribe(url.createCopy(), listener);
}
代码示例来源:origin: weibocom/motan
@Override
public RestServer createServer(URL url) {
String ipPort = url.getServerPortStr();
String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
LoggerUtil.info(this.getClass().getSimpleName() + " create share_channel server: url={}", url);
synchronized (ipPort2ServerShareChannel) {
RestServer server = ipPort2ServerShareChannel.get(ipPort);
if (server != null) {
saveEndpoint2Urls(server2UrlsShareChannel, server, protocolKey);
return server;
}
url = url.createCopy();
url.setPath(""); // 共享server端口,由于有多个interfaces存在,所以把path设置为空
server = innerCreateServer(url);
server.start();
ipPort2ServerShareChannel.put(ipPort, server);
saveEndpoint2Urls(server2UrlsShareChannel, server, protocolKey);
return server;
}
}
代码示例来源:origin: weibocom/motan
@Override
public void available(URL url) {
LoggerUtil.info("[{}] Url ({}) will set to available to Registry [{}]", registryClassName, url, registryUrl.getIdentity());
if (url != null) {
doAvailable(removeUnnecessaryParmas(url.createCopy()));
} else {
doAvailable(null);
}
}
代码示例来源:origin: weibocom/motan
@Override
public void unavailable(URL url) {
LoggerUtil.info("[{}] Url ({}) will set to unavailable to Registry [{}]", registryClassName, url, registryUrl.getIdentity());
if (url != null) {
doUnavailable(removeUnnecessaryParmas(url.createCopy()));
} else {
doUnavailable(null);
}
}
代码示例来源:origin: weibocom/motan
@Override
public void notifyService(URL serviceUrl, URL registryUrl, List<URL> urls) {
if (registry == null) {
throw new MotanFrameworkException("registry must be set.");
}
URL urlCopy = serviceUrl.createCopy();
String groupName = urlCopy.getParameter(URLParamType.group.getName(), URLParamType.group.getValue());
groupServiceCache.put(groupName, urls);
List<URL> finalResult = new ArrayList<URL>();
if (commandCache != null) {
Map<String, Integer> weights = new HashMap<String, Integer>();
finalResult = discoverServiceWithCommand(refUrl, weights, commandCache);
} else {
LoggerUtil.info("command cache is null. service:" + serviceUrl.toSimpleString());
// 没有命令时,只返回这个manager实际group对应的结果
finalResult.addAll(discoverOneGroup(refUrl));
}
for (NotifyListener notifyListener : notifySet) {
notifyListener.notify(registry.getUrl(), finalResult);
}
}
代码示例来源:origin: weibocom/motan
@Override
public void register(URL url) {
if (url == null) {
LoggerUtil.warn("[{}] register with malformed param, url is null", registryClassName);
return;
}
LoggerUtil.info("[{}] Url ({}) will register to Registry [{}]", registryClassName, url, registryUrl.getIdentity());
doRegister(removeUnnecessaryParmas(url.createCopy()));
registeredServiceUrls.add(url);
// available if heartbeat switcher already open
if (MotanSwitcherUtil.isOpen(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER)) {
available(url);
}
}
代码示例来源:origin: weibocom/motan
@Override
protected void doSubscribe(URL url, final NotifyListener listener) {
LoggerUtil.info("CommandFailbackRegistry subscribe. url: " + url.toSimpleString());
URL urlCopy = url.createCopy();
CommandServiceManager manager = getCommandServiceManager(urlCopy);
manager.addNotifyListener(listener);
subscribeService(urlCopy, manager);
subscribeCommand(urlCopy, manager);
List<URL> urls = doDiscover(urlCopy);
if (urls != null && urls.size() > 0) {
this.notify(urlCopy, listener, urls);
}
}
代码示例来源:origin: weibocom/motan
@Override
protected List<URL> doDiscover(URL url) {
LoggerUtil.info("CommandFailbackRegistry discover. url: " + url.toSimpleString());
List<URL> finalResult;
URL urlCopy = url.createCopy();
String commandStr = discoverCommand(urlCopy);
RpcCommand rpcCommand = null;
if (StringUtils.isNotEmpty(commandStr)) {
rpcCommand = RpcCommandUtil.stringToCommand(commandStr);
}
LoggerUtil.info("CommandFailbackRegistry discover command. commandStr: " + commandStr + ", rpccommand "
+ (rpcCommand == null ? "is null." : "is not null."));
if (rpcCommand != null) {
rpcCommand.sort();
CommandServiceManager manager = getCommandServiceManager(urlCopy);
finalResult = manager.discoverServiceWithCommand(urlCopy, new HashMap<String, Integer>(), rpcCommand);
// 在subscribeCommon时,可能订阅完马上就notify,导致首次notify指令时,可能还有其他service没有完成订阅,
// 此处先对manager更新指令,避免首次订阅无效的问题。
manager.setCommandCache(commandStr);
} else {
finalResult = discoverService(urlCopy);
}
LoggerUtil.info("CommandFailbackRegistry discover size: " + (finalResult == null ? "0" : finalResult.size()));
return finalResult;
}
代码示例来源:origin: weibocom/motan
url = url.createCopy();
url.setPath(""); // 共享server端口,由于有多个interfaces存在,所以把path设置为空
内容来源于网络,如有侵权,请联系作者删除!