Browse Source

优化消息模块,靠不靠谱还有待商榷!

zhouhao 8 years ago
parent
commit
c88b45bd8a
14 changed files with 369 additions and 62 deletions
  1. 30 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageContext.java
  2. 0 10
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageListener.java
  3. 0 17
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageManager.java
  4. 29 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageSubject.java
  5. 32 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageSubscribe.java
  6. 49 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Messager.java
  7. 33 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/annotation/MessageConsumer.java
  8. 33 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/annotation/MessageSupplier.java
  9. 35 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/builder/MessageBuilder.java
  10. 38 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/builder/MessageSubjectBuilder.java
  11. 30 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/DataMessage.java
  12. 30 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/ObjectMessage.java
  13. 30 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/TextMessage.java
  14. 0 35
      hsweb-message/hsweb-message-jms/src/main/java/org/hswebframework/web/message/jms/JmsMessageManager.java

+ 30 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageContext.java

@@ -0,0 +1,30 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message;
+
+/**
+ * @author zhouhao
+ */
+public interface MessageContext {
+    MessageContext from(MessageSubject subject);
+
+    MessageContext to(MessageSubject subject);
+
+    void send();
+}

+ 0 - 10
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageListener.java

@@ -1,10 +0,0 @@
-package org.hswebframework.web.message;
-
-/**
- * TODO 完成注释
- *
- * @author zhouhao
- */
-public interface MessageListener<T extends Message> {
-    void onMessage(T message);
-}

+ 0 - 17
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageManager.java

@@ -1,17 +0,0 @@
-package org.hswebframework.web.message;
-
-/**
- * TODO 完成注释
- *
- * @author zhouhao
- */
-public interface MessageManager {
-
-    void send(String toUser,String destination, Message message);
-
-    void publish(String topic, Message message);
-
-    <T extends Message> void subscribe(String topic, MessageListener<T> listener);
-
-    void deSubscribe(String topic);
-}

+ 29 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageSubject.java

@@ -0,0 +1,29 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message;
+
+import java.io.Serializable;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface MessageSubject extends Serializable {
+}

+ 32 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageSubscribe.java

@@ -0,0 +1,32 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message;
+
+import java.util.function.Consumer;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface MessageSubscribe<M extends Message> {
+    MessageSubscribe<M> iam(MessageSubject iam);
+
+    MessageSubscribe<M> onMessage(Consumer<M> consumer);
+}

+ 49 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Messager.java

@@ -0,0 +1,49 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message;
+
+/**
+ * <pre>
+ *     messager
+ *     .create(text("hello"))
+ *     .from(system())
+ *     .to(user("admin"))
+ *     .send();
+ * </pre>
+ * <pre>
+ *     messager
+ *     .create(object(user))
+ *     .from(system())
+ *     .to(topic("user-login"))
+ *     .send();
+ * </pre>
+ * <pre>
+ *     messager
+ *     .subscribe(topic("user-login"))
+ *     .iam(user("admin"))
+ *     .onMessage(user->System.out.println(user));
+ * </pre>
+ *
+ * @author zhouhao
+ */
+public interface Messager {
+    MessageContext create(Message message);
+
+    <M extends Message> MessageSubscribe<M> subscribe(MessageSubject subscribe);
+}

+ 33 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/annotation/MessageConsumer.java

@@ -0,0 +1,33 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * @author zhouhao
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface MessageConsumer {
+    String topic() default "";
+
+}

+ 33 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/annotation/MessageSupplier.java

@@ -0,0 +1,33 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message.annotation;
+
+
+import java.lang.annotation.*;
+
+/**
+ * @author zhouhao
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface MessageSupplier {
+    
+}

+ 35 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/builder/MessageBuilder.java

@@ -0,0 +1,35 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message.builder;
+
+import org.hswebframework.web.message.support.DataMessage;
+import org.hswebframework.web.message.support.ObjectMessage;
+import org.hswebframework.web.message.support.TextMessage;
+
+/**
+ * @author zhouhao
+ */
+public interface MessageBuilder {
+    TextMessage text(String msg);
+
+    <T> ObjectMessage object(T msg);
+
+    DataMessage data(byte[] msg);
+
+}

+ 38 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/builder/MessageSubjectBuilder.java

@@ -0,0 +1,38 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message.builder;
+
+import org.hswebframework.web.message.MessageSubject;
+
+import java.util.Set;
+
+/**
+ * @author zhouhao
+ */
+public interface MessageSubjectBuilder {
+    MessageSubject user(String userId);
+
+    MessageSubject users(String... userIds);
+
+    MessageSubject users(Set<String> userIds);
+
+    MessageSubject system();
+
+    MessageSubject topic(String subId);
+}

+ 30 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/DataMessage.java

@@ -0,0 +1,30 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message.support;
+
+import org.hswebframework.web.message.Message;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface DataMessage extends Message {
+    byte[] getMessage();
+}

+ 30 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/ObjectMessage.java

@@ -0,0 +1,30 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message.support;
+
+import org.hswebframework.web.message.Message;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface ObjectMessage<T> extends Message {
+    T getObject();
+}

+ 30 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/TextMessage.java

@@ -0,0 +1,30 @@
+/*
+ *  Copyright 2016 http://www.hswebframework.org
+ *
+ *  Licensed 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.hswebframework.web.message.support;
+
+import org.hswebframework.web.message.Message;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface TextMessage extends Message {
+    String getMessage();
+}

+ 0 - 35
hsweb-message/hsweb-message-jms/src/main/java/org/hswebframework/web/message/jms/JmsMessageManager.java

@@ -1,35 +0,0 @@
-package org.hswebframework.web.message.jms;
-
-import org.hswebframework.web.message.Message;
-import org.hswebframework.web.message.MessageListener;
-import org.hswebframework.web.message.MessageManager;
-import org.springframework.jms.core.JmsTemplate;
-
-/**
- * TODO 完成注释
- *
- * @author zhouhao
- */
-public class JmsMessageManager implements MessageManager {
-    JmsTemplate jmsTemplate;
-
-    @Override
-    public void send(String toUser,String destination, Message message) {
-
-    }
-
-    @Override
-    public void publish(String topic, Message message) {
-
-    }
-
-    @Override
-    public <T extends Message> void subscribe(String topic, MessageListener<T> listener) {
-
-    }
-
-    @Override
-    public void deSubscribe(String topic) {
-
-    }
-}