This commit is contained in:
@@ -1,28 +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 com.wentch.redkale.test.service;
|
||||
|
||||
import com.wentch.redkale.service.Service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class IMService implements Service {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + this.getClass().getSimpleName() + "]";
|
||||
}
|
||||
|
||||
public void send(String text) {
|
||||
onSend(text);
|
||||
}
|
||||
|
||||
public void onSend(String text) {
|
||||
System.out.println("接收到消息: " + text);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +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 com.wentch.redkale.test.service;
|
||||
|
||||
import com.wentch.redkale.net.http.WebSocketServlet;
|
||||
import com.wentch.redkale.net.http.WebSocket;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class IMServlet extends WebSocketServlet {
|
||||
|
||||
@Resource(name = "^IMNODE.+$")
|
||||
private Map<String, IMService> nodemaps;
|
||||
|
||||
@Override
|
||||
protected WebSocket createWebSocket() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
42
test/com/wentch/redkale/test/sncp/SncpTestBean.java
Normal file
42
test/com/wentch/redkale/test/sncp/SncpTestBean.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.sncp;
|
||||
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.source.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class SncpTestBean implements FilterBean {
|
||||
|
||||
private long id;
|
||||
|
||||
private String content;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
}
|
||||
26
test/com/wentch/redkale/test/sncp/SncpTestService.java
Normal file
26
test/com/wentch/redkale/test/sncp/SncpTestService.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.sncp;
|
||||
|
||||
import com.wentch.redkale.service.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class SncpTestService implements Service {
|
||||
|
||||
public String queryResult(SncpTestBean bean) {
|
||||
System.out.println(Thread.currentThread().getName() + " 运行了queryResult方法");
|
||||
return "result: " + bean;
|
||||
}
|
||||
|
||||
@MultiRun
|
||||
public String updateBean(SncpTestBean bean) {
|
||||
System.out.println(Thread.currentThread().getName() + " 运行了updateBean方法");
|
||||
return "result: " + bean;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package com.wentch.redkale.test.websocket;
|
||||
import com.wentch.redkale.net.http.WebServlet;
|
||||
import com.wentch.redkale.net.http.WebSocketServlet;
|
||||
import com.wentch.redkale.net.http.WebSocket;
|
||||
import java.io.*;
|
||||
import static java.lang.Thread.sleep;
|
||||
import java.text.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
@@ -16,7 +17,7 @@ import java.util.concurrent.atomic.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@WebServlet("/chat")
|
||||
@WebServlet("/ws/chat")
|
||||
public class ChatWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
private final AtomicLong counter = new AtomicLong();
|
||||
@@ -62,7 +63,17 @@ public class ChatWebSocketServlet extends WebSocketServlet {
|
||||
if (debug) System.out.println("收到消息: " + text);
|
||||
super.getWebSocketGroup().getWebSockets().forEach(x -> x.send(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable createGroupid() {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "chat";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,13 +20,18 @@ import java.util.concurrent.CountDownLatch;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@WebServlet({"/listen/*"})
|
||||
@WebServlet({"/ws/listen"})
|
||||
public class VideoWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
private final Map<Serializable, Entry> sessions = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
|
||||
private final Map<Serializable, String> users = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "listen";
|
||||
}
|
||||
|
||||
private static final class Entry {
|
||||
|
||||
public WebSocket socket;
|
||||
@@ -102,6 +107,11 @@ public class VideoWebSocketServlet extends WebSocketServlet {
|
||||
x.send(msg);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable createGroupid() {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
return socket;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user