本文整理汇总了Java中com.alibaba.dubbo.config.ReferenceConfig类的典型用法代码示例。如果您正苦于以下问题:Java ReferenceConfig类的具体用法?Java ReferenceConfig怎么用?Java ReferenceConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReferenceConfig类属于com.alibaba.dubbo.config包,在下文中一共展示了ReferenceConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCaller
import com.alibaba.dubbo.config.ReferenceConfig; //导入依赖的package包/类
private GenericService getCaller(String appId, String busCode,EasyTransRequest<?,?> request) {
GenericService genericService = mapRef.get(getTargetKey(appId,busCode));
if(genericService == null){
List<Class<?>> typeArguments = ReflectUtil.getTypeArguments(EasyTransRequest.class, request.getClass());
Class<?> executorCLass = typeArguments.get(1);
RelativeInterface annotation = executorCLass.getAnnotation(RelativeInterface.class);
Class<?> value = annotation.value();
ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<GenericService>();
referenceConfig.setInterface(value.getName()); // 弱类型接口名
referenceConfig.setVersion("1.0.0");
referenceConfig.setGeneric(true); // 声明为泛化接口
referenceConfig.setApplication(new ApplicationConfig(applicationName));
referenceConfig.setRegistry(new RegistryConfig(dubboZkUrl));
referenceConfig.setGroup(appId + "-" + busCode);
referenceConfig.setCheck(false);
referenceConfig.setSticky(true);//设置粘滞连接以优化级联事务的级联提交性能
genericService = referenceConfig.get();
mapRef.put(getTargetKey(appId,busCode), genericService);
}
return genericService;
}
示例2: 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;
}
示例3: 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();
}
示例4: 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", "");
}
}
示例5: generateKey
import com.alibaba.dubbo.config.ReferenceConfig; //导入依赖的package包/类
public String generateKey(ReferenceConfig<?> referenceConfig) {
String iName = referenceConfig.getInterface();
if(StringUtils.isBlank(iName)) {
Class<?> clazz = referenceConfig.getInterfaceClass();
iName = clazz.getName();
}
if(StringUtils.isBlank(iName)) {
throw new IllegalArgumentException("No interface info in ReferenceConfig" + referenceConfig);
}
StringBuilder ret = new StringBuilder();
if(! StringUtils.isBlank(referenceConfig.getGroup())) {
ret.append(referenceConfig.getGroup()).append("/");
}
ret.append(iName);
if(! StringUtils.isBlank(referenceConfig.getVersion())) {
ret.append(":").append(referenceConfig.getVersion());
}
return ret.toString();
}
示例6: 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();
}
示例7: getService
import com.alibaba.dubbo.config.ReferenceConfig; //导入依赖的package包/类
public static <S> S getService(Class<S> c){
ApplicationConfig application = new ApplicationConfig();
application.setName("beast-litx");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("zookeeper://114.55.174.189:2181");
registry.setGroup("dubbo-zhang");
ReferenceConfig<S> reference = new ReferenceConfig<S>();
reference.setApplication(application);
reference.setRegistry(registry);
reference.setInterface(c);
reference.setTimeout(30000);
reference.setRetries(0);
S service = reference.get();
return service;
}
示例8: 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"));
}
示例9: generateKey
import com.alibaba.dubbo.config.ReferenceConfig; //导入依赖的package包/类
public String generateKey(ReferenceConfig<?> referenceConfig) {
String iName = referenceConfig.getInterface();
if (StringUtils.isBlank(iName)) {
Class<?> clazz = referenceConfig.getInterfaceClass();
iName = clazz.getName();
}
if (StringUtils.isBlank(iName)) {
throw new IllegalArgumentException("No interface info in ReferenceConfig" + referenceConfig);
}
StringBuilder ret = new StringBuilder();
if (!StringUtils.isBlank(referenceConfig.getGroup())) {
ret.append(referenceConfig.getGroup()).append("/");
}
ret.append(iName);
if (!StringUtils.isBlank(referenceConfig.getVersion())) {
ret.append(":").append(referenceConfig.getVersion());
}
return ret.toString();
}