aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
index 2ab3a94c..4ce230a4 100644
--- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
+++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
@@ -9,6 +9,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
@@ -24,13 +25,17 @@ import java.util.List;
* Created by vitalyster on 28.06.2016.
*/
public class WebsocketComponent extends TextWebSocketHandler {
+ private static final Logger logger = LoggerFactory.getLogger(WebsocketComponent.class);
- @Inject
- JdbcTemplate jdbc;
+ private JdbcTemplate jdbc;
- private static final Logger logger = LoggerFactory.getLogger(WebsocketComponent.class);
+ private final List<SocketSubscribed> clients = Collections.synchronizedList(new ArrayList<SocketSubscribed>());
- final List<SocketSubscribed> clients = Collections.synchronizedList(new ArrayList<SocketSubscribed>());
+
+ public WebsocketComponent(JdbcTemplate jdbc) {
+ Assert.notNull(jdbc);
+ this.jdbc = jdbc;
+ }
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
@@ -102,6 +107,7 @@ public class WebsocketComponent extends TextWebSocketHandler {
}
}
}
+
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
synchronized (clients) {
@@ -116,8 +122,12 @@ public class WebsocketComponent extends TextWebSocketHandler {
}
}
- class SocketSubscribed {
+ public List<SocketSubscribed> getClients() {
+ return clients;
+ }
+
+ class SocketSubscribed {
WebSocketSession session;
String clientName;
User visitor;