本文整理汇总了Java中com.alibaba.dubbo.config.ReferenceConfig.get方法的典型用法代码示例。如果您正苦于以下问题:Java ReferenceConfig.get方法的具体用法?Java ReferenceConfig.get怎么用?Java ReferenceConfig.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.config.ReferenceConfig
的用法示例。
在下文中一共展示了ReferenceConfig.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProxy
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
public Object getProxy(String interfaceClass) {
Set<Entry<Class<?>, Object>> entrySet = interfaceMapProxy.entrySet();
for (Entry<Class<?>, Object> entry : entrySet) {
if (entry.getKey().getName().equals(interfaceClass)) { return entry.getValue(); }
}
for (ServiceBean<?> service : services) {
if (interfaceClass.equals(service.getInterfaceClass().getName())) {
ReferenceConfig<Object> reference = new ReferenceConfig<Object>();
reference.setApplication(service.getApplication());
reference.setRegistry(service.getRegistry());
reference.setRegistries(service.getRegistries());
reference.setInterface(service.getInterfaceClass());
reference.setVersion(service.getVersion());
interfaceMapProxy.put(service.getInterfaceClass(), reference.get());
return reference.get();
}
}
return null;
}
示例2: createClient
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums){
ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
referenceConfig.setInterface(cls);
StringBuilder url = new StringBuilder();
url.append("dubbo://");
url.append(targetIP);
url.append(":");
url.append(targetPort);
url.append("/");
url.append(cls.getName());
referenceConfig.setUrl(url.toString());
// hardcode
referenceConfig.setConnections(clientNums);
ApplicationConfig application = new ApplicationConfig();
application.setName("dubbo_consumer");
referenceConfig.setApplication(application);
referenceConfig.setTimeout(connectTimeout);
return referenceConfig.get();
}
示例3: testSystemPropertyOverrideReferenceConfig
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@Test
public void testSystemPropertyOverrideReferenceConfig() throws Exception {
System.setProperty("dubbo.reference.retries", "5");
try {
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
service.setProtocol(protocolConfig);
service.export();
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setInterface(DemoService.class);
reference.setInjvm(true);
reference.setRetries(2);
reference.get();
assertEquals(Integer.valueOf(5), reference.getRetries());
} finally {
System.setProperty("dubbo.reference.retries", "");
}
}
示例4: createClient
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums, String protocol, String serialization){
ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
referenceConfig.setInterface(cls);
StringBuilder url = new StringBuilder();
url.append(protocol);
url.append("://");
url.append(targetIP);
url.append(":");
url.append(targetPort);
url.append("/");
url.append(cls.getName());
url.append("?optimizer=com.alibaba.dubbo.rpc.benchmark.SerializationOptimizerImpl");
if (!StringUtils.isEmpty(serialization)) {
url.append("&serialization=");
url.append(serialization);
}
referenceConfig.setUrl(url.toString());
// hardcode
referenceConfig.setConnections(clientNums);
ApplicationConfig application = new ApplicationConfig();
application.setName("dubbo_consumer");
referenceConfig.setApplication(application);
referenceConfig.setTimeout(connectTimeout);
return referenceConfig.get();
}
示例5: main
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
public static void main(String[] args) {
ApplicationConfig application = new ApplicationConfig();
application.setName("demo-consumer");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("zookeeper://127.0.0.1:2181");
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
reference.setApplication(application);
reference.setRegistry(registry);
reference.setInterface(DemoService.class);
reference.setVersion("1.0.0");
DemoService demoService = reference.get();
System.out.println(demoService.sayHello("hongxi"));
}
示例6: createClient
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
/**
* 创建连接到该service上的reference bean的客户端配置实例,好吧,实际上核心就是一个url地址
*
* @param cls
* @param targetIP
* @param targetPort
* @param connectTimeout
* @param clientNums
* @return
*/
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums){
ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
referenceConfig.setInterface(cls);
StringBuilder url = new StringBuilder();
url.append("dubbo://");
url.append(targetIP);
url.append(":");
url.append(targetPort);
url.append("/");
url.append(cls.getName());
referenceConfig.setUrl(url.toString());
// hardcode
referenceConfig.setConnections(clientNums);
ApplicationConfig application = new ApplicationConfig(); // 在这个里面有注册中心列表
application.setName("dubbo_consumer");
referenceConfig.setApplication(application);
referenceConfig.setTimeout(connectTimeout);
return referenceConfig.get();
}
示例7: createClient
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout, int clientNums) {
ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
referenceConfig.setInterface(cls);
StringBuilder url = new StringBuilder();
url.append("dubbo://");
url.append(targetIP);
url.append(":");
url.append(targetPort);
url.append("/");
url.append(cls.getName());
referenceConfig.setUrl(url.toString());
// hardcode
referenceConfig.setConnections(clientNums);
ApplicationConfig application = new ApplicationConfig();
application.setName("dubbo_consumer");
referenceConfig.setApplication(application);
referenceConfig.setTimeout(connectTimeout);
return referenceConfig.get();
}
示例8: refer
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
private DemoService refer(String url) {
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setApplication(new ApplicationConfig("consumer"));
reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
reference.setInterface(DemoService.class);
reference.setUrl(url);
return reference.get();
}
示例9: testReferGenericExport
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@Test
public void testReferGenericExport() throws Exception {
ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export");
RegistryConfig rc = new RegistryConfig();
rc.setAddress(RegistryConfig.NO_AVAILABLE);
ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
sc.setApplication(ac);
sc.setRegistry(rc);
sc.setInterface(DemoService.class.getName());
sc.setRef(new GenericService() {
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
return null;
}
});
ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
ref.setApplication(ac);
ref.setRegistry(rc);
ref.setInterface(DemoService.class.getName());
try {
sc.export();
ref.get();
Assert.fail();
} catch (Exception e) {
e.printStackTrace();
} finally {
sc.unexport();
ref.destroy();
}
}
示例10: get
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(ReferenceConfig<T> referenceConfig) {
String key = generator.generateKey(referenceConfig);
ReferenceConfig<?> config = cache.get(key);
if(config != null) {
return (T) config.get();
}
cache.putIfAbsent(key, referenceConfig);
config = cache.get(key);
return (T) config.get();
}
示例11: getRemoteService
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
/**
* 从远程注册中心获取服务
*
* @param clazz 接口Class对象
* @param version 服务版本
* @param <T> T
* @return 对应服务
*/
private <T> T getRemoteService(Class<T> clazz, String... version) {
// 引用远程服务
ReferenceConfig<T> reference = new ReferenceConfig<>();
reference.setApplication(application);
reference.setRegistry(registry);
if (version != null && version.length != 0) {
reference.setVersion(version[0]);
}
reference.setTimeout(10000);
reference.setInterface(clazz);
return reference.get();
}
示例12: connectRegistry
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
public void connectRegistry() {
Long s = System.currentTimeMillis();
ReferenceConfig<RegistryService> reference = new ReferenceConfig<RegistryService>();
reference.setApplication(application);
reference.setRegistries(registryList); // 多个注册中心可以用setRegistries()
reference.setInterface(RegistryService.class); // 弱类型接口名
reference.setRetries(0);
reference.setTimeout(5000);
RegistryService registryService = reference.get();
Long t = System.currentTimeMillis() - s;
logger.info("connectRegistry success ,spend time=" + t + "ms");
}
示例13: get
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(ReferenceConfig<T> referenceConfig) {
String key = generator.generateKey(referenceConfig);
ReferenceConfig<?> config = cache.get(key);
if (config != null) {
return (T) config.get();
}
cache.putIfAbsent(key, referenceConfig);
config = cache.get(key);
return (T) config.get();
}
示例14: get
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(ReferenceConfig<T> referenceConfig) {
String key = generator.generateKey(referenceConfig);
ReferenceConfig<?> config = cache.get(key);
if(config != null) {
return (T) config.get();// 调用config中解析文件配置获取
}
cache.putIfAbsent(key, referenceConfig);
config = cache.get(key);
return (T) config.get();
}
示例15: testAppendFilter
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@Test
public void testAppendFilter() throws Exception {
ProviderConfig provider = new ProviderConfig();
provider.setFilter("classloader,monitor");
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setFilter("accesslog,trace");
service.setProvider(provider);
service.setProtocol(new ProtocolConfig("dubbo", 20880));
service.setApplication(new ApplicationConfig("provider"));
service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
try {
service.export();
List<URL> urls = service.toUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
ConsumerConfig consumer = new ConsumerConfig();
consumer.setFilter("classloader,monitor");
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setFilter("accesslog,trace");
reference.setConsumer(consumer);
reference.setApplication(new ApplicationConfig("consumer"));
reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
reference.setInterface(DemoService.class);
reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
try {
reference.get();
urls = reference.toUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
} finally {
reference.destroy();
}
} finally {
service.unexport();
}
}