From d9946ceb645d0b5e062f93e85dd6de1b5ab33933 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Mon, 22 May 2017 19:32:26 +0800 Subject: [PATCH] --- src/org/redkale/net/http/RestOnMessage.java | 39 +++++++ src/org/redkale/net/http/RestOnOpen.java | 32 ++++++ src/org/redkale/net/http/RestWebSocket.java | 52 +++++++++ src/org/redkale/net/http/WebSocket.java | 2 +- src/org/redkale/net/http/WebSocketId.java | 52 --------- .../redkale/net/http/WebSocketService.java | 103 ------------------ 6 files changed, 124 insertions(+), 156 deletions(-) create mode 100644 src/org/redkale/net/http/RestOnMessage.java create mode 100644 src/org/redkale/net/http/RestOnOpen.java create mode 100644 src/org/redkale/net/http/RestWebSocket.java delete mode 100644 src/org/redkale/net/http/WebSocketId.java delete mode 100644 src/org/redkale/net/http/WebSocketService.java diff --git a/src/org/redkale/net/http/RestOnMessage.java b/src/org/redkale/net/http/RestOnMessage.java new file mode 100644 index 000000000..c664f5068 --- /dev/null +++ b/src/org/redkale/net/http/RestOnMessage.java @@ -0,0 +1,39 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.redkale.net.http; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * 标记在RestWebSocket的接收消息方法上 + * + *

+ * 详情见: https://redkale.org + * + * @author zhangjx + */ +@Inherited +@Documented +@Target({METHOD}) +@Retention(RUNTIME) +public @interface RestOnMessage { + + /** + * 请求的方法名, 不能含特殊字符 + * + * @return String + */ + String name() default ""; + + /** + * 备注描述 + * + * @return String + */ + String comment() default ""; +} diff --git a/src/org/redkale/net/http/RestOnOpen.java b/src/org/redkale/net/http/RestOnOpen.java new file mode 100644 index 000000000..8f97b3970 --- /dev/null +++ b/src/org/redkale/net/http/RestOnOpen.java @@ -0,0 +1,32 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.redkale.net.http; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * 标记在RestWebSocket的方法上 + * + *

+ * 详情见: https://redkale.org + * + * @author zhangjx + */ +@Inherited +@Documented +@Target({METHOD}) +@Retention(RUNTIME) +public @interface RestOnOpen { + + /** + * 备注描述 + * + * @return String + */ + String comment() default ""; +} diff --git a/src/org/redkale/net/http/RestWebSocket.java b/src/org/redkale/net/http/RestWebSocket.java new file mode 100644 index 000000000..1e7d149cc --- /dev/null +++ b/src/org/redkale/net/http/RestWebSocket.java @@ -0,0 +1,52 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.redkale.net.http; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * 只能依附在WebSocket类上,name默认为Service的类名小写并去掉Service字样及后面的字符串 (如HelloWebSocket/HelloWebSocketImpl,的默认路径为 hello)。 + *

+ * 详情见: https://redkale.org + * + * @author zhangjx + */ +@Inherited +@Documented +@Target({TYPE}) +@Retention(RUNTIME) +public @interface RestWebSocket { + + /** + * 模块名, 只能是模块名,不能含特殊字符, 只能小写字母+数字,且不能以数字开头 + * + * @return 模块名 + */ + String name() default ""; + + /** + * 是否屏蔽该类的转换 + * + * @return 默认false + */ + boolean ignore() default false; + + /** + * 同@WebServlet的repair属性 + * + * @return 默认true + */ + boolean repair() default true; + + /** + * 备注描述 + * + * @return 备注描述 + */ + String comment() default ""; +} diff --git a/src/org/redkale/net/http/WebSocket.java b/src/org/redkale/net/http/WebSocket.java index eb85ccee8..6d3be2774 100644 --- a/src/org/redkale/net/http/WebSocket.java +++ b/src/org/redkale/net/http/WebSocket.java @@ -368,7 +368,7 @@ public abstract class WebSocket { * * @return sessionid */ - public CompletableFuture onOpen(final HttpRequest request) { + protected CompletableFuture onOpen(final HttpRequest request) { return CompletableFuture.completedFuture(request.getSessionid(false)); } diff --git a/src/org/redkale/net/http/WebSocketId.java b/src/org/redkale/net/http/WebSocketId.java deleted file mode 100644 index 8d13a89fc..000000000 --- a/src/org/redkale/net/http/WebSocketId.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.redkale.net.http; - -import java.io.Serializable; -import org.redkale.convert.json.JsonConvert; - -/** - * - * @author zhangjx - */ -public class WebSocketId { - - protected long websocketid; - - protected Serializable groupid; - - protected Serializable sessionid; - - protected String remoteAddr; - - public WebSocketId(long websocketid, Serializable groupid, Serializable sessionid, String remoteAddr) { - this.websocketid = websocketid; - this.groupid = groupid; - this.sessionid = sessionid; - this.remoteAddr = remoteAddr; - } - - public long getWebsocketid() { - return websocketid; - } - - public Serializable getGroupid() { - return groupid; - } - - public Serializable getSessionid() { - return sessionid; - } - - public String getRemoteAddr() { - return remoteAddr; - } - - @Override - public String toString() { - return JsonConvert.root().convertTo(this); - } -} diff --git a/src/org/redkale/net/http/WebSocketService.java b/src/org/redkale/net/http/WebSocketService.java deleted file mode 100644 index 802092891..000000000 --- a/src/org/redkale/net/http/WebSocketService.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.redkale.net.http; - -import java.io.Serializable; -import java.lang.annotation.*; -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.util.concurrent.CompletableFuture; - -/** - * 与RestService结合使用 - *

- * 详情见: https://redkale.org - * - * @author zhangjx - */ -public interface WebSocketService { - - public CompletableFuture createGroupid(final WebSocketId wsid); - - default void onConnected(final WebSocketId wsid) { - } - - default void onPing(final WebSocketId wsid, final byte[] bytes) { - } - - default void onPong(final WebSocketId wsid, final byte[] bytes) { - } - - default void onClose(final WebSocketId wsid, final int code, final String reason) { - } - - /** - * 标记在WebSocketService的消息接收方法上 - * - *

- * 详情见: https://redkale.org - * - * @author zhangjx - */ - @Inherited - @Documented - @Target({METHOD}) - @Retention(RUNTIME) - public @interface RestOnMessage { - - /** - * 请求的方法名, 不能含特殊字符 - * - * @return String - */ - String name() default ""; - - /** - * 备注描述 - * - * @return String - */ - String comment() default ""; - } - - /** - * 标记在WebSocketService的方法上 - * - *

- * 详情见: https://redkale.org - * - * @author zhangjx - */ - @Inherited - @Documented - @Target({METHOD}) - @Retention(RUNTIME) - public @interface RestOnOpen { - - /** - * 备注描述 - * - * @return String - */ - String comment() default ""; - } - - /** - * 标记在WebSocketService的RestOnMessage方法的boolean参数上 - * - *

- * 详情见: https://redkale.org - * - * @author zhangjx - */ - @Inherited - @Documented - @Target({PARAMETER}) - @Retention(RUNTIME) - public @interface RestMessageLast { - } - -}