This commit is contained in:
Redkale
2017-05-22 19:32:26 +08:00
parent fda9c30dc4
commit d9946ceb64
6 changed files with 124 additions and 156 deletions

View File

@@ -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的接收消息方法上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({METHOD})
@Retention(RUNTIME)
public @interface RestOnMessage {
/**
* 请求的方法名, 不能含特殊字符
*
* @return String
*/
String name() default "";
/**
* 备注描述
*
* @return String
*/
String comment() default "";
}

View File

@@ -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的方法上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({METHOD})
@Retention(RUNTIME)
public @interface RestOnOpen {
/**
* 备注描述
*
* @return String
*/
String comment() default "";
}

View File

@@ -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)。
* <p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({TYPE})
@Retention(RUNTIME)
public @interface RestWebSocket {
/**
* 模块名, 只能是模块名,不能含特殊字符, 只能小写字母+数字,且不能以数字开头
*
* @return 模块名
*/
String name() default "";
/**
* 是否屏蔽该类的转换
*
* @return 默认false
*/
boolean ignore() default false;
/**
* 同&#64;WebServlet的repair属性
*
* @return 默认true
*/
boolean repair() default true;
/**
* 备注描述
*
* @return 备注描述
*/
String comment() default "";
}

View File

@@ -368,7 +368,7 @@ public abstract class WebSocket<G extends Serializable, T> {
*
* @return sessionid
*/
public CompletableFuture<Serializable> onOpen(final HttpRequest request) {
protected CompletableFuture<Serializable> onOpen(final HttpRequest request) {
return CompletableFuture.completedFuture(request.getSessionid(false));
}

View File

@@ -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);
}
}

View File

@@ -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结合使用
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
public interface WebSocketService {
public CompletableFuture<Serializable> 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的消息接收方法上
*
* <br><p>
* 详情见: 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的方法上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({METHOD})
@Retention(RUNTIME)
public @interface RestOnOpen {
/**
* 备注描述
*
* @return String
*/
String comment() default "";
}
/**
* 标记在WebSocketService的RestOnMessage方法的boolean参数上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({PARAMETER})
@Retention(RUNTIME)
public @interface RestMessageLast {
}
}