chickenlj closed pull request #1792: zk Unsubscribe issue
URL: https://github.com/apache/incubator-dubbo/pull/1792
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java
 
b/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java
index 8a67d711ec..02553aa535 100644
--- 
a/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java
+++ 
b/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java
@@ -28,6 +28,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
@@ -358,6 +359,24 @@ public Object decode(Object jv) throws IOException {
             }
         };
         GlobalDecoderMap.put(Date.class, d);
+
+        d = new Decoder() {
+            @Override
+            public Object decode(Object jv) throws IOException {
+                if (jv instanceof String) {
+                    String[] items = ((String)jv).split("_");
+                    if(items.length == 1){
+                        return new Locale(items[0]);
+                    }
+                    if(items.length == 2){
+                        return new Locale(items[0], items[1]);
+                    }
+                    return new Locale(items[0], items[1], items[2]);
+                }
+                return (Locale)null;
+            }
+        };
+        GlobalDecoderMap.put(Locale.class, d);
     }
 
     @Override
@@ -407,6 +426,8 @@ public void writeValue(Object obj, JSONWriter jb, boolean 
writeClass) throws IOE
                     writeValue(item, jb, writeClass);
             }
             jb.arrayEnd();
+        } else if(obj instanceof Locale) {
+            jb.valueString(obj.toString());
         } else {
             jb.objectBegin();
 
diff --git 
a/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java 
b/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java
index bc45e87f24..cf631eebb6 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java
@@ -24,6 +24,7 @@
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
@@ -169,6 +170,14 @@ public void testParse2Arguments() throws Exception {
         assertEquals(test[0], 1);
     }
 
+    @Test
+    public void testLocale() throws Exception {
+        Locale obj = Locale.US;
+        String str = JSON.json(obj);
+        assertEquals("\"en_US\"", str);
+        assertEquals(obj, JSON.parse(str, Locale.class));
+    }
+
     public static class Bean1 {
         public int[] array;
         private String name, displayName;
diff --git 
a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/com/alibaba/dubbo/registry/zookeeper/ZookeeperRegistry.java
 
b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/com/alibaba/dubbo/registry/zookeeper/ZookeeperRegistry.java
index 8bebf53158..6835c2c86d 100644
--- 
a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/com/alibaba/dubbo/registry/zookeeper/ZookeeperRegistry.java
+++ 
b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/com/alibaba/dubbo/registry/zookeeper/ZookeeperRegistry.java
@@ -200,7 +200,14 @@ protected void doUnsubscribe(URL url, NotifyListener 
listener) {
         if (listeners != null) {
             ChildListener zkListener = listeners.get(listener);
             if (zkListener != null) {
-                zkClient.removeChildListener(toUrlPath(url), zkListener);
+                if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
+                    String root = toRootPath();
+                    zkClient.removeChildListener(root, zkListener);
+                } else {
+                    for (String path : toCategoriesPath(url)) {
+                        zkClient.removeChildListener(path, zkListener);
+                    }
+                }
             }
         }
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to