This commit is contained in:
Redkale
2017-05-22 17:13:16 +08:00
parent f5379df63b
commit 205162ce38
2 changed files with 87 additions and 140 deletions

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.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

@@ -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<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的消息接收方法上
*
@@ -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的方法上 <br>
* 方法的返回值必须是CompletableFuture&lt;Serializable&gt;, 且方法没有参数
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({METHOD})
@Retention(RUNTIME)
public @interface RestCreateGroup {
String comment() default ""; //备注描述
}
/**
* 标记在WebSocketService的方法上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({METHOD})
@Retention(RUNTIME)
public @interface RestOnConnected {
String comment() default ""; //备注描述
}
/**
* 标记在WebSocketService的方法上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({METHOD})
@Retention(RUNTIME)
public @interface RestOnClose {
String comment() default ""; //备注描述
}
/**
* 标记在WebSocketService的方法上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({METHOD})
@Retention(RUNTIME)
public @interface RestOnPing {
String comment() default ""; //备注描述
}
/**
* 标记在WebSocketService的方法上
*
* <br><p>
* 详情见: 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参数上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({PARAMETER})
@Retention(RUNTIME)
public @interface RestClientAddress {
String comment() default ""; //备注描述
}
/**
* 标记在WebSocketService的RestOnMessage方法的Serializable参数上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({PARAMETER})
@Retention(RUNTIME)
public @interface RestGroupid {
String comment() default ""; //备注描述
}
/**
* 标记在WebSocketService的方法的Serializable参数上
*
* <br><p>
* 详情见: https://redkale.org
*
* @author zhangjx
*/
@Inherited
@Documented
@Target({PARAMETER})
@Retention(RUNTIME)
public @interface RestSessionid {
String comment() default ""; //备注描述
}
}