本文整理汇总了Java中com.alibaba.dubbo.registry.RegistryService类的典型用法代码示例。如果您正苦于以下问题:Java RegistryService类的具体用法?Java RegistryService怎么用?Java RegistryService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RegistryService类属于com.alibaba.dubbo.registry包,在下文中一共展示了RegistryService类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribe
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
public void subscribe(URL url, NotifyListener listener) {
if (getUrl().getPort() == 0) {
URL registryUrl = RpcContext.getContext().getUrl();
if (registryUrl != null && registryUrl.getPort() > 0
&& RegistryService.class.getName().equals(registryUrl.getPath())) {
super.setUrl(registryUrl);
super.register(registryUrl);
}
}
String client = RpcContext.getContext().getRemoteAddressString();
ConcurrentMap<URL, Set<NotifyListener>> clientListeners = remoteSubscribed.get(client);
if (clientListeners == null) {
remoteSubscribed.putIfAbsent(client, new ConcurrentHashMap<URL, Set<NotifyListener>>());
clientListeners = remoteSubscribed.get(client);
}
Set<NotifyListener> listeners = clientListeners.get(url);
if (listeners == null) {
clientListeners.putIfAbsent(url, new ConcurrentHashSet<NotifyListener>());
listeners = clientListeners.get(url);
}
listeners.add(listener);
super.subscribe(url, listener);
subscribed(url, listener);
}
示例2: testMultiProtocolRegister
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
@Test
public void testMultiProtocolRegister() {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml");
ctx.start();
try {
List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
示例3: testMultiRegistry
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
@Test
public void testMultiRegistry() {
SimpleRegistryService registryService1 = new SimpleRegistryService();
Exporter<RegistryService> exporter1 = SimpleRegistryExporter.export(4545, registryService1);
SimpleRegistryService registryService2 = new SimpleRegistryService();
Exporter<RegistryService> exporter2 = SimpleRegistryExporter.export(4546, registryService2);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-registry.xml");
ctx.start();
try {
List<URL> urls1 = registryService1.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNull(urls1);
List<URL> urls2 = registryService2.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls2);
assertEquals(1, urls2.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20880/com.alibaba.dubbo.config.spring.api.DemoService", urls2.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter1.unexport();
exporter2.unexport();
}
}
示例4: testDelayFixedTime
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
@Test
public void testDelayFixedTime() throws Exception {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-fixed-time.xml");
ctx.start();
try {
List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNull(urls);
int i = 0;
while ((i ++) < 60 && urls == null) {
urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
Thread.sleep(10);
}
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
示例5: testDelayOnInitialized
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
@Test
public void testDelayOnInitialized() throws Exception {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-on-initialized.xml");
//ctx.start();
try {
List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
示例6: testAnnotation
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
@Test
public void testAnnotation() {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
try {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml");
consumerContext.start();
try {
AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction");
String hello = annotationAction.doSayName("hello");
assertEquals("annotation:hello", hello);
} finally {
consumerContext.stop();
consumerContext.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
} finally {
exporter.unexport();
}
}
示例7: createRegistry
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
public Registry createRegistry(URL url) {
url = getRegistryURL(url);
List<URL> urls = new ArrayList<URL>();
urls.add(url.removeParameter(Constants.BACKUP_KEY));
String backup = url.getParameter(Constants.BACKUP_KEY);
if (backup != null && backup.length() > 0) {
String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(backup);
for (String address : addresses) {
urls.add(url.setAddress(address));
}
}
RegistryDirectory<RegistryService> directory = new RegistryDirectory<RegistryService>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString()));
Invoker<RegistryService> registryInvoker = cluster.join(directory);
RegistryService registryService = proxyFactory.getProxy(registryInvoker);
DubboRegistry registry = new DubboRegistry(registryInvoker, registryService);
directory.setRegistry(registry);
directory.setProtocol(protocol);
directory.notify(urls);
directory.subscribe(new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters()));
return registry;
}
示例8: getRegistryURL
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
private static URL getRegistryURL(URL url) {
return url.setPath(RegistryService.class.getName())
.removeParameter(Constants.EXPORT_KEY).removeParameter(Constants.REFER_KEY)
.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
.addParameter(Constants.CLUSTER_STICKY_KEY, "true")
.addParameter(Constants.LAZY_CONNECT_KEY, "true")
.addParameter(Constants.RECONNECT_KEY, "false")
.addParameterIfAbsent(Constants.TIMEOUT_KEY, "10000")
.addParameterIfAbsent(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "10000")
.addParameterIfAbsent(Constants.CONNECT_TIMEOUT_KEY, "10000")
.addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ","))
//.addParameter(Constants.STUB_KEY, RegistryServiceStub.class.getName())
//.addParameter(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()) //for event dispatch
//.addParameter(Constants.ON_DISCONNECT_KEY, "disconnect")
.addParameter("subscribe.1.callback", "true")
.addParameter("unsubscribe.1.callback", "false");
}
示例9: DubboRegistry
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
public DubboRegistry(Invoker<RegistryService> registryInvoker, RegistryService registryService) {
super(registryInvoker.getUrl());
this.registryInvoker = registryInvoker;
this.registryService = registryService;
// 启动重连定时器
int reconnectPeriod = registryInvoker.getUrl().getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, RECONNECT_PERIOD_DEFAULT);
reconnectFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
public void run() {
// 检测并连接注册中心
try {
connect();
} catch (Throwable t) { // 防御性容错
logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t);
}
}
}, reconnectPeriod, reconnectPeriod, TimeUnit.MILLISECONDS);
}
示例10: refer
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY);
Registry registry = registryFactory.getRegistry(url);
if (RegistryService.class.equals(type)) {
return proxyFactory.getInvoker((T) registry, type, url);
}
// group="a,b" or group="*"
Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
String group = qs.get(Constants.GROUP_KEY);
if (group != null && group.length() > 0 ) {
if ( ( Constants.COMMA_SPLIT_PATTERN.split( group ) ).length > 1
|| "*".equals( group ) ) {
return doRefer( getMergeableCluster(), registry, type, url );
}
}
return doRefer(cluster, registry, type, url);
}
示例11: getRegistry
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
public Registry getRegistry(URL url) {
url = url.setPath(RegistryService.class.getName())
.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
.removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
String key = url.toServiceString();
// 锁定注册中心获取过程,保证注册中心单一实例
LOCK.lock();
try {
Registry registry = REGISTRIES.get(key);
if (registry != null) {
return registry;
}
registry = createRegistry(url);
if (registry == null) {
throw new IllegalStateException("Can not create registry " + url);
}
REGISTRIES.put(key, registry);
return registry;
} finally {
// 释放锁
LOCK.unlock();
}
}
示例12: refer
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY);
Registry registry = registryFactory.getRegistry(url);
if (RegistryService.class.equals(type)) {
return proxyFactory.getInvoker((T) registry, type, url);
}
// group="a,b" or group="*"
Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
String group = qs.get(Constants.GROUP_KEY);
if (group != null && group.length() > 0) {
if ((Constants.COMMA_SPLIT_PATTERN.split(group)).length > 1
|| "*".equals(group)) {
return doRefer(getMergeableCluster(), registry, type, url);
}
}
return doRefer(cluster, registry, type, url);
}
示例13: getRegistry
import com.alibaba.dubbo.registry.RegistryService; //导入依赖的package包/类
public Registry getRegistry(URL url) {
url = url.setPath(RegistryService.class.getName())
.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
.removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
String key = url.toServiceString();
// 锁定注册中心获取过程,保证注册中心单一实例
LOCK.lock();
try {
Registry registry = REGISTRIES.get(key);
if (registry != null) {
return registry;
}
registry = createRegistry(url);
if (registry == null) {
throw new IllegalStateException("Can not create registry " + url);
}
REGISTRIES.put(key, registry);
return registry;
} finally {
// 释放锁
LOCK.unlock();
}
}