aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/ws/XMPPConnection.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-06-30 11:46:44 +0300
committerGravatar Vitaly Takmazov2016-06-30 11:46:44 +0300
commitdbceb8cb379c44366c1014d282a73457762aabe1 (patch)
treef265954387142c7983928f2db71cc22c715896f3 /src/main/java/com/juick/ws/XMPPConnection.java
parent38040c8f5faaab4fe6d7055ed010533aa1860b07 (diff)
ws injection fix, next
Diffstat (limited to 'src/main/java/com/juick/ws/XMPPConnection.java')
-rw-r--r--src/main/java/com/juick/ws/XMPPConnection.java33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/main/java/com/juick/ws/XMPPConnection.java b/src/main/java/com/juick/ws/XMPPConnection.java
index ae70d956..d5cb4eba 100644
--- a/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/src/main/java/com/juick/ws/XMPPConnection.java
@@ -17,8 +17,6 @@ import javax.inject.Inject;
import java.io.IOException;
import java.net.Socket;
import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -30,21 +28,18 @@ import java.util.stream.Collectors;
@Component
public class XMPPConnection implements Runnable, Stream.StreamListener, Message.MessageListener {
private static final Logger logger = Logger.getLogger(XMPPConnection.class.getName());
-
+ @Inject
JdbcTemplate sql;
Stream xmpp;
String xmppPassword;
MessageSerializer ms;
- WebsocketComponent ws;
- ExecutorService xmppThreadService = Executors.newSingleThreadExecutor();
+ WebsocketComponent wsHandler;
@Inject
- public XMPPConnection(Environment env, WebsocketComponent ws, JdbcTemplate sql) {
- this.sql = sql;
- this.ws = ws;
+ public XMPPConnection(Environment env, WebsocketComponent wsHandler) {
+ this.wsHandler = wsHandler;
xmppPassword = env.getProperty("xmpp_password");
ms = new MessageSerializer();
- xmppThreadService.submit(this);
}
@Override
@@ -97,8 +92,8 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
private void onJuickPM(int uid_to, com.juick.Message jmsg) {
String json = messageSerializer.serialize(jmsg).toString();
- synchronized (ws.clients) {
- ws.clients.stream().filter(c -> !c.legacy && c.visitor.getUID() == uid_to).forEach(c -> {
+ synchronized (wsHandler.clients) {
+ wsHandler.clients.stream().filter(c -> !c.legacy && c.visitor.getUID() == uid_to).forEach(c -> {
try {
logger.info("sending pm to " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));
@@ -114,10 +109,10 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
List<Integer> uids = SubscriptionsQueries.getSubscribedUsers(sql, jmsg.getUser().getUID(), jmsg.getMID())
.stream().map(User::getUID).collect(Collectors.toList());
logger.info(String.format("%d users subscribed to %d", uids.size(), jmsg.getUser().getUID()));
- synchronized (ws.clients) {
- Long legacycount = ws.clients.stream().filter(c -> c.legacy && c.allMessages).count();
+ synchronized (wsHandler.clients) {
+ Long legacycount = wsHandler.clients.stream().filter(c -> c.legacy && c.allMessages).count();
logger.info(String.format("%d legacy users watched %d", legacycount, jmsg.getMID()));
- ws.clients.stream().filter(c -> !c.legacy && uids.contains(c.visitor.getUID())).forEach(c -> {
+ wsHandler.clients.stream().filter(c -> !c.legacy && uids.contains(c.visitor.getUID())).forEach(c -> {
try {
logger.info("sending message to " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));
@@ -125,7 +120,7 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
logger.log(Level.WARNING, "ws error", e);
}
});
- ws.clients.stream().filter(c -> c.legacy && c.allMessages).forEach(c -> {
+ wsHandler.clients.stream().filter(c -> c.legacy && c.allMessages).forEach(c -> {
try {
logger.info("sending message to legacy client " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));
@@ -143,10 +138,10 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
SubscriptionsQueries.getUsersSubscribedToComments(sql, jmsg.getMID(), jmsg.getUser().getUID())
.stream().map(User::getUID).collect(Collectors.toList());
logger.info(String.format("%d users subscribed to %d", threadUsers.size(), jmsg.getMID()));
- synchronized (ws.clients) {
- Long legacycount = ws.clients.stream().filter(c -> c.legacy && c.allReplies).count();
+ synchronized (wsHandler.clients) {
+ Long legacycount = wsHandler.clients.stream().filter(c -> c.legacy && c.allReplies).count();
logger.info(String.format("%d legacy users watched %d", legacycount, jmsg.getMID()));
- ws.clients.stream().filter(c -> !c.legacy && threadUsers.contains(c.visitor.getUID())).forEach(c -> {
+ wsHandler.clients.stream().filter(c -> !c.legacy && threadUsers.contains(c.visitor.getUID())).forEach(c -> {
try {
logger.info("sending reply to " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));
@@ -154,7 +149,7 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
logger.log(Level.WARNING, "ws error", e);
}
});
- ws.clients.stream().filter(c -> (c.legacy && c.allReplies) || (c.legacy && c.MID == jmsg.getMID())).forEach(c -> {
+ wsHandler.clients.stream().filter(c -> (c.legacy && c.allReplies) || (c.legacy && c.MID == jmsg.getMID())).forEach(c -> {
try {
logger.info("sending reply to legacy client " + c.visitor.getUID());
c.session.sendMessage(new TextMessage(json));