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/02 02:26:14 UTC

[dubbo-samples] branch master updated: update dubbo-samples-annotation to demo 'methods' in @Reference

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 4005404  update dubbo-samples-annotation to demo 'methods' in @Reference
4005404 is described below

commit 4005404faf10dafb215fb58669ba8e7212bd9831
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Fri Aug 2 10:25:27 2019 +0800

    update dubbo-samples-annotation to demo 'methods' in @Reference
---
 dubbo-samples-annotation/pom.xml                   |  2 +-
 .../annotation/AnnotationConsumerBootstrap.java    |  8 +--
 .../annotation/action/AnnotationAction.java        | 14 ++++-
 .../dubbo/samples/annotation/api/Notify.java       | 35 +++++++++++
 .../impl/AnnotationGreetingServiceImpl.java        |  2 +-
 .../dubbo/samples/annotation/impl/NotifyImpl.java  | 68 ++++++++++++++++++++++
 .../samples/annotation/AnnotationServicesIT.java   |  4 +-
 7 files changed, 123 insertions(+), 10 deletions(-)

diff --git a/dubbo-samples-annotation/pom.xml b/dubbo-samples-annotation/pom.xml
index e59d23d..23d7cdb 100644
--- a/dubbo-samples-annotation/pom.xml
+++ b/dubbo-samples-annotation/pom.xml
@@ -31,7 +31,7 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
-        <dubbo.version>2.7.3</dubbo.version>
+        <dubbo.version>2.7.4-SNAPSHOT</dubbo.version>
         <spring-test.version>4.3.16.RELEASE</spring-test.version>
         <junit.version>4.12</junit.version>
         <docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
diff --git a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java
index 7c483d9..2e2d66b 100644
--- a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java
+++ b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java
@@ -34,10 +34,10 @@ public class AnnotationConsumerBootstrap {
         context.start();
         final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
 
-        System.out.println("hello :" + annotationAction.doSayHello("world"));
-        System.out.println("goodbye :" + annotationAction.doSayGoodbye("world"));
-        System.out.println("greeting :" + annotationAction.doGreeting("world"));
-        System.out.println("reply :" + annotationAction.replyGreeting("world"));
+        System.out.println("hello : " + annotationAction.doSayHello("world"));
+        System.out.println("goodbye : " + annotationAction.doSayGoodbye("world"));
+        System.out.println("greeting : " + annotationAction.doGreeting("world"));
+        System.out.println("reply : " + annotationAction.replyGreeting("world"));
     }
 
 
diff --git a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java
index 0c9c61e..1cdbb84 100644
--- a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java
+++ b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java
@@ -30,12 +30,22 @@ import org.springframework.stereotype.Component;
 @Component("annotationAction")
 public class AnnotationAction {
 
-    @Reference(interfaceClass = HelloService.class, version = AnnotationConstants.VERSION)
+    @Reference(interfaceClass = HelloService.class, version = AnnotationConstants.VERSION /*,
+            methods = {
+                    @Method(
+                            name = "sayHello",
+                            oninvoke = "notify.oninvoke",
+                            onreturn = "notify.onreturn",
+                            onthrow = "notify.onthrow")
+            }
+             */
+    )
     private HelloService helloService;
 
     @Reference(interfaceClass = GreetingService.class,
             version = AnnotationConstants.VERSION,
-            methods = {@Method(name = "greeting", timeout = 250, retries = 1)})
+            timeout = 1000,
+            methods = {@Method(name = "greeting", timeout = 3000, retries = 1)})
     private GreetingService greetingService;
 
     public String doSayHello(String name) {
diff --git a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/Notify.java b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/Notify.java
new file mode 100644
index 0000000..4e7d0cf
--- /dev/null
+++ b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/Notify.java
@@ -0,0 +1,35 @@
+/*
+ * 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.annotation.api;
+
+import java.util.List;
+import java.util.Map;
+
+public interface Notify {
+    void oninvoke(String request);
+
+    void onreturn(String response, String request);
+
+    void onthrow(Throwable ex, String request);
+
+    List<String> getInvokes();
+
+    Map<String, String> getReturns();
+
+    Map<String, Throwable> getExceptions();
+}
diff --git a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java
index 257e5ec..6bea0e2 100644
--- a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java
+++ b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java
@@ -38,7 +38,7 @@ public class AnnotationGreetingServiceImpl implements GreetingService {
 
     private void sleepWhile() {
         try {
-            Thread.sleep(3000);
+            Thread.sleep(2000);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
diff --git a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/NotifyImpl.java b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/NotifyImpl.java
new file mode 100644
index 0000000..c9c1663
--- /dev/null
+++ b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/NotifyImpl.java
@@ -0,0 +1,68 @@
+/*
+ * 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.annotation.impl;
+
+
+import org.apache.dubbo.samples.annotation.api.Notify;
+
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component("notify")
+public class NotifyImpl implements Notify {
+    private List<String> invokes = new ArrayList<>();
+    private Map<String, String> returns = new HashMap<>();
+    private Map<String, Throwable> exceptions = new HashMap<>();
+
+    @Override
+    public void oninvoke(String request) {
+        System.out.println("oninvoke - request: " + request);
+        invokes.add(request);
+    }
+
+    @Override
+    public void onreturn(String response, String request) {
+        System.out.println("onreturn - req: " + request + ", res: " + response);
+        returns.put(request, response);
+    }
+
+    @Override
+    public void onthrow(Throwable ex, String request) {
+        System.out.println("onthrow - request: " + request + ", exception: " + ex);
+        exceptions.put(request, ex);
+    }
+
+    @Override
+    public List<String> getInvokes() {
+        return invokes;
+    }
+
+    @Override
+    public Map<String, String> getReturns() {
+        return returns;
+    }
+
+    @Override
+    public Map<String, Throwable> getExceptions() {
+        return exceptions;
+    }
+}
diff --git a/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java b/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java
index ce5e191..aceef35 100644
--- a/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java
+++ b/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java
@@ -39,12 +39,12 @@ public class AnnotationServicesIT {
 
     @Test
     public void testSayGoodbye() throws Exception {
-        Assert.assertEquals("Goodbye, dubbo", annotationAction.doSayGoodbye("dubbo"));
+        Assert.assertEquals("Throw Exception", annotationAction.doSayGoodbye("dubbo"));
     }
 
     @Test
     public void testGreeting() throws Exception {
-        Assert.assertEquals("Throw Exception", annotationAction.doGreeting("dubbo"));
+        Assert.assertEquals("Annotation, greeting dubbo", annotationAction.doGreeting("dubbo"));
     }
 
     @Test


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