You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by il...@apache.org on 2019/08/06 11:14:45 UTC

[dubbo-samples] branch master updated: clean up dubbo-samples-gateway

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

iluo 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 b283def  clean up dubbo-samples-gateway
b283def is described below

commit b283def23ccba2c6812f597b609ff51685e313c1
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Tue Aug 6 19:14:12 2019 +0800

    clean up dubbo-samples-gateway
---
 .../apache/dubbo/samples/CallbackListenerImpl.java | 14 ----
 .../org/apache/dubbo/samples/TestClientFilter.java | 28 --------
 .../META-INF/services/org.apache.dubbo.rpc.Filter  |  1 -
 .../org.apache.dubbo.rpc.cluster.LoadBalance       |  1 -
 .../org.apache.dubbo.rpc.listener.CallbackListener |  1 -
 .../src/test/java/UserLoadBalanceTest.java         | 77 ----------------------
 .../README.md                                      |  0
 .../pom.xml                                        | 26 +++++---
 .../org/apache/dubbo/samples/CallbackListener.java | 24 +++++++
 .../apache/dubbo/samples/CallbackListenerImpl.java | 28 ++++++++
 .../org/apache/dubbo/samples/TestClientFilter.java | 41 ++++++++++++
 .../org/apache/dubbo/samples/UserLoadBalance.java  | 23 ++++++-
 .../META-INF/dubbo/org.apache.dubbo.rpc.Filter     |  1 +
 .../dubbo/org.apache.dubbo.rpc.cluster.LoadBalance |  1 +
 .../org.apache.dubbo.rpc.listener.CallbackListener |  1 +
 pom.xml                                            |  1 +
 16 files changed, 135 insertions(+), 133 deletions(-)

diff --git a/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/CallbackListenerImpl.java b/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/CallbackListenerImpl.java
deleted file mode 100644
index e5b72dc..0000000
--- a/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/CallbackListenerImpl.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.apache.dubbo.samples;
-
-
-import org.apache.dubbo.samples.callback.api.CallbackListener;
-
-
-public class CallbackListenerImpl implements CallbackListener {
-
-    @Override
-    public void changed(String msg) {
-        System.out.println("receive msg from server :" + msg);
-    }
-
-}
diff --git a/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/TestClientFilter.java b/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/TestClientFilter.java
deleted file mode 100644
index 762c87a..0000000
--- a/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/TestClientFilter.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.dubbo.samples;
-
-import org.apache.dubbo.common.Constants;
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.rpc.Filter;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcException;
-
-
-@Activate(group = Constants.CONSUMER)
-public class TestClientFilter implements Filter {
-    @Override
-    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
-        try{
-            Result result = invoker.invoke(invocation);
-            return result;
-        }catch (Exception e){
-            throw e;
-        }
-    }
-
-    @Override
-    public Result onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
-        return result;
-    }
-}
diff --git a/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter b/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter
deleted file mode 100644
index d7836df..0000000
--- a/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.Filter
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.dubbo.samples.TestClientFilter
\ No newline at end of file
diff --git a/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.cluster.LoadBalance b/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.cluster.LoadBalance
deleted file mode 100644
index 4f24664..0000000
--- a/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.cluster.LoadBalance
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.dubbo.samples.UserLoadBalance
\ No newline at end of file
diff --git a/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.listener.CallbackListener b/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.listener.CallbackListener
deleted file mode 100644
index 077d9b6..0000000
--- a/dubbo-sample-gateway/src/main/resources/META-INF/services/org.apache.dubbo.rpc.listener.CallbackListener
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.dubbo.samples.CallbackListenerImpl
\ No newline at end of file
diff --git a/dubbo-sample-gateway/src/test/java/UserLoadBalanceTest.java b/dubbo-sample-gateway/src/test/java/UserLoadBalanceTest.java
deleted file mode 100644
index a6f6ebc..0000000
--- a/dubbo-sample-gateway/src/test/java/UserLoadBalanceTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.RpcStatus;
-import org.apache.dubbo.rpc.cluster.LoadBalance;
-import org.apache.dubbo.rpc.cluster.loadbalance.AbstractLoadBalance;
-import org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance;
-import org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
-import org.apache.dubbo.samples.UserLoadBalance;
-import org.junit.Assert;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicLong;
-
-import static org.junit.Assert.*;
-
-
-public class UserLoadBalanceTest {
-
-    Invocation invocation;
-
-    Invoker<UserLoadBalanceTest> invoker1;
-    Invoker<UserLoadBalanceTest> invoker2;
-    Invoker<UserLoadBalanceTest> invoker3;
-    Invoker<UserLoadBalanceTest> invoker4;
-    Invoker<UserLoadBalanceTest> invoker5;
-
-    List<Invoker<UserLoadBalanceTest>> invokers = new ArrayList<Invoker<UserLoadBalanceTest>>();
-    @org.junit.Test
-    public void doSelect() {
-
-        int runs = 1000;
-        Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, RandomLoadBalance.NAME);
-        for (Map.Entry<Invoker, AtomicLong> entry : counter.entrySet()) {
-            Long count = entry.getValue().get();
-            Assert.assertTrue("abs diff should < avg",Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()));
-        }
-
-        for (int i = 0; i < 5; i++) {
-            for (int j = 0; j <= i; j++) {
-                RpcStatus.beginCount(invokers.get(i).getUrl(), invocation.getMethodName());
-            }
-        }
-        counter = getInvokeCounter(runs, LeastActiveLoadBalance.NAME);
-        for (Map.Entry<Invoker, AtomicLong> entry : counter.entrySet()) {
-            Long count = entry.getValue().get();
-        }
-        Assert.assertEquals(runs, counter.get(invoker1).intValue());
-        Assert.assertEquals(0, counter.get(invoker2).intValue());
-        Assert.assertEquals(0, counter.get(invoker3).intValue());
-        Assert.assertEquals(0, counter.get(invoker4).intValue());
-        Assert.assertEquals(0, counter.get(invoker5).intValue());
-    }
-
-
-    public Map<Invoker, AtomicLong> getInvokeCounter(int runs, String loadbalanceName) {
-        Map<Invoker, AtomicLong> counter = new ConcurrentHashMap<Invoker, AtomicLong>();
-        LoadBalance lb = getLoadBalance(loadbalanceName);
-        for (Invoker invoker : invokers) {
-            counter.put(invoker, new AtomicLong(0));
-        }
-        URL url = invokers.get(0).getUrl();
-        for (int i = 0; i < runs; i++) {
-            Invoker sinvoker = lb.select(invokers, url, invocation);
-            counter.get(sinvoker).incrementAndGet();
-        }
-        return counter;
-    }
-
-    protected AbstractLoadBalance getLoadBalance(String loadbalanceName) {
-        return (AbstractLoadBalance) ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(loadbalanceName);
-    }
-
-}
diff --git a/dubbo-sample-gateway/README.md b/dubbo-samples-gateway/README.md
similarity index 100%
rename from dubbo-sample-gateway/README.md
rename to dubbo-samples-gateway/README.md
diff --git a/dubbo-sample-gateway/pom.xml b/dubbo-samples-gateway/pom.xml
similarity index 67%
rename from dubbo-sample-gateway/pom.xml
rename to dubbo-samples-gateway/pom.xml
index 0876df9..09e1d4f 100644
--- a/dubbo-sample-gateway/pom.xml
+++ b/dubbo-samples-gateway/pom.xml
@@ -13,8 +13,9 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
-        <dubbo.version>2.7.1</dubbo.version>
+        <dubbo.version>2.7.3</dubbo.version>
         <junit.version>4.12</junit.version>
+        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
     </properties>
 
     <dependencies>
@@ -30,12 +31,7 @@
             <version>${dubbo.version}</version>
             <type>pom</type>
         </dependency>
-        <dependency>
-            <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-samples-callback</artifactId>
-             <version>1.0-SNAPSHOT</version>
-            <scope>compile</scope>
-        </dependency>
+
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
@@ -43,4 +39,18 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
-</project>
\ No newline at end of file
+
+    <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>
+        </plugins>
+    </build>
+</project>
diff --git a/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/CallbackListener.java b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/CallbackListener.java
new file mode 100644
index 0000000..5cefe1c
--- /dev/null
+++ b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/CallbackListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.samples;
+
+public interface CallbackListener {
+
+    void changed(String msg);
+
+}
diff --git a/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/CallbackListenerImpl.java b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/CallbackListenerImpl.java
new file mode 100644
index 0000000..918acfb
--- /dev/null
+++ b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/CallbackListenerImpl.java
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.samples;
+
+
+public class CallbackListenerImpl implements CallbackListener {
+
+    @Override
+    public void changed(String msg) {
+        System.out.println("receive msg from server :" + msg);
+    }
+
+}
diff --git a/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/TestClientFilter.java b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/TestClientFilter.java
new file mode 100644
index 0000000..d014a65
--- /dev/null
+++ b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/TestClientFilter.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.samples;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.rpc.Filter;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+
+
+@Activate(group = CONSUMER)
+public class TestClientFilter implements Filter {
+    @Override
+    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+        return invoker.invoke(invocation);
+    }
+
+    @Override
+    public Result onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
+        return result;
+    }
+}
diff --git a/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
similarity index 52%
rename from dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
rename to dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
index cd0557a..c05013c 100644
--- a/dubbo-sample-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
+++ b/dubbo-samples-gateway/src/main/java/org/apache/dubbo/samples/UserLoadBalance.java
@@ -1,3 +1,20 @@
+/*
+ * 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.
+ */
+
 package org.apache.dubbo.samples;
 
 import org.apache.dubbo.common.URL;
@@ -20,16 +37,16 @@ public class UserLoadBalance extends RandomLoadBalance {
 
     @Override
     public <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
-        // 循环当前注册的多个invoker 优先选择与自己IP相同的服务
         for (Invoker t : invokers) {
             try {
                 InetAddress addr = InetAddress.getLocalHost();
-                String ip=addr.getHostAddress().toString(); //获取本机ip
+                String ip = addr.getHostAddress().toString();
                 URL u = t.getUrl();
                 if (u.getIp().equals(ip)) {
-                    return  t;
+                    return t;
                 }
             } catch (Exception e) {
+                // no op
             }
         }
         return super.doSelect(invokers, url, invocation);
diff --git a/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
new file mode 100644
index 0000000..67d1cec
--- /dev/null
+++ b/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
@@ -0,0 +1 @@
+testclientfilter=org.apache.dubbo.samples.TestClientFilter
diff --git a/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance b/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance
new file mode 100644
index 0000000..916d7b8
--- /dev/null
+++ b/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance
@@ -0,0 +1 @@
+userloadbalance=org.apache.dubbo.samples.UserLoadBalance
diff --git a/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.listener.CallbackListener b/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.listener.CallbackListener
new file mode 100644
index 0000000..2a19f84
--- /dev/null
+++ b/dubbo-samples-gateway/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.listener.CallbackListener
@@ -0,0 +1 @@
+testcallback=org.apache.dubbo.samples.CallbackListenerImpl
diff --git a/pom.xml b/pom.xml
index a1c3d97..91d8db0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,7 @@
         <module>dubbo-samples-direct</module>
         <module>dubbo-samples-docker</module>
         <module>dubbo-samples-echo</module>
+        <module>dubbo-samples-gateway</module>
         <module>dubbo-samples-generic</module>
         <module>dubbo-samples-group</module>
         <module>dubbo-samples-governance</module>


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