RestWebSocket增加anyuser功能
This commit is contained in:
@@ -328,6 +328,10 @@ public final class Rest {
|
|||||||
mv.visitInsn(rws.single() ? ICONST_1 : ICONST_0);
|
mv.visitInsn(rws.single() ? ICONST_1 : ICONST_0);
|
||||||
mv.visitFieldInsn(PUTFIELD, newDynName, "single", "Z");
|
mv.visitFieldInsn(PUTFIELD, newDynName, "single", "Z");
|
||||||
|
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(rws.anyuser() ? ICONST_1 : ICONST_0);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, newDynName, "anyuser", "Z");
|
||||||
|
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
mv.visitMaxs(3, 1);
|
mv.visitMaxs(3, 1);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ public @interface RestWebSocket {
|
|||||||
*/
|
*/
|
||||||
boolean single() default true;
|
boolean single() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket.createUserid返回的值是否不能表示户登录态
|
||||||
|
*
|
||||||
|
* @return 默认false
|
||||||
|
*/
|
||||||
|
boolean anyuser() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebScoket服务器给客户端进行ping操作的间隔时间, 单位: 秒, 默认值:15秒
|
* WebScoket服务器给客户端进行ping操作的间隔时间, 单位: 秒, 默认值:15秒
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -62,14 +62,21 @@ public abstract class WebSocketServlet extends HttpServlet implements Resourcabl
|
|||||||
|
|
||||||
protected Type messageTextType; //RestWebSocket时会被修改
|
protected Type messageTextType; //RestWebSocket时会被修改
|
||||||
|
|
||||||
|
//同RestWebSocket.single
|
||||||
protected boolean single = true; //是否单用户单连接
|
protected boolean single = true; //是否单用户单连接
|
||||||
|
|
||||||
|
//同RestWebSocket.liveinterval
|
||||||
protected int liveinterval = DEFAILT_LIVEINTERVAL;
|
protected int liveinterval = DEFAILT_LIVEINTERVAL;
|
||||||
|
|
||||||
|
//同RestWebSocket.wsmaxconns
|
||||||
protected int wsmaxconns = 0;
|
protected int wsmaxconns = 0;
|
||||||
|
|
||||||
|
//同RestWebSocket.wsmaxbody
|
||||||
protected int wsmaxbody = 16 * 1024;
|
protected int wsmaxbody = 16 * 1024;
|
||||||
|
|
||||||
|
//同RestWebSocket.anyuser
|
||||||
|
protected boolean anyuser = false;
|
||||||
|
|
||||||
@Resource(name = "jsonconvert")
|
@Resource(name = "jsonconvert")
|
||||||
protected Convert jsonConvert;
|
protected Convert jsonConvert;
|
||||||
|
|
||||||
@@ -203,7 +210,7 @@ public abstract class WebSocketServlet extends HttpServlet implements Resourcabl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
webSocket._userid = userid;
|
webSocket._userid = userid;
|
||||||
if (single) {
|
if (single && !anyuser) {
|
||||||
WebSocketServlet.this.node.existsWebSocket(userid).whenComplete((rs, ex) -> {
|
WebSocketServlet.this.node.existsWebSocket(userid).whenComplete((rs, ex) -> {
|
||||||
if (rs) webSocket.onSingleRepeatConnect();
|
if (rs) webSocket.onSingleRepeatConnect();
|
||||||
WebSocketServlet.this.node.localEngine.add(webSocket);
|
WebSocketServlet.this.node.localEngine.add(webSocket);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import org.redkale.net.http.*;
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@RestWebSocket(name = "chat", catalog = "ws", comment = "文字聊天")
|
@RestWebSocket(name = "chat", catalog = "ws", comment = "文字聊天", anyuser = true)
|
||||||
public class ChatWebSocket extends WebSocket<Integer, Object> {
|
public class ChatWebSocket extends WebSocket<Integer, Object> {
|
||||||
|
|
||||||
protected static final AtomicInteger idcreator = new AtomicInteger(10000);
|
protected static final AtomicInteger idcreator = new AtomicInteger(10000);
|
||||||
|
|||||||
Reference in New Issue
Block a user