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

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


The following commit(s) were added to refs/heads/master by this push:
     new 79cb53d  refactor sample-annotation and introduce @Method
79cb53d is described below

commit 79cb53d9603e0056c14632b25742c6b7325bc93c
Author: cvictory <[email protected]>
AuthorDate: Tue Mar 12 18:42:52 2019 +0800

    refactor sample-annotation and introduce @Method
---
 dubbo-samples-annotation/pom.xml                   |  5 ++
 .../AnnotationConstants.java}                      | 11 +--
 .../AnnotationConsumerBootstrap.java}              | 18 +++--
 .../AnnotationProviderBootstrap.java}              |  6 +-
 .../{simple => }/annotation/EmbeddedZooKeeper.java |  2 +-
 .../annotation/action/AnnotationAction.java        | 85 ++++++++++++++++++++++
 .../impl/AnnotationGreetingServiceImpl.java}       | 31 ++++++--
 .../impl/AnnotationHelloServiceImpl.java}          | 30 ++++++--
 .../simple/annotation/action/AnnotationAction.java | 40 ----------
 .../resources/spring/dubbo-consumer.properties     | 10 +--
 .../resources/spring/dubbo-provider.properties     | 10 +--
 .../dubbo/samples/api/client/GreetingService.java  |  4 +
 .../dubbo/samples/api/client/HelloService.java     |  3 +
 dubbo-samples-spring-hystrix/README.md             |  2 +-
 14 files changed, 172 insertions(+), 85 deletions(-)

diff --git a/dubbo-samples-annotation/pom.xml b/dubbo-samples-annotation/pom.xml
index cdcf56c..58d9b65 100644
--- a/dubbo-samples-annotation/pom.xml
+++ b/dubbo-samples-annotation/pom.xml
@@ -212,6 +212,11 @@
             <artifactId>spring-context-support</artifactId>
             <version>1.0.2</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-samples-api-client</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
 
diff --git 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/api/AnnotationService.java
 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConstants.java
similarity index 83%
rename from 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/api/AnnotationService.java
rename to 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConstants.java
index e4a3818..678805b 100644
--- 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/api/AnnotationService.java
+++ 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConstants.java
@@ -16,14 +16,11 @@
  *   limitations under the License.
  *
  */
-
-package org.apache.dubbo.samples.simple.annotation.api;
+package org.apache.dubbo.samples.annotation;
 
 /**
- * AsyncService
+ * @author cvictory ON 2019-03-12
  */
-public interface AnnotationService {
-
-    String sayHello(String name);
-
+public interface AnnotationConstants {
+    static final String VERSION = "1.0.0_annotation";
 }
diff --git 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/AnnotationConsumer.java
 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java
similarity index 72%
rename from 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/AnnotationConsumer.java
rename to 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java
index 0d39fa9..6159d2b 100644
--- 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/AnnotationConsumer.java
+++ 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java
@@ -17,10 +17,10 @@
  *
  */
 
-package org.apache.dubbo.samples.simple.annotation;
+package org.apache.dubbo.samples.annotation;
 
 import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
-import org.apache.dubbo.samples.simple.annotation.action.AnnotationAction;
+import org.apache.dubbo.samples.annotation.action.AnnotationAction;
 
 import 
org.springframework.context.annotation.AnnotationConfigApplicationContext;
 import org.springframework.context.annotation.ComponentScan;
@@ -30,21 +30,25 @@ import 
org.springframework.context.annotation.PropertySource;
 /**
  * CallbackConsumer
  */
-public class AnnotationConsumer {
+public class AnnotationConsumerBootstrap {
 
     public static void main(String[] args) throws Exception {
         AnnotationConfigApplicationContext context = new 
AnnotationConfigApplicationContext(ConsumerConfiguration.class);
         context.start();
         final AnnotationAction annotationAction = (AnnotationAction) 
context.getBean("annotationAction");
-        String hello = annotationAction.doSayHello("world");
-        System.out.println("result :" + hello);
+
+        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.in.read();
     }
 
+
     @Configuration
-    @EnableDubbo(scanBasePackages = 
"org.apache.dubbo.samples.simple.annotation.action")
+    @EnableDubbo(scanBasePackages = 
"org.apache.dubbo.samples.annotation.action")
     @PropertySource("classpath:/spring/dubbo-consumer.properties")
-    @ComponentScan(value = 
{"org.apache.dubbo.samples.simple.annotation.action"})
+    @ComponentScan(value = {"org.apache.dubbo.samples.annotation.action"})
     static public class ConsumerConfiguration {
 
     }
diff --git 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/AnnotationProvider.java
 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationProviderBootstrap.java
similarity index 91%
rename from 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/AnnotationProvider.java
rename to 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationProviderBootstrap.java
index 4606e44..ec46463 100644
--- 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/AnnotationProvider.java
+++ 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationProviderBootstrap.java
@@ -17,7 +17,7 @@
  *
  */
 
-package org.apache.dubbo.samples.simple.annotation;
+package org.apache.dubbo.samples.annotation;
 
 
 import org.apache.dubbo.config.ProviderConfig;
@@ -31,7 +31,7 @@ import org.springframework.context.annotation.PropertySource;
 /**
  * MergeProvider
  */
-public class AnnotationProvider {
+public class AnnotationProviderBootstrap {
 
     public static void main(String[] args) throws Exception {
         new EmbeddedZooKeeper(2181, false).start();
@@ -41,7 +41,7 @@ public class AnnotationProvider {
     }
 
     @Configuration
-    @EnableDubbo(scanBasePackages = 
"org.apache.dubbo.samples.simple.annotation.impl")
+    @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.annotation.impl")
     @PropertySource("classpath:/spring/dubbo-provider.properties")
     static public class ProviderConfiguration {
         @Bean
diff --git 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/EmbeddedZooKeeper.java
 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/EmbeddedZooKeeper.java
similarity index 99%
rename from 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/EmbeddedZooKeeper.java
rename to 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/EmbeddedZooKeeper.java
index eaab029..0018215 100644
--- 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/EmbeddedZooKeeper.java
+++ 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/EmbeddedZooKeeper.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.dubbo.samples.simple.annotation;
+package org.apache.dubbo.samples.annotation;
 
 import java.io.File;
 import java.lang.reflect.Method;
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
new file mode 100644
index 0000000..365a8e3
--- /dev/null
+++ 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java
@@ -0,0 +1,85 @@
+/*
+ *
+ *   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.action;
+
+import org.apache.dubbo.config.annotation.Reference;
+import org.apache.dubbo.samples.annotation.AnnotationConstants;
+import org.apache.dubbo.samples.api.client.GreetingService;
+import org.apache.dubbo.samples.api.client.HelloService;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * AnnotationAction
+ */
+@Component("annotationAction")
+public class AnnotationAction {
+
+    @Reference(interfaceClass = HelloService.class, version = 
AnnotationConstants.VERSION)
+    private HelloService helloService;
+
+    /**
+     * @since 2.7.1
+     */
+    //@Reference(interfaceClass = GreetingService.class, version = 
AnnotationConstants.VERSION, methods = {@Method(name = "greeting", timeout = 
250, retries = 1)})
+    private GreetingService greetingService;
+
+    public String doSayHello(String name) {
+        try {
+            return helloService.sayHello(name);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "Throw Exception";
+        }
+    }
+
+    public String doSayGoodbye(String name) {
+
+        try {
+            return helloService.sayGoodbye(name);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "Throw Exception";
+        }
+
+    }
+
+    public String doGreeting(String name) {
+
+        try {
+            return greetingService.greeting(name);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "Throw Exception";
+        }
+
+    }
+
+    public String replyGreeting(String name) {
+        try {
+            return greetingService.replyGreeting(name);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "Throw Exception";
+        }
+
+    }
+
+}
diff --git 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/impl/AnnotationServiceImpl.java
 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java
similarity index 50%
copy from 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/impl/AnnotationServiceImpl.java
copy to 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java
index 73b0707..e869660 100644
--- 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/impl/AnnotationServiceImpl.java
+++ 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java
@@ -14,21 +14,36 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.dubbo.samples.simple.annotation.impl;
+package org.apache.dubbo.samples.annotation.impl;
 
 import org.apache.dubbo.config.annotation.Service;
-import org.apache.dubbo.samples.simple.annotation.api.AnnotationService;
+import org.apache.dubbo.samples.annotation.AnnotationConstants;
+import org.apache.dubbo.samples.api.client.GreetingService;
 
 /**
- *
+ * 2019-03-12
  */
-@Service
-public class AnnotationServiceImpl implements AnnotationService {
+@Service(version = AnnotationConstants.VERSION)
+public class AnnotationGreetingServiceImpl implements GreetingService {
 
     @Override
-    public String sayHello(String name) {
-        System.out.println("async provider received: " + name);
-        return "annotation: hello, " + name;
+    public String greeting(String name) {
+        System.out.println("provider received invoke of greeting: " + name);
+        sleepWhile();
+        return "Annotation, greeting " + name;
+    }
+
+    public String replyGreeting(String name) {
+        System.out.println("provider received invoke of replyGreeting: " + 
name);
+        sleepWhile();
+        return "Annotation, fine " + name;
     }
 
+    private void sleepWhile() {
+        try {
+            Thread.sleep(300);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
 }
diff --git 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/impl/AnnotationServiceImpl.java
 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationHelloServiceImpl.java
similarity index 52%
rename from 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/impl/AnnotationServiceImpl.java
rename to 
dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationHelloServiceImpl.java
index 73b0707..fe4146d 100644
--- 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/impl/AnnotationServiceImpl.java
+++ 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationHelloServiceImpl.java
@@ -14,21 +14,35 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.dubbo.samples.simple.annotation.impl;
+package org.apache.dubbo.samples.annotation.impl;
 
-import org.apache.dubbo.config.annotation.Service;
-import org.apache.dubbo.samples.simple.annotation.api.AnnotationService;
+import org.apache.dubbo.samples.api.client.HelloService;
 
 /**
- *
+ * @since 2.7.1
  */
-@Service
-public class AnnotationServiceImpl implements AnnotationService {
+//@Service(version = AnnotationConstants.VERSION, methods = {@Method(name = 
"sayGoodbye", timeout = 250, retries = 0)})
+public class AnnotationHelloServiceImpl implements HelloService {
 
     @Override
     public String sayHello(String name) {
-        System.out.println("async provider received: " + name);
-        return "annotation: hello, " + name;
+        System.out.println("provider received invoke of sayHello: " + name);
+        sleepWhile();
+        return "Annotation, hello " + name;
+    }
+
+    public String sayGoodbye(String name) {
+        System.out.println("provider received invoke of sayGoodbye: " + name);
+        sleepWhile();
+        return "Goodbye, " + name;
+    }
+
+    private void sleepWhile() {
+        try {
+            Thread.sleep(300);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
     }
 
 }
diff --git 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/action/AnnotationAction.java
 
b/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/action/AnnotationAction.java
deleted file mode 100644
index 87abc4a..0000000
--- 
a/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/simple/annotation/action/AnnotationAction.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *
- *   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.simple.annotation.action;
-
-import org.apache.dubbo.config.annotation.Reference;
-import org.apache.dubbo.samples.simple.annotation.api.AnnotationService;
-
-import org.springframework.stereotype.Component;
-
-/**
- * AnnotationAction
- */
-@Component("annotationAction")
-public class AnnotationAction {
-
-    @Reference
-    private AnnotationService annotationService;
-
-    public String doSayHello(String name) {
-        return annotationService.sayHello(name);
-    }
-
-}
diff --git 
a/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties 
b/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties
index 96ab667..40ad921 100644
--- 
a/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties
+++ 
b/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties
@@ -6,17 +6,17 @@
 #   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.
-#  
+#
 #
 
-dubbo.application.name=annotation-consumer
+dubbo.application.name=samples-annotation-consumer
 dubbo.registry.address=zookeeper://127.0.0.1:2181
-dubbo.consumer.timeout=3000
\ No newline at end of file
+dubbo.consumer.timeout=3000
diff --git 
a/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties 
b/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties
index 51fccca..be30389 100644
--- 
a/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties
+++ 
b/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties
@@ -6,18 +6,18 @@
 #   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.
-#  
+#
 #
 
-dubbo.application.name=annotation-provider
+dubbo.application.name=samples-annotation-provider
 dubbo.registry.address=zookeeper://127.0.0.1:2181
 dubbo.protocol.name=dubbo
-dubbo.protocol.port=20880
\ No newline at end of file
+dubbo.protocol.port=20880
diff --git 
a/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/GreetingService.java
 
b/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/GreetingService.java
index 73b87da..cdc27c4 100644
--- 
a/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/GreetingService.java
+++ 
b/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/GreetingService.java
@@ -25,6 +25,10 @@ public interface GreetingService {
 
     String greeting(String name);
 
+    default String replyGreeting(String name) {
+        return "Fine, " + name;
+    }
+
     default CompletableFuture<String> greeting(String name, byte signal) {
         return CompletableFuture.completedFuture(greeting(name));
     }
diff --git 
a/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/HelloService.java
 
b/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/HelloService.java
index 44a4f13..fdc38e4 100644
--- 
a/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/HelloService.java
+++ 
b/dubbo-samples-api-client/src/main/java/org/apache/dubbo/samples/api/client/HelloService.java
@@ -23,4 +23,7 @@ public interface HelloService {
 
     String sayHello(String name);
 
+    default String sayGoodbye(String name) {
+        return "Goodbye, " + name;
+    }
 }
diff --git a/dubbo-samples-spring-hystrix/README.md 
b/dubbo-samples-spring-hystrix/README.md
index 12c735e..7fe4f0c 100644
--- a/dubbo-samples-spring-hystrix/README.md
+++ b/dubbo-samples-spring-hystrix/README.md
@@ -7,7 +7,7 @@ Run `org.apache.dubbo.samples.annotation.AnnotationProvider`
 
 ### Start Consumer
 
-Run `org.apache.dubbo.samples.annotation.AnnotationConsumer`
+Run `org.apache.dubbo.samples.annotation.AnnotationConsumerBootstrap`
 
 ### Result
 


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

Reply via email to