diff --git a/dubbo-registry-default/src/main/java/com/alibaba/dubbo/registry/dubbo/DubboRegistryService.java b/dubbo-registry-default/src/main/java/com/alibaba/dubbo/registry/dubbo/DubboRegistryService.java deleted file mode 100644 index 9c221a58bbb8902e7705294e72561237c94023eb..0000000000000000000000000000000000000000 --- a/dubbo-registry-default/src/main/java/com/alibaba/dubbo/registry/dubbo/DubboRegistryService.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.registry.dubbo; - -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.logger.Logger; -import com.alibaba.dubbo.common.logger.LoggerFactory; -import com.alibaba.dubbo.common.utils.ConcurrentHashSet; -import com.alibaba.dubbo.common.utils.NetUtils; -import com.alibaba.dubbo.common.utils.UrlUtils; -import com.alibaba.dubbo.registry.NotifyListener; -import com.alibaba.dubbo.registry.RegistryService; -import com.alibaba.dubbo.registry.support.CacheRegistry; -import com.alibaba.dubbo.registry.support.SimpleRegistryService; -import com.alibaba.dubbo.rpc.RpcContext; - -/** - * DubboRegistryService - * - * @author william.liangf - */ -public class DubboRegistryService extends CacheRegistry { - - private final ConcurrentMap> remoteRegistered = new ConcurrentHashMap>(); - - private final ConcurrentMap>> remoteSubscribed = new ConcurrentHashMap>>(); - - private final static Logger logger = LoggerFactory.getLogger(SimpleRegistryService.class); - - private List registries; - - public DubboRegistryService() { - this(0); - } - - public DubboRegistryService(int port) { - super(new URL("dubbo", NetUtils.getLocalHost(), port, RegistryService.class.getName())); - } - - public boolean isAvailable() { - return true; - } - - public void doRegister(URL url) { - String client = RpcContext.getContext().getRemoteAddressString(); - Set urls = remoteRegistered.get(client); - if (urls == null) { - remoteRegistered.putIfAbsent(client, new ConcurrentHashSet()); - urls = remoteRegistered.get(client); - } - urls.add(url.toFullString()); - registered(url); - } - - public void doUnregister(URL url) { - String client = RpcContext.getContext().getRemoteAddressString(); - Set urls = remoteRegistered.get(client); - if (urls != null && urls.size() > 0) { - urls.remove(url.toFullString()); - } - unregistered(url); - } - - public void doSubscribe(URL url, NotifyListener listener) { - if (! Constants.ANY_VALUE.equals(url.getServiceName()) - && url.getParameter(Constants.REGISTER_KEY, true)) { - register(url); - } - String client = RpcContext.getContext().getRemoteAddressString(); - List urls = lookup(url); - if ((RegistryService.class.getName()).equals(url.getServiceName()) - && (urls == null || urls.size() == 0)) { - register(new URL("dubbo", - NetUtils.getLocalHost(), - RpcContext.getContext().getLocalPort(), - com.alibaba.dubbo.registry.RegistryService.class.getName(), - url.getParameters())); - List rs = registries; - if (rs != null && rs.size() > 0) { - for (String registry : rs) { - register(UrlUtils.parseURL(registry, url.getParameters())); - } - } - } - ConcurrentMap> clientListeners = remoteSubscribed.get(client); - if (clientListeners == null) { - remoteSubscribed.putIfAbsent(client, new ConcurrentHashMap>()); - clientListeners = remoteSubscribed.get(client); - } - String key = url.toFullString(); - Set listeners = clientListeners.get(key); - if (listeners == null) { - clientListeners.putIfAbsent(key, new ConcurrentHashSet()); - listeners = clientListeners.get(key); - } - listeners.add(listener); - subscribed(url, listener); - } - - public void doUnsubscribe(URL url, NotifyListener listener) { - if (! Constants.ANY_VALUE.equals(url.getServiceName()) - && url.getParameter(Constants.REGISTER_KEY, true)) { - unregister(url); - } - String client = RpcContext.getContext().getRemoteAddressString(); - Map> clientListeners = remoteSubscribed.get(client); - if (clientListeners != null && clientListeners.size() > 0) { - String key = url.toFullString(); - Set listeners = clientListeners.get(key); - if (listeners != null && listeners.size() > 0) { - listeners.remove(listener); - } - } - } - - public void disconnect() { - String client = RpcContext.getContext().getRemoteAddressString(); - if (logger.isInfoEnabled()) { - logger.info("Disconnected " + client); - } - Set urls = remoteRegistered.get(client); - if (urls != null && urls.size() > 0) { - for (String url : urls) { - unregister(URL.valueOf(url)); - } - } - Map> listeners = remoteSubscribed.get(client); - if (listeners != null && listeners.size() > 0) { - for (Map.Entry> entry : listeners.entrySet()) { - String url = entry.getKey(); - for (NotifyListener listener : entry.getValue()) { - unsubscribe(URL.valueOf(url), listener); - } - } - } - } - - public List getRegistries() { - return registries; - } - - public void setRegistries(List registries) { - this.registries = registries; - } - -} diff --git a/dubbo-registry-default/src/test/java/com/alibaba/dubbo/registry/dubbo/Simple.java b/dubbo-registry-default/src/test/java/com/alibaba/dubbo/registry/dubbo/Simple.java deleted file mode 100644 index 2b5f2fd292c32bc61b96c3320f82e752f106c9aa..0000000000000000000000000000000000000000 --- a/dubbo-registry-default/src/test/java/com/alibaba/dubbo/registry/dubbo/Simple.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.registry.dubbo; - -import java.io.IOException; -import java.net.ServerSocket; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.ExtensionLoader; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.utils.NetUtils; -import com.alibaba.dubbo.registry.RegistryService; -import com.alibaba.dubbo.rpc.Exporter; -import com.alibaba.dubbo.rpc.Protocol; -import com.alibaba.dubbo.rpc.ProxyFactory; -import com.alibaba.dubbo.rpc.RpcConstants; - -public class Simple { - - private static final Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); - - private static final ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); - - public synchronized static Exporter exportIfAbsent(int port) { - try { - new ServerSocket(port).close(); - return export(port); - } catch (IOException e) { - return null; - } - } - - public static Exporter export(int port) { - return export(port, new DubboRegistryService()); - } - - public static Exporter export(int port, RegistryService registryService) { - return protocol.export(proxyFactory.getInvoker(registryService, RegistryService.class, - new URL("dubbo", NetUtils.getLocalHost(), port, RegistryService.class.getName()) - .setPath(RegistryService.class.getName()) - .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) - .addParameter(RpcConstants.CLUSTER_STICKY_KEY, "true") - .addParameter(RpcConstants.CALLBACK_INSTANCES_LIMIT_KEY, "1000") - .addParameter("ondisconnect", "disconnect") - .addParameter("subscribe.1.callback", "true") - .addParameter("unsubscribe.1.callback", "false"))); - } - - public static void main(String[] args) { - export(9090); - synchronized (Simple.class) { - while (true) { - try { - Simple.class.wait(); - } catch (InterruptedException e) { - } - } - } - } - -} \ No newline at end of file