diff options
author | 2016-11-12 01:34:07 +0700 | |
---|---|---|
committer | 2016-11-12 11:14:56 +0300 | |
commit | 194a9a763c6b11d207e682b2f93de94475c473b4 (patch) | |
tree | 196317662017b716066eadfa413ecbdc7532c52d /juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java | |
parent | 7d86347a351aa5263c19cd03aa0bda4650c8bfca (diff) |
extracted application configuration from Mvc configuration with application specific beans;
extracted bean initialization from constructor;
force using properties;
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.java | 20 |
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; |