From 205162ce382602738afbb80200c10ec358e27e06 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Mon, 22 May 2017 17:13:16 +0800 Subject: [PATCH] --- src/org/redkale/net/http/WebSocketId.java | 52 ++++++ .../redkale/net/http/WebSocketService.java | 175 ++++-------------- 2 files changed, 87 insertions(+), 140 deletions(-) create mode 100644 src/org/redkale/net/http/WebSocketId.java diff --git a/src/org/redkale/net/http/WebSocketId.java b/src/org/redkale/net/http/WebSocketId.java new file mode 100644 index 000000000..8d13a89fc --- /dev/null +++ b/src/org/redkale/net/http/WebSocketId.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.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 index c66b59a4f..802092891 100644 --- a/src/org/redkale/net/http/WebSocketService.java +++ b/src/org/redkale/net/http/WebSocketService.java @@ -5,9 +5,11 @@ */ 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结合使用 @@ -18,6 +20,20 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; */ 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的消息接收方法上 * @@ -32,7 +48,19 @@ public interface WebSocketService { @Retention(RUNTIME) public @interface RestOnMessage { - String comment() default ""; //备注描述 + /** + * 请求的方法名, 不能含特殊字符 + * + * @return String + */ + String name() default ""; + + /** + * 备注描述 + * + * @return String + */ + String comment() default ""; } /** @@ -49,93 +77,12 @@ public interface WebSocketService { @Retention(RUNTIME) public @interface RestOnOpen { - String comment() default ""; //备注描述 - } - - /** - * 标记在WebSocketService的方法上
- * 方法的返回值必须是CompletableFuture<Serializable>, 且方法没有参数 - * - *

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

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

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

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

- * 详情见: https://redkale.org - * - * @author zhangjx - */ - @Inherited - @Documented - @Target({METHOD}) - @Retention(RUNTIME) - public @interface RestOnPong { - - String comment() default ""; //备注描述 + /** + * 备注描述 + * + * @return String + */ + String comment() default ""; } /** @@ -151,58 +98,6 @@ public interface WebSocketService { @Target({PARAMETER}) @Retention(RUNTIME) public @interface RestMessageLast { - - String comment() default ""; //备注描述 } - /** - * 标记在WebSocketService的方法的String参数上 - * - *

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

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

- * 详情见: https://redkale.org - * - * @author zhangjx - */ - @Inherited - @Documented - @Target({PARAMETER}) - @Retention(RUNTIME) - public @interface RestSessionid { - - String comment() default ""; //备注描述 - } }