Ver código fonte

0327 callback

Qing 1 ano atrás
pai
commit
3915fe4223

+ 89 - 29
rocketmq-demo/.idea/workspace.xml

@@ -4,17 +4,14 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="cc632264-3e04-48d2-b24e-1e5609483d8e" name="Changes" comment="">
+    <list default="true" id="cc632264-3e04-48d2-b24e-1e5609483d8e" name="Changes" comment="0324 rocketmq">
       <change afterPath="$PROJECT_DIR$/../.idea/VIPJAVA.iml" afterDir="false" />
       <change afterPath="$PROJECT_DIR$/../gn_oa_vip27/.idea/google-java-format.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/helloworld/Consumer.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/helloworld/Producer.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/message/AsyncProducer.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/message/OnewayProducer.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/callback/Answer.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/callback/CallBack.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/callback/Person.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/callback/Person1.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/callback/Test.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/java/com/lc/mapper/UserMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/java/com/lc/mapper/UserMapper.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../02_JavaWeb/day07_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../02_JavaWeb/day07_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" afterDir="false" />
@@ -22,15 +19,22 @@
       <change beforePath="$PROJECT_DIR$/../gn_oa_vip27/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../gn_oa_vip27/.idea/misc.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../gn_oa_vip27/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../gn_oa_vip27/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../gn_oa_vip27/src/main/java/com/sf/utils/JdbcUtil.java" beforeDir="false" afterPath="$PROJECT_DIR$/../gn_oa_vip27/src/main/java/com/sf/utils/JdbcUtil.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
     <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
     <option name="LAST_RESOLUTION" value="IGNORE" />
   </component>
+  <component name="ChangesViewManager">
+    <option name="groupingKeys">
+      <option value="directory" />
+    </option>
+  </component>
   <component name="FileTemplateManagerImpl">
     <option name="RECENT_TEMPLATES">
       <list>
+        <option value="Interface" />
         <option value="Class" />
       </list>
     </option>
@@ -38,9 +42,9 @@
   <component name="Git.Settings">
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
   </component>
-  <component name="ProjectColorInfo"><![CDATA[{
-  "associatedIndex": 5
-}]]></component>
+  <component name="ProjectColorInfo">{
+  &quot;associatedIndex&quot;: 5
+}</component>
   <component name="ProjectId" id="2e7riCGNDFRhmF7p5dUKghzhJFb" />
   <component name="ProjectLevelVcsManager">
     <ConfirmationsSetting value="2" id="Add" />
@@ -55,6 +59,7 @@
     "Application.Consumer.executor": "Run",
     "Application.OnewayProducer.executor": "Run",
     "Application.Producer.executor": "Run",
+    "Application.Test.executor": "Run",
     "Maven. [org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate].executor": "Run",
     "RunOnceActivity.OpenProjectViewOnStart": "true",
     "RunOnceActivity.ShowReadmeOnStart": "true",
@@ -69,7 +74,12 @@
     "vue.rearranger.settings.migration": "true"
   }
 }]]></component>
-  <component name="RunManager" selected="Application.OnewayProducer">
+  <component name="RecentsManager">
+    <key name="CopyClassDialog.RECENTS_KEY">
+      <recent name="com.sf.callback" />
+    </key>
+  </component>
+  <component name="RunManager" selected="Application.Test">
     <configuration name="AsyncProducer (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
       <option name="MAIN_CLASS_NAME" value="com.sf.message.AsyncProducer" />
       <module name="rocketmq-demo" />
@@ -83,12 +93,12 @@
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="AsyncProducer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="com.sf.message.AsyncProducer" />
+    <configuration name="Consumer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+      <option name="MAIN_CLASS_NAME" value="com.sf.helloworld.Consumer" />
       <module name="rocketmq-demo" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.message.*" />
+          <option name="PATTERN" value="com.sf.helloworld.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
@@ -96,12 +106,12 @@
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="Consumer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="com.sf.helloworld.Consumer" />
+    <configuration name="OnewayProducer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+      <option name="MAIN_CLASS_NAME" value="com.sf.message.OnewayProducer" />
       <module name="rocketmq-demo" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.helloworld.*" />
+          <option name="PATTERN" value="com.sf.message.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
@@ -109,12 +119,12 @@
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="OnewayProducer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="com.sf.message.OnewayProducer" />
+    <configuration name="Producer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+      <option name="MAIN_CLASS_NAME" value="com.sf.helloworld.Producer" />
       <module name="rocketmq-demo" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.message.*" />
+          <option name="PATTERN" value="com.sf.helloworld.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
@@ -122,12 +132,12 @@
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="Producer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="com.sf.helloworld.Producer" />
+    <configuration name="Test" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
+      <option name="MAIN_CLASS_NAME" value="com.sf.callback.Test" />
       <module name="rocketmq-demo" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.helloworld.*" />
+          <option name="PATTERN" value="com.sf.callback.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
@@ -137,11 +147,11 @@
     </configuration>
     <recent_temporary>
       <list>
+        <item itemvalue="Application.Test" />
+        <item itemvalue="Application.Producer" />
+        <item itemvalue="Application.Consumer" />
         <item itemvalue="Application.OnewayProducer" />
         <item itemvalue="Application.AsyncProducer (1)" />
-        <item itemvalue="Application.AsyncProducer" />
-        <item itemvalue="Application.Consumer" />
-        <item itemvalue="Application.Producer" />
       </list>
     </recent_temporary>
   </component>
@@ -153,11 +163,61 @@
       <option name="number" value="Default" />
       <option name="presentableId" value="Default" />
       <updated>1711266581667</updated>
-      <workItem from="1711266583057" duration="4047000" />
+      <workItem from="1711266583057" duration="4122000" />
+      <workItem from="1711533395564" duration="4228000" />
+    </task>
+    <task id="LOCAL-00001" summary="0324 rocketmq">
+      <option name="closed" value="true" />
+      <created>1711271538450</created>
+      <option name="number" value="00001" />
+      <option name="presentableId" value="LOCAL-00001" />
+      <option name="project" value="LOCAL" />
+      <updated>1711271538450</updated>
     </task>
+    <option name="localTasksCounter" value="2" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
     <option name="version" value="3" />
   </component>
+  <component name="Vcs.Log.Tabs.Properties">
+    <option name="OPEN_GENERIC_TABS">
+      <map>
+        <entry key="3895a3d2-79df-4765-8c62-8961ee80125f" value="TOOL_WINDOW" />
+      </map>
+    </option>
+    <option name="TAB_STATES">
+      <map>
+        <entry key="3895a3d2-79df-4765-8c62-8961ee80125f">
+          <value>
+            <State>
+              <option name="FILTERS">
+                <map>
+                  <entry key="branch">
+                    <value>
+                      <list>
+                        <option value="HEAD" />
+                      </list>
+                    </value>
+                  </entry>
+                  <entry key="structure">
+                    <value>
+                      <list>
+                        <option value="dir:/Users/Qing/IdeaProjects/SiFu/VIPJAVA/rocketmq-demo" />
+                      </list>
+                    </value>
+                  </entry>
+                </map>
+              </option>
+              <option name="SHOW_ONLY_AFFECTED_CHANGES" value="true" />
+            </State>
+          </value>
+        </entry>
+      </map>
+    </option>
+  </component>
+  <component name="VcsManagerConfiguration">
+    <MESSAGE value="0324 rocketmq" />
+    <option name="LAST_COMMIT_MESSAGE" value="0324 rocketmq" />
+  </component>
 </project>

+ 46 - 0
rocketmq-demo/src/main/java/com/sf/callback/Answer.java

@@ -0,0 +1,46 @@
+package com.sf.callback;
+
+import java.util.concurrent.TimeUnit;
+
+public class Answer {
+
+    // 作为问题的回答者  如果想要支持回答之后的通知功能
+    // 要将描述通知方式的接口 作为方法的入参
+    public void ans(CallBack callBack) {
+        // 要被如何通知  需要在调用之前就声明的
+        System.out.println("接收问题");
+        try {
+            TimeUnit.SECONDS.sleep(2);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        System.out.println("回答完毕");
+        // 回答之后的回调
+        // 返回之后调用的逻辑
+        callBack.call("111");
+    }
+
+    public void ans(CallBack callBack, CallBack callBack1) {
+        boolean flag = true;
+        if (flag) {
+            callBack.call("ok");
+        } else {
+            callBack1.call("fail");
+        }
+    }
+
+    public String ans1() {
+        return "111";
+    }
+
+    // 1 短信 2 电话
+    public String ans2(int type) {
+        switch (type) {
+            case 1:
+                break;
+            case 2:
+                break;
+        }
+        return "111";
+    }
+}

+ 10 - 0
rocketmq-demo/src/main/java/com/sf/callback/CallBack.java

@@ -0,0 +1,10 @@
+package com.sf.callback;
+
+// 模拟一个问答场景  一个人问 一个人答
+//    这个人在问完问题后  能够让回答者回答完问题 通知他  通过调用这个回调接口来通知
+// 声明一个回调接口
+public interface CallBack {
+    // 使用CallBack接口来传递  提问者想要的通知方式
+    //  通知的具体逻辑需要实现call方法
+    void call(String str);
+}

+ 24 - 0
rocketmq-demo/src/main/java/com/sf/callback/Person.java

@@ -0,0 +1,24 @@
+package com.sf.callback;
+
+// 提问者
+public class Person implements CallBack {
+    // 明确被调用者
+    private Answer answer;
+
+    public Person(Answer answer) {
+        this.answer = answer;
+    }
+
+    // 提问题的逻辑
+    public void ask() {
+        // 找到回答的人 调用回答的逻辑
+        answer.ans(this);
+    }
+
+    // 明确answer回答之后的  通知方式(回调逻辑)
+    @Override
+    public void call(String str) {
+        System.out.println("收到答案: " + str);
+    }
+
+}

+ 24 - 0
rocketmq-demo/src/main/java/com/sf/callback/Person1.java

@@ -0,0 +1,24 @@
+package com.sf.callback;
+
+// 提问者
+public class Person1 implements CallBack {
+    // 明确被调用者
+    private Answer answer;
+
+    public Person1(Answer answer) {
+        this.answer = answer;
+    }
+
+    // 提问题的逻辑
+    public void ask() {
+        // 找到回答的人 调用回答的逻辑
+        answer.ans(this);
+    }
+
+    // 明确answer回答之后的  通知方式(回调逻辑)
+    @Override
+    public void call(String str) {
+        System.out.println("答案: " + str);
+        System.out.println("谢谢");
+    }
+}

+ 17 - 0
rocketmq-demo/src/main/java/com/sf/callback/Test.java

@@ -0,0 +1,17 @@
+package com.sf.callback;
+
+public class Test {
+
+    public static void main(String[] args) {
+        System.out.println("start");
+        // 创建了一个回答者
+        Answer answer = new Answer();
+        // 创建了一个提问者 使用了之前创建的回答者
+        Person person = new Person(answer);
+        person.ask();
+
+        Person1 person1 = new Person1(answer);
+        person1.ask();
+        System.out.println("end");
+    }
+}