瀏覽代碼

简单优化api

zhouhao 8 年之前
父節點
當前提交
1eab9d3a03
共有 17 個文件被更改,包括 682 次插入12 次删除
  1. 36 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessagePublish.java
  2. 21 3
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Messager.java
  3. 2 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/builder/MessageBuilder.java
  4. 7 4
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/builder/MessageSubjectBuilder.java
  5. 32 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/MultipleUserMessageSubject.java
  6. 34 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/ServiceInvokerMessage.java
  7. 29 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/TopicMessageSubject.java
  8. 30 0
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/UserMessageSubject.java
  9. 5 5
      hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageContext.java
  10. 56 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessagePublish.java
  11. 81 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessageSubscribe.java
  12. 45 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessageTests.java
  13. 86 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessager.java
  14. 52 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/SimpleMessageBuilder.java
  15. 60 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/SimpleMessageSubjectBuilder.java
  16. 49 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/StaticMessageBuilder.java
  17. 57 0
      hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/StaticMessageSubjectBuilder.java

+ 36 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessagePublish.java

@@ -0,0 +1,36 @@
+/*
+ *  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;
+
+/**
+ * @author zhouhao
+ */
+public interface MessagePublish {
+    MessagePublish from(MessageSubject subject);
+
+    MessagePublish to(MessageSubject subject);
+
+    MessagePublish deleteOnTimeout(long timeOutSecond);
+
+    <T> T send();
+
+    <T> void send(Consumer<T> responseConsumer);
+}

+ 21 - 3
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Messager.java

@@ -19,31 +19,49 @@
 package org.hswebframework.web.message;
 
 /**
+ * simple
  * <pre>
  *     messager
- *     .create(text("hello"))
+ *     .publish(text("hello"))
  *     .from(system())
  *     .to(user("admin"))
  *     .send();
  * </pre>
+ * service invoke
+ * <pre>
+ *    User admin = messager
+ *     .publish(service("userService"))
+ *     .from(system())
+ *     .to(method("getById","admin"))
+ *     .send();
+ * </pre>
+ * send object to topic
  * <pre>
  *     messager
- *     .create(object(user))
+ *     .publish(object(user))
  *     .from(system())
  *     .to(topic("user-login"))
  *     .send();
  * </pre>
+ * subscribe topic
  * <pre>
  *     messager
  *     .subscribe(topic("user-login"))
  *     .iam(user("admin"))
  *     .onMessage(user->System.out.println(user));
  * </pre>
+ * subscribe user msg
+ * <pre>
+ *      messager
+ *     .subscribe(user("admin"))
+ *     .onMessage(message->System.out.println(message));
+ * </pre>
  *
  * @author zhouhao
+ * @since 3.0
  */
 public interface Messager {
-    MessageContext create(Message message);
+    MessagePublish publish(Message message);
 
     <M extends Message> MessageSubscribe<M> subscribe(MessageSubject subscribe);
 }

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

@@ -20,6 +20,7 @@ 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.ServiceInvokerMessage;
 import org.hswebframework.web.message.support.TextMessage;
 
 /**
@@ -32,4 +33,5 @@ public interface MessageBuilder {
 
     DataMessage data(byte[] msg);
 
+    ServiceInvokerMessage service(String serviceName);
 }

+ 7 - 4
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/builder/MessageSubjectBuilder.java

@@ -19,6 +19,9 @@
 package org.hswebframework.web.message.builder;
 
 import org.hswebframework.web.message.MessageSubject;
+import org.hswebframework.web.message.support.MultipleUserMessageSubject;
+import org.hswebframework.web.message.support.TopicMessageSubject;
+import org.hswebframework.web.message.support.UserMessageSubject;
 
 import java.util.Set;
 
@@ -26,13 +29,13 @@ import java.util.Set;
  * @author zhouhao
  */
 public interface MessageSubjectBuilder {
-    MessageSubject user(String userId);
+    UserMessageSubject user(String userId);
 
-    MessageSubject users(String... userIds);
+    MultipleUserMessageSubject users(String... userIds);
 
-    MessageSubject users(Set<String> userIds);
+    MultipleUserMessageSubject users(Set<String> userIds);
 
     MessageSubject system();
 
-    MessageSubject topic(String subId);
+    TopicMessageSubject topic(String topic);
 }

+ 32 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/MultipleUserMessageSubject.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.support;
+
+import org.hswebframework.web.message.MessageSubject;
+
+import java.util.Set;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface MultipleUserMessageSubject extends MessageSubject {
+    Set<String> getUserIdList();
+}

+ 34 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/ServiceInvokerMessage.java

@@ -0,0 +1,34 @@
+/*
+ *  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;
+
+import java.io.Serializable;
+
+/**
+ * @author zhouhao
+ */
+public interface ServiceInvokerMessage extends Message {
+    String getServiceName();
+
+    String getMethod();
+
+    Serializable[] getArgs();
+}

+ 29 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/TopicMessageSubject.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.support;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface TopicMessageSubject {
+    String getTopic();
+
+}

+ 30 - 0
hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/support/UserMessageSubject.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.MessageSubject;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public interface UserMessageSubject extends MessageSubject {
+    String getUserId();
+}

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

@@ -19,12 +19,12 @@
 package org.hswebframework.web.message;
 
 /**
+ * TODO 完成注释
+ *
  * @author zhouhao
  */
-public interface MessageContext {
-    MessageContext from(MessageSubject subject);
-
-    MessageContext to(MessageSubject subject);
+public interface MessagePublishHanlder {
+    boolean isSupport(Message message);
 
-    void send();
+    MessagePublish handle(Message message);
 }

+ 56 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessagePublish.java

@@ -0,0 +1,56 @@
+/*
+ *  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 abstract class SimpleMessagePublish implements MessagePublish {
+    MessageSubject from;
+
+    MessageSubject to;
+
+    @Override
+    public MessagePublish from(MessageSubject subject) {
+        this.from = subject;
+        return this;
+    }
+
+    @Override
+    public MessagePublish to(MessageSubject subject) {
+        this.to = subject;
+
+        return this;
+    }
+
+    @Override
+    public MessagePublish deleteOnTimeout(long timeOutSecond) {
+        //not support now
+        return this;
+    }
+
+    @Override
+    public <T> void send(Consumer<T> responseConsumer) {
+        responseConsumer.accept(send());
+    }
+}

+ 81 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessageSubscribe.java

@@ -0,0 +1,81 @@
+/*
+ *  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.ArrayList;
+import java.util.List;
+import java.util.Queue;
+import java.util.function.Consumer;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public class SimpleMessageSubscribe<T extends Message> implements MessageSubscribe<T> {
+    MessageSubject im;
+
+    MessageSubject subject;
+
+    final List<Consumer<T>> consumers = new ArrayList<>();
+
+    Queue<T> queue;
+
+    boolean started = false;
+
+    boolean stop = false;
+
+    public SimpleMessageSubscribe(MessageSubject subject, Queue<T> queue) {
+        this.subject = subject;
+        this.queue = queue;
+    }
+
+    @Override
+    public MessageSubscribe<T> iam(MessageSubject iam) {
+        im = iam;
+        return this;
+    }
+
+    @Override
+    public MessageSubscribe<T> onMessage(Consumer<T> consumer) {
+        synchronized (consumers) {
+            consumers.add(consumer);
+        }
+        startConsumer();
+        return this;
+    }
+
+    public void startConsumer() {
+        if (started) return;
+        new Thread(() -> {
+
+            while (!stop) {
+                T msg = queue.poll();
+                if (msg != null)
+                    consumers.forEach(consumer -> consumer.accept(msg));
+                else
+                    try {
+                        Thread.sleep(50);
+                    } catch (InterruptedException e) {
+                        e.printStackTrace();
+                    }
+            }
+        }).start();
+    }
+}

+ 45 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessageTests.java

@@ -0,0 +1,45 @@
+/*
+ *  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 org.junit.Assert;
+import org.junit.Test;
+
+import static org.hswebframework.web.message.builder.StaticMessageBuilder.text;
+import static org.hswebframework.web.message.builder.StaticMessageSubjectBuilder.user;
+
+/**
+ * @author zhouhao
+ */
+public class SimpleMessageTests {
+    Messager messager = new SimpleMessager();
+
+    @Test
+    public void simpleTest() throws InterruptedException {
+        byte[] stat = new byte[1];
+        messager.subscribe(user("test"))
+                .onMessage(msg -> stat[0] = 1);
+        messager.publish(text("hello2"))
+                .to(user("test"))
+                .from(user("admin"))
+                .send();
+        Thread.sleep(1000);
+        Assert.assertEquals(stat[0], 1);
+    }
+}

+ 86 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/SimpleMessager.java

@@ -0,0 +1,86 @@
+/*
+ *  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 org.hswebframework.web.message.support.TextMessage;
+import org.hswebframework.web.message.support.UserMessageSubject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * @author zhouhao
+ */
+public class SimpleMessager implements Messager {
+
+    Map<String, Queue<Message>> queueStorage = new ConcurrentHashMap<>(256);
+
+    private Queue<Message> getQueue(String key) {
+        return queueStorage.computeIfAbsent(key, k -> new LinkedBlockingQueue<>());
+    }
+
+    List<MessagePublishHanlder> publishHanlders = new ArrayList<>();
+
+    public SimpleMessager() {
+        publishHanlders.add(new MessagePublishHanlder() {
+            @Override
+            public boolean isSupport(Message message) {
+                return message instanceof TextMessage;
+            }
+
+            @Override
+            public MessagePublish handle(Message message) {
+                return new SimpleMessagePublish() {
+                    @Override
+                    public <T> T send() {
+                        getQueue(buildKey(to)).add(message);
+                        return null;
+                    }
+
+                };
+            }
+        });
+    }
+
+    public String buildKey(MessageSubject subject) {
+        if (subject instanceof UserMessageSubject) {
+            return UserMessageSubject.class.getName().concat(((UserMessageSubject) subject).getUserId());
+        }
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public MessagePublish publish(Message message) {
+        return publishHanlders.stream()
+                .filter(handler -> handler.isSupport(message))
+                .findFirst()
+                .orElseThrow(UnsupportedOperationException::new)
+                .handle(message);
+    }
+
+    @Override
+    public <M extends Message> MessageSubscribe<M> subscribe(MessageSubject subscribe) {
+        return new SimpleMessageSubscribe(subscribe, getQueue(buildKey(subscribe)));
+    }
+
+}

+ 52 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/SimpleMessageBuilder.java

@@ -0,0 +1,52 @@
+/*
+ *  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.ServiceInvokerMessage;
+import org.hswebframework.web.message.support.TextMessage;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public class SimpleMessageBuilder implements MessageBuilder {
+    @Override
+    public TextMessage text(String msg) {
+        return (TextMessage) () -> msg;
+    }
+
+    @Override
+    public <T> ObjectMessage object(T msg) {
+        return (ObjectMessage) () -> msg;
+    }
+
+    @Override
+    public DataMessage data(byte[] msg) {
+        return (DataMessage) () -> msg;
+    }
+
+    @Override
+    public ServiceInvokerMessage service(String serviceName) {
+
+        return null;
+    }
+}

+ 60 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/SimpleMessageSubjectBuilder.java

@@ -0,0 +1,60 @@
+/*
+ *  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 org.hswebframework.web.message.support.MultipleUserMessageSubject;
+import org.hswebframework.web.message.support.TopicMessageSubject;
+import org.hswebframework.web.message.support.UserMessageSubject;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public class SimpleMessageSubjectBuilder implements MessageSubjectBuilder {
+    @Override
+    public UserMessageSubject user(String userId) {
+        return () -> userId;
+    }
+
+    @Override
+    public MultipleUserMessageSubject users(String... userIds) {
+        return (MultipleUserMessageSubject) () -> new HashSet<>(Arrays.asList(userIds));
+    }
+
+    @Override
+    public MultipleUserMessageSubject users(Set<String> userIds) {
+        return (MultipleUserMessageSubject) () -> userIds;
+    }
+
+    @Override
+    public MessageSubject system() {
+        return null;
+    }
+
+    @Override
+    public TopicMessageSubject topic(String topic) {
+        return () -> topic;
+    }
+}

+ 49 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/StaticMessageBuilder.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.builder;
+
+import org.hswebframework.web.message.support.DataMessage;
+import org.hswebframework.web.message.support.ObjectMessage;
+import org.hswebframework.web.message.support.ServiceInvokerMessage;
+import org.hswebframework.web.message.support.TextMessage;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public class StaticMessageBuilder {
+    private static MessageBuilder messageBuilder = new SimpleMessageBuilder();
+
+    public static TextMessage text(String msg) {
+        return messageBuilder.text(msg);
+    }
+
+    public <T> ObjectMessage object(T msg) {
+        return messageBuilder.object(msg);
+    }
+
+    public DataMessage data(byte[] msg) {
+        return messageBuilder.data(msg);
+    }
+
+    public ServiceInvokerMessage service(String serviceName) {
+        return messageBuilder.service(serviceName);
+    }
+}

+ 57 - 0
hsweb-message/hsweb-message-api/src/test/java/org/hswebframework/web/message/builder/StaticMessageSubjectBuilder.java

@@ -0,0 +1,57 @@
+/*
+ *  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 org.hswebframework.web.message.support.MultipleUserMessageSubject;
+import org.hswebframework.web.message.support.TopicMessageSubject;
+import org.hswebframework.web.message.support.UserMessageSubject;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+public class StaticMessageSubjectBuilder {
+    private static MessageSubjectBuilder messageSubjectBuilder = new SimpleMessageSubjectBuilder();
+
+    public static UserMessageSubject user(String userId) {
+        return messageSubjectBuilder.user(userId);
+    }
+
+    public static MultipleUserMessageSubject users(String... userIds) {
+        return messageSubjectBuilder.users(userIds);
+    }
+
+    public MultipleUserMessageSubject users(Set<String> userIds) {
+        return messageSubjectBuilder.users(userIds);
+    }
+
+    public MessageSubject system() {
+        return messageSubjectBuilder.system();
+    }
+
+    public TopicMessageSubject topic(String topic) {
+        return messageSubjectBuilder.topic(topic);
+    }
+}