diff options
author | Vitaly Takmazov | 2016-07-06 18:48:28 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-07-06 18:48:28 +0300 |
commit | d48e3b71c27d6782a63dda84aced58780b54f309 (patch) | |
tree | 0139968c6c7f297a8e7ff9123df3490519c3367e /src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java | |
parent | 210690e7aefbd4d82e269277d621b5e6efc5c909 (diff) |
JdbcTemplate is thread-safe
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java b/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java index 95878edd..0030834a 100644 --- a/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java +++ b/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java @@ -55,15 +55,13 @@ public class ConnectionRouter implements Stream.StreamListener, public void sendJuickMessage(JuickMessage jmsg) { List<String> jids = new ArrayList<>(); - synchronized (XMPPComponent.sqlSync) { - if (jmsg.FriendsOnly) { - jids = SubscriptionsQueries.getJIDSubscribedToUser(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.FriendsOnly); - } else { - List<User> users = SubscriptionsQueries.getSubscribedUsers(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.getMID()); - for (User user : users) { - for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { - jids.add(jid); - } + if (jmsg.FriendsOnly) { + jids = SubscriptionsQueries.getJIDSubscribedToUser(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.FriendsOnly); + } else { + List<User> users = SubscriptionsQueries.getSubscribedUsers(XMPPComponent.sql, jmsg.getUser().getUID(), jmsg.getMID()); + for (User user : users) { + for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { + jids.add(jid); } } } @@ -103,13 +101,11 @@ public class ConnectionRouter implements Stream.StreamListener, String replyQuote; String replyTo; - synchronized (XMPPComponent.sqlSync) { - users = SubscriptionsQueries.getUsersSubscribedToComments(XMPPComponent.sql, jmsg.getMID(), jmsg.getUser().getUID()); - com.juick.Message replyMessage = jmsg.ReplyTo > 0 ? MessagesQueries.getReply(XMPPComponent.sql, jmsg.getMID(), jmsg.ReplyTo) - : MessagesQueries.getMessage(XMPPComponent.sql, jmsg.getMID()); - replyTo = replyMessage.getUser().getUName(); - replyQuote = getReplyQuote(replyMessage); - } + users = SubscriptionsQueries.getUsersSubscribedToComments(XMPPComponent.sql, jmsg.getMID(), jmsg.getUser().getUID()); + com.juick.Message replyMessage = jmsg.ReplyTo > 0 ? MessagesQueries.getReply(XMPPComponent.sql, jmsg.getMID(), jmsg.ReplyTo) + : MessagesQueries.getMessage(XMPPComponent.sql, jmsg.getMID()); + replyTo = replyMessage.getUser().getUName(); + replyQuote = getReplyQuote(replyMessage); String txt = "Reply by @" + jmsg.getUser().getUName() + ":\n" + replyQuote + "\n@" + replyTo + " "; String attachment = jmsg.getAttachmentURL(); @@ -124,11 +120,9 @@ public class ConnectionRouter implements Stream.StreamListener, msg.type = Message.Type.chat; msg.addChild(jmsg); for (User user : users) { - synchronized (XMPPComponent.sqlSync) { - for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { - msg.to = new JID(jid); - XMPPComponent.sendOut(msg); - } + for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { + msg.to = new JID(jid); + XMPPComponent.sendOut(msg); } } } @@ -146,11 +140,9 @@ public class ConnectionRouter implements Stream.StreamListener, public void sendJuickRecommendation(JuickMessage recomm) { List<User> users; JuickMessage jmsg; - synchronized (XMPPComponent.sqlSync) { - jmsg = new JuickMessage(MessagesQueries.getMessage(XMPPComponent.sql, recomm.getMID())); - users = SubscriptionsQueries.getUsersSubscribedToUserRecommendations(XMPPComponent.sql, - recomm.getUser().getUID(), recomm.getMID(), jmsg.getUser().getUID()); - } + jmsg = new JuickMessage(MessagesQueries.getMessage(XMPPComponent.sql, recomm.getMID())); + users = SubscriptionsQueries.getUsersSubscribedToUserRecommendations(XMPPComponent.sql, + recomm.getUser().getUID(), recomm.getMID(), jmsg.getUser().getUID()); String txt = "Recommended by @" + recomm.getUser().getUName() + ":\n"; txt += "@" + jmsg.getUser().getUName() + ":" + jmsg.getTagsString() + "\n"; @@ -186,11 +178,9 @@ public class ConnectionRouter implements Stream.StreamListener, } for (User user : users) { - synchronized (XMPPComponent.sqlSync) { - for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { - msg.to = new JID(jid); - XMPPComponent.sendOut(msg); - } + for (String jid : UserQueries.getJIDsbyUID(XMPPComponent.sql, user.getUID())) { + msg.to = new JID(jid); + XMPPComponent.sendOut(msg); } } } |