This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new c510384  sample enrichments (#140)
c510384 is described below

commit c510384251749a52f96468d00837e0d7876506dc
Author: ken.lj <[email protected]>
AuthorDate: Tue Jan 14 11:26:42 2020 +0800

    sample enrichments (#140)
---
 .../samples/async/filter/LegacyBlockFilter.java    |   6 +
 ...lockFilter.java => LegacyListenableFilter.java} |  28 +++--
 .../META-INF/dubbo/org.apache.dubbo.rpc.Filter     |   1 +
 java/dubbo-samples-default-config/pom.xml          |   2 +-
 .../org/apache/dubbo/samples/UserLoadBalance.java  |   5 -
 java/dubbo-samples-perf/pom.xml                    |  18 +++
 java/dubbo-samples-perf/registry/pom.xml           |  98 +++++++++++++++
 .../perf/registry/ZookeeperNotificationMock.java   | 135 +++++++++++++++++++++
 java/pom.xml                                       |   1 +
 9 files changed, 279 insertions(+), 15 deletions(-)

diff --git 
a/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyBlockFilter.java
 
b/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyBlockFilter.java
index f17c736..c6ea262 100644
--- 
a/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyBlockFilter.java
+++ 
b/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyBlockFilter.java
@@ -55,4 +55,10 @@ public class LegacyBlockFilter implements Filter {
         logger.info("LegacyBlockFilter: This msg should not be blocked.");
         return result;
     }
+
+    @Override
+    public Result onResponse(Result appResponse, Invoker<?> invoker, 
Invocation invocation) {
+        System.out.println("Callback received on Filter.onResponse .");
+        return appResponse;
+    }
 }
diff --git 
a/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyBlockFilter.java
 
b/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyListenableFilter.java
similarity index 73%
copy from 
java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyBlockFilter.java
copy to 
java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyListenableFilter.java
index f17c736..2593015 100644
--- 
a/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyBlockFilter.java
+++ 
b/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/async/filter/LegacyListenableFilter.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.rpc.Filter;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.ListenableFilter;
 import org.apache.dubbo.rpc.Result;
 import org.apache.dubbo.rpc.RpcContext;
 import org.apache.dubbo.rpc.RpcException;
@@ -30,8 +31,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Activate(group = {Constants.PROVIDER, Constants.CONSUMER})
-public class LegacyBlockFilter implements Filter {
-    private static Logger logger = 
LoggerFactory.getLogger(LegacyBlockFilter.class);
+public class LegacyListenableFilter extends ListenableFilter {
+    private static Logger logger = 
LoggerFactory.getLogger(LegacyListenableFilter.class);
+
+    public LegacyListenableFilter() {
+        super.listener = new CallbackListener();
+    }
 
     @Override
     public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
@@ -43,16 +48,21 @@ public class LegacyBlockFilter implements Filter {
         filters += " legacy-block-filter";
         context.setAttachment("filters", filters);
 
-        Result result = invoker.invoke(invocation);
+        return invoker.invoke(invocation);
+    }
+
 
-        logger.info("This is the default return value: " + result.getValue());
+    private static class CallbackListener implements Filter.Listener {
 
-        if (result.hasException()) {
-            System.out.println("LegacyBlockFilter: This will only happen when 
the real exception returns: " + result.getException());
-            logger.warn("This will only happen when the real exception 
returns", result.getException());
+        @Override
+        public void onMessage(Result appResponse, Invoker<?> invoker, 
Invocation invocation) {
+            System.out.println("Callback received in 
ListenableFilter.onResponse .");
         }
 
-        logger.info("LegacyBlockFilter: This msg should not be blocked.");
-        return result;
+        @Override
+        public void onError(Throwable t, Invoker<?> invoker, Invocation 
invocation) {
+
+        }
     }
+
 }
diff --git 
a/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
 
b/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
index ee348bd..d121024 100644
--- 
a/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
+++ 
b/java/dubbo-samples-async/dubbo-samples-async-original-future/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
@@ -1,2 +1,3 @@
 async-postprocess=org.apache.dubbo.samples.async.filter.AsyncPostprocessFilter
 legacy-block=org.apache.dubbo.samples.async.filter.LegacyBlockFilter
+legacy-listenable=org.apache.dubbo.samples.async.filter.LegacyListenableFilter
diff --git a/java/dubbo-samples-default-config/pom.xml 
b/java/dubbo-samples-default-config/pom.xml
index 24093e7..7fa0676 100644
--- a/java/dubbo-samples-default-config/pom.xml
+++ b/java/dubbo-samples-default-config/pom.xml
@@ -29,7 +29,7 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
-        <dubbo.version>2.7.5-SNAPSHOT</dubbo.version>
+        <dubbo.version>2.7.5</dubbo.version>
         <spring.version>4.3.16.RELEASE</spring.version>
         <junit.version>4.12</junit.version>
         <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
diff --git 
a/java/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
 
b/java/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
index c05013c..adbb39b 100644
--- 
a/java/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
+++ 
b/java/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
@@ -21,16 +21,11 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.cluster.LoadBalance;
 import org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
 
 import java.net.InetAddress;
 
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
 import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
 
 
 public class UserLoadBalance extends RandomLoadBalance {
diff --git a/java/dubbo-samples-perf/pom.xml b/java/dubbo-samples-perf/pom.xml
new file mode 100644
index 0000000..126a2ce
--- /dev/null
+++ b/java/dubbo-samples-perf/pom.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>dubbo-samples-all</artifactId>
+        <groupId>org.apache.dubbo</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>pom</packaging>
+    <artifactId>dubbo-samples-perf</artifactId>
+
+    <modules>
+        <module>registry</module>
+    </modules>
+
+</project>
\ No newline at end of file
diff --git a/java/dubbo-samples-perf/registry/pom.xml 
b/java/dubbo-samples-perf/registry/pom.xml
new file mode 100644
index 0000000..e72f106
--- /dev/null
+++ b/java/dubbo-samples-perf/registry/pom.xml
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>dubbo-samples-perf</artifactId>
+        <groupId>org.apache.dubbo</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>perf-registry</artifactId>
+
+    <properties>
+        <source.level>1.8</source.level>
+        <target.level>1.8</target.level>
+        <dubbo.version>2.7.5</dubbo.version>
+        <spring.version>4.3.16.RELEASE</spring.version>
+        <junit.version>4.12</junit.version>
+        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+        <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
+        
<spring-boot-maven-plugin.version>2.1.4.RELEASE</spring-boot-maven-plugin.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <version>${dubbo.version}</version>
+            <type>pom</type>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${source.level}</source>
+                    <target>${target.level}</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot-maven-plugin.version}</version>
+                <configuration>
+                    
<mainClass>org.apache.dubbo.samples.perf.registry.ZookeeperNotificationMock</mainClass>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <repositories>
+        <repository>
+            <id>apache.snapshots.https</id>
+            <name>Apache Development Snapshot Repository</name>
+            
<url>https://repository.apache.org/content/repositories/snapshots</url>
+            <layout>default</layout>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+            </snapshots>
+        </repository>
+    </repositories>
+</project>
\ No newline at end of file
diff --git 
a/java/dubbo-samples-perf/registry/src/main/java/org/apache/dubbo/samples/perf/registry/ZookeeperNotificationMock.java
 
b/java/dubbo-samples-perf/registry/src/main/java/org/apache/dubbo/samples/perf/registry/ZookeeperNotificationMock.java
new file mode 100644
index 0000000..d78ec77
--- /dev/null
+++ 
b/java/dubbo-samples-perf/registry/src/main/java/org/apache/dubbo/samples/perf/registry/ZookeeperNotificationMock.java
@@ -0,0 +1,135 @@
+package org.apache.dubbo.samples.perf.registry;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.zookeeper.CreateMode;
+import org.springframework.util.CollectionUtils;
+
+import java.net.URLEncoder;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+public class ZookeeperNotificationMock {
+    private static String zookeeperHost = 
System.getProperty("zookeeper.address", "11.164.235.9");
+    private static String ROOT_PATH = 
"/dubbo/org.apache.dubbo.samples.basic.api.DemoService/providers/";
+    private static ExecutorService executorService = 
Executors.newFixedThreadPool(100);
+    private static String[] nodePathes;
+    private static CuratorFramework client;
+
+    public static void main(String[] args) throws Exception {
+        initClient();
+        if (args.length == 1) {
+            deleteProviders();
+        } else {
+            initProviders();
+            mockProvidersChange();
+        }
+    }
+
+    public static void initClient() throws Exception {
+        client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 
* 1000, 60 * 1000,
+                new ExponentialBackoffRetry(1000, 3));
+        client.start();
+    }
+
+    public static void initProviders() throws Exception {
+        nodePathes = new String[1000];
+        for (int i = 0; i < 1000; i++) {
+            String providerUrl = 
"dubbo://30.5.125.28:20880/org.apache.dubbo.samples.basic.api.DemoService?anyhost=true&application=demo-provider&bind.ip=30.5.125.122&bind.port=20880&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=org.apache.dubbo.samples.basic.api.DemoService&methods=testVoid,sayHello&pid=19175&release=2.7.5-SNAPSHOT&side=provider"
 +
+                    "timestamp=" + System.currentTimeMillis();
+            try {
+                String path = ROOT_PATH + URLEncoder.encode(providerUrl, 
"utf-8");
+                nodePathes[i] = path;
+                if (client.checkExists().forPath(path) == null) {
+                    client.create().creatingParentsIfNeeded().forPath(path);
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        Thread.sleep(100);
+    }
+
+    public static void mockProvidersChange() throws Exception {
+        Random r = new Random();
+        String[] changes = new String[100];
+        while (true) {
+            CountDownLatch deleteLatch = new CountDownLatch(100);
+            for (int i = 0; i < 100; i++) {
+                String path = nodePathes[r.nextInt(1000)];
+                changes[i] = path;
+                executorService.submit(() -> {
+                    try {
+                        deleteNode(path);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                        deleteLatch.countDown();
+                    }
+                });
+            }
+            deleteLatch.await();
+
+            Thread.sleep(100);
+
+            CountDownLatch createLatch = new CountDownLatch(100);
+            for (int i = 0; i < 100; i++) {
+                try {
+                    createNode(changes[i]);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                } finally {
+                    createLatch.countDown();
+                }
+            }
+            createLatch.await();
+
+            Thread.sleep(100);
+        }
+    }
+
+    public static void deleteProviders() throws Exception {
+        List<String> children = 
client.getChildren().forPath("/dubbo/org.apache.dubbo.samples.basic.api.DemoService/providers");
+        if (!CollectionUtils.isEmpty(children)) {
+            children.forEach(c -> {
+                try {
+                    deleteNode(ROOT_PATH + c);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            });
+        }
+    }
+
+    private static void createNode(String path) throws Exception {
+        client.create().withMode(CreateMode.EPHEMERAL).forPath(path);
+        System.out.println("Creating " + path);
+    }
+
+    private static void deleteNode(String path) throws Exception {
+        client.delete().forPath(path);
+        System.out.println("Deleting " + path);
+    }
+
+}
diff --git a/java/pom.xml b/java/pom.xml
index 7628e22..5144867 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -81,6 +81,7 @@
         <module>dubbo-samples-cloud-native</module>
         <module>dubbo-samples-protobuf</module>
         <module>dubbo-samples-ssl</module>
+        <module>dubbo-samples-perf</module>
     </modules>
 
     <repositories>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to