本文整理汇总了Java中com.alibaba.dubbo.common.URL.addParameter方法的典型用法代码示例。如果您正苦于以下问题:Java URL.addParameter方法的具体用法?Java URL.addParameter怎么用?Java URL.addParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.common.URL
的用法示例。
在下文中一共展示了URL.addParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enableRoute
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
public void enableRoute(Long id) {
if (id == null) {
throw new IllegalStateException("no route id");
}
URL oldRoute = findRouteUrl(id);
if (oldRoute == null) {
throw new IllegalStateException("Route was changed!");
}
if (oldRoute.getParameter("enabled", true)) {
return;
}
registryService.unregister(oldRoute);
URL newRoute = oldRoute.addParameter("enabled", true);
registryService.register(newRoute);
}
示例2: createServer
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
private ExchangeServer createServer(URL url) {
//默认开启server关闭时发送readonly事件
url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString());
//默认开启heartbeat
url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT));
String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER);
if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str))
throw new RpcException("Unsupported server type: " + str + ", url: " + url);
url = url.addParameter(Constants.CODEC_KEY, Version.isCompatibleVersion() ? COMPATIBLE_CODEC_NAME : DubboCodec.NAME);
ExchangeServer server;
try {
server = Exchangers.bind(url, requestHandler);
} catch (RemotingException e) {
throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e);
}
str = url.getParameter(Constants.CLIENT_KEY);
if (str != null && str.length() > 0) {
Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions();
if (!supportedTypes.contains(str)) {
throw new RpcException("Unsupported client type: " + str);
}
}
return server;
}
示例3: disableOverride
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
public void disableOverride(Long id) {
if(id == null) {
throw new IllegalStateException("no override id");
}
URL oldProvider = findOverrideUrl(id);
if(oldProvider == null) {
throw new IllegalStateException("Override was changed!");
}
if(!oldProvider.getParameter("enabled", true)) {
return;
}
URL newProvider = oldProvider.addParameter("enabled", false);
registryService.unregister(oldProvider);
registryService.register(newProvider);
}
示例4: enableRoute
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
public void enableRoute(Long id) {
if(id == null) {
throw new IllegalStateException("no route id");
}
URL oldRoute = findRouteUrl(id);
if(oldRoute == null) {
throw new IllegalStateException("Route was changed!");
}
if(oldRoute.getParameter("enabled", true)) {
return;
}
registryService.unregister(oldRoute);
URL newRoute= oldRoute.addParameter("enabled", true);
registryService.register(newRoute);
}
示例5: testFail
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
@Test(expected = RpcException.class)
public void testFail() throws Exception {
URL url = URL.valueOf("test://test");
url = url.addParameter(Constants.INTERFACE_KEY,
"com.alibaba.dubbo.rpc.file.TpsService");
url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5);
Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
Invocation invocation = new MockInvocation();
for (int i = 0; i < 10; i++) {
try {
filter.invoke(invoker, invocation);
} catch (Exception e) {
assertTrue(i >= 5);
throw e;
}
}
}
示例6: testIsServiceKeyMatch
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
@Test
public void testIsServiceKeyMatch() throws Exception {
URL url = URL.valueOf("test://127.0.0.0");
URL pattern = url.addParameter(Constants.GROUP_KEY, "test")
.addParameter(Constants.INTERFACE_KEY, "test")
.addParameter(Constants.VERSION_KEY, "test");
URL value = pattern;
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
pattern = pattern.addParameter(Constants.GROUP_KEY, "*");
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
pattern = pattern.addParameter(Constants.VERSION_KEY, "*");
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
}
示例7: testClientHeartbeat
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
@Test
public void testClientHeartbeat() throws Exception {
FakeChannelHandlers.setTestingChannelHandlers();
URL serverURL = URL.valueOf("header://localhost:55555");
TestHeartbeatHandler handler = new TestHeartbeatHandler();
server = Exchangers.bind(serverURL, handler);
System.out.println("Server bind successfully");
FakeChannelHandlers.resetChannelHandlers();
serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000);
client = Exchangers.connect(serverURL);
Thread.sleep(10000);
Assert.assertTrue(handler.connectCount > 0);
System.out.println("connect count " + handler.connectCount);
}
示例8: testServerHeartbeat
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
@Test
public void testServerHeartbeat() throws Exception {
URL serverURL = URL.valueOf("header://localhost:55555");
serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000);
TestHeartbeatHandler handler = new TestHeartbeatHandler();
server = Exchangers.bind(serverURL, handler);
System.out.println("Server bind successfully");
FakeChannelHandlers.setTestingChannelHandlers();
serverURL = serverURL.removeParameter(Constants.HEARTBEAT_KEY);
client = Exchangers.connect(serverURL);
Thread.sleep(10000);
Assert.assertTrue(handler.disconnectCount > 0);
System.out.println("disconnect count " + handler.disconnectCount);
}
示例9: testHeartbeat
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
@Test
public void testHeartbeat() throws Exception {
URL serverURL = URL.valueOf("header://localhost:55555");
serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000);
TestHeartbeatHandler handler = new TestHeartbeatHandler();
server = Exchangers.bind(serverURL, handler);
System.out.println("Server bind successfully");
client = Exchangers.connect(serverURL);
Thread.sleep(10000);
System.err.println("++++++++++++++ disconnect count " + handler.disconnectCount);
System.err.println("++++++++++++++ connect count " + handler.connectCount);
Assert.assertTrue(handler.disconnectCount == 0);
Assert.assertTrue(handler.connectCount == 1);
}
示例10: LazyConnectExchangeClient
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
public LazyConnectExchangeClient(URL url, ExchangeHandler requestHandler) {
//lazy connect ,need set send.reconnect = true, to avoid channel bad status.
this.url = url.addParameter(Constants.SEND_RECONNECT_KEY, Boolean.TRUE.toString());
this.requestHandler = requestHandler;
this.initialState = url.getParameter(Constants.LAZY_CONNECT_INITIAL_STATE_KEY,Constants.DEFAULT_LAZY_CONNECT_INITIAL_STATE);
this.requestWithWarning = url.getParameter(REQUEST_WITH_WARNING_KEY, false);
}
示例11: setThreadName
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
/**
* append thread name with url address
* @return new url with updated thread name
*/
public static URL setThreadName(URL url, String defaultName) {
String name = url.getParameter(Constants.THREAD_NAME_KEY, defaultName);
name = new StringBuilder(32).append(name).append("-").append(url.getAddress()).toString();
url = url.addParameter(Constants.THREAD_NAME_KEY, name);
return url;
}
示例12: test_getAdaptiveExtension_customizeAdaptiveKey
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
@Test
public void test_getAdaptiveExtension_customizeAdaptiveKey() throws Exception {
SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();
Map<String, String> map = new HashMap<String, String>();
map.put("key2", "impl2");
URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);
String echo = ext.yell(url, "haha");
assertEquals("Ext1Impl2-yell", echo);
url = url.addParameter("key1", "impl3"); // 注意: URL是值类型
echo = ext.yell(url, "haha");
assertEquals("Ext1Impl3-yell", echo);
}
示例13: mergeUrl
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
/**
* 合并url参数 顺序为override > -D >Consumer > Provider
* @param providerUrl
* @param overrides
* @return
*/
private URL mergeUrl(URL providerUrl){
providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // 合并消费端参数
List<Configurator> localConfigurators = this.configurators; // local reference
if (localConfigurators != null && localConfigurators.size() > 0) {
for (Configurator configurator : localConfigurators) {
providerUrl = configurator.configure(providerUrl);
}
}
providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // 不检查连接是否成功,总是创建Invoker!
//directoryUrl 与 override 合并是在notify的最后,这里不能够处理
this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // 合并提供者参数
if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0)
&& "dubbo".equals(providerUrl.getProtocol())) { // 兼容1.0
//fix by tony.chenl DUBBO-44
String path = directoryUrl.getParameter(Constants.INTERFACE_KEY);
if (path != null) {
int i = path.indexOf('/');
if (i >= 0) {
path = path.substring(i + 1);
}
i = path.lastIndexOf(':');
if (i >= 0) {
path = path.substring(0, i);
}
providerUrl = providerUrl.setPath(path);
}
}
return providerUrl;
}
示例14: notify
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
public void notify(List<URL> urls) {
List<URL> result = null;
for (URL url : urls) {
URL overrideUrl = url;
if (url.getParameter(Constants.CATEGORY_KEY) == null
&& Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) {
// 兼容旧版本
overrideUrl = url.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
}
if (! UrlUtils.isMatch(subscribeUrl, overrideUrl)) {
if (result == null) {
result = new ArrayList<URL>(urls);
}
result.remove(url);
logger.warn("Subsribe category=configurator, but notifed non-configurator urls. may be registry bug. unexcepted url: " + url);
}
}
if (result != null) {
urls = result;
}
this.configurators = RegistryDirectory.toConfigurators(urls);
List<ExporterChangeableWrapper<?>> exporters = new ArrayList<ExporterChangeableWrapper<?>>(bounds.values());
for (ExporterChangeableWrapper<?> exporter : exporters){
Invoker<?> invoker = exporter.getOriginInvoker();
final Invoker<?> originInvoker ;
if (invoker instanceof InvokerDelegete){
originInvoker = ((InvokerDelegete<?>)invoker).getInvoker();
}else {
originInvoker = invoker;
}
URL originUrl = RegistryProtocol.this.getProviderUrl(originInvoker);
URL newUrl = getNewInvokerUrl(originUrl, urls);
if (! originUrl.equals(newUrl)){
RegistryProtocol.this.doChangeLocalExport(originInvoker, newUrl);
}
}
}
示例15: loadRegistries
import com.alibaba.dubbo.common.URL; //导入方法依赖的package包/类
protected List<URL> loadRegistries(boolean provider) {
//检查注册中心配置,并填充各种Registry属性
checkRegistry();
//存放注册中心的URL
List<URL> registryList = new ArrayList<URL>();
if (registries != null && registries.size() > 0) {
//遍历注册中心配置
for (RegistryConfig config : registries) {
//获取配置中的注册中心地址
String address = config.getAddress();
if (address == null || address.length() == 0) {
//没配置,使用默认的0.0.0.0
address = Constants.ANYHOST_VALUE;
}
//尝试从系统属性中获取
String sysaddress = System.getProperty("dubbo.registry.address");
if (sysaddress != null && sysaddress.length() > 0) {
address = sysaddress;
}
if (address != null && address.length() > 0
&& ! RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) {
Map<String, String> map = new HashMap<String, String>();
//配置的application中的属性取出来放到map中
appendParameters(map, application);
//配置的registry中的属性取出来放到map中
appendParameters(map, config);
//服务名
map.put("path", RegistryService.class.getName());
//dubbo的版本
map.put("dubbo", Version.getVersion());
//时间戳
map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
//pid
if (ConfigUtils.getPid() > 0) {
map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
}
//map中不存在protocol,说明没有配置procotol
if (! map.containsKey("protocol")) {
//查看有没有名为remote的Registry的实现类
if (ExtensionLoader.getExtensionLoader(RegistryFactory.class).hasExtension("remote")) {
map.put("protocol", "remote");
} else {//没有的话Protocol使用dubbo
map.put("protocol", "dubbo");
}
}
//解析生成url
//zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-provider&application.version=1.0&
// dubbo=2.5.3&environment=product&organization=china&owner=cheng.xi&pid=17268×tamp=1488986530185
List<URL> urls = UrlUtils.parseURLs(address, map);
for (URL url : urls) {
url = url.addParameter(Constants.REGISTRY_KEY, url.getProtocol());
url = url.setProtocol(Constants.REGISTRY_PROTOCOL);
if ((provider && url.getParameter(Constants.REGISTER_KEY, true))
|| (! provider && url.getParameter(Constants.SUBSCRIBE_KEY, true))) {
registryList.add(url);
}
}
}
}
}
//返回的url为registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-provider&application.version=1.0&dubbo=2.5.3&
// environment=product&organization=china&owner=cheng.xi&pid=17268®istry=zookeeper×tamp=1488986530185
return registryList;
}