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/JuickBot.java | |
parent | 210690e7aefbd4d82e269277d621b5e6efc5c909 (diff) |
JdbcTemplate is thread-safe
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/JuickBot.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/JuickBot.java | 182 |
1 files changed, 79 insertions, 103 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/JuickBot.java b/src/main/java/com/juick/xmpp/s2s/JuickBot.java index 1172d75f..357b070f 100644 --- a/src/main/java/com/juick/xmpp/s2s/JuickBot.java +++ b/src/main/java/com/juick/xmpp/s2s/JuickBot.java @@ -69,9 +69,7 @@ public class JuickBot { } else if (p.type.equals(Presence.Type.probe)) { int uid_to = 0; if (!toJuick) { - synchronized (XMPPComponent.sqlSync) { - uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); - } + uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); } if (toJuick || uid_to > 0) { @@ -94,12 +92,10 @@ public class JuickBot { if (toJuick) { canSubscribe = true; } else { - synchronized (XMPPComponent.sqlSync) { - int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); - if (uid_to > 0) { - PMQueries.addPMinRoster(XMPPComponent.sql, uid_to, p.from.Bare()); - canSubscribe = true; - } + int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); + if (uid_to > 0) { + PMQueries.addPMinRoster(XMPPComponent.sql, uid_to, p.from.Bare()); + canSubscribe = true; } } @@ -122,11 +118,9 @@ public class JuickBot { } } else if (p.type.equals(Presence.Type.unsubscribe)) { if (!toJuick) { - synchronized (XMPPComponent.sqlSync) { - int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); - if (uid_to > 0) { - PMQueries.removePMinRoster(XMPPComponent.sql, uid_to, p.from.Bare()); - } + int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); + if (uid_to > 0) { + PMQueries.removePMinRoster(XMPPComponent.sql, uid_to, p.from.Bare()); } } @@ -146,11 +140,9 @@ public class JuickBot { User user_from = null; String signuphash = ""; - synchronized (XMPPComponent.sqlSync) { - user_from = UserQueries.getUserByJID(XMPPComponent.sql, msg.from.Bare()); - if (user_from == null) { - signuphash = UserQueries.getSignUpHashByJID(XMPPComponent.sql, msg.from.Bare()); - } + user_from = UserQueries.getUserByJID(XMPPComponent.sql, msg.from.Bare()); + if (user_from == null) { + signuphash = UserQueries.getSignUpHashByJID(XMPPComponent.sql, msg.from.Bare()); } if (user_from == null) { @@ -168,10 +160,7 @@ public class JuickBot { return incomingMessageJuick(user_from, msg); } - int uid_to = 0; - synchronized (XMPPComponent.sqlSync) { - uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); - } + int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username); if (uid_to == 0) { Message reply = new Message(msg.to, msg.from, Message.Type.error); @@ -182,10 +171,8 @@ public class JuickBot { } boolean success = false; - synchronized (XMPPComponent.sqlSync) { - if (!UserQueries.isInBLAny(XMPPComponent.sql, uid_to, user_from.getUID())) { - success = PMQueries.createPM(XMPPComponent.sql, user_from.getUID(), uid_to, msg.body); - } + if (!UserQueries.isInBLAny(XMPPComponent.sql, uid_to, user_from.getUID())) { + success = PMQueries.createPM(XMPPComponent.sql, user_from.getUID(), uid_to, msg.body); } if (success) { @@ -193,9 +180,7 @@ public class JuickBot { m.from = new JID("juick", "juick.com", null); m.to = new JID(Integer.toString(uid_to), "push.juick.com", null); JuickMessage jmsg = new JuickMessage(); - synchronized (XMPPComponent.sqlSync) { - jmsg.setUser(user_from); - } + jmsg.setUser(user_from); jmsg.setText(msg.body); m.childs.add(jmsg); XMPPComponent.connRouter.router.send(m.toString()); @@ -205,22 +190,20 @@ public class JuickBot { List<String> jids; boolean inroster = false; - synchronized (XMPPComponent.sqlSync) { - jids = UserQueries.getJIDsbyUID(XMPPComponent.sql, uid_to); - for (String jid : jids) { - Message mm = new Message(); - mm.to = new JID(jid); - mm.type = Message.Type.chat; - inroster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid); - if (inroster) { - mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick"); - mm.body = msg.body; - } else { - mm.from = new JID("juick", "juick.com", "Juick"); - mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + msg.body; - } - XMPPComponent.sendOut(mm); + jids = UserQueries.getJIDsbyUID(XMPPComponent.sql, uid_to); + for (String jid : jids) { + Message mm = new Message(); + mm.to = new JID(jid); + mm.type = Message.Type.chat; + inroster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid); + if (inroster) { + mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick"); + mm.body = msg.body; + } else { + mm.from = new JID("juick", "juick.com", "Juick"); + mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + msg.body; } + XMPPComponent.sendOut(mm); } } else { Message reply = new Message(msg.to, msg.from, Message.Type.error); @@ -299,77 +282,70 @@ public class JuickBot { List<String> jids_to = null; boolean haveInRoster = false; - synchronized (XMPPComponent.sqlSync) { - if (user_to.indexOf('@') > 0) { - uid_to = UserQueries.getUIDbyJID(XMPPComponent.sql, user_to); - } else { - uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, user_to); - } + if (user_to.indexOf('@') > 0) { + uid_to = UserQueries.getUIDbyJID(XMPPComponent.sql, user_to); + } else { + uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, user_to); + } - if (uid_to > 0) { - if (!UserQueries.isInBLAny(XMPPComponent.sql, uid_to, user_from.getUID())) { - if (PMQueries.createPM(XMPPComponent.sql, user_from.getUID(), uid_to, body)) { - jids_to = UserQueries.getJIDsbyUID(XMPPComponent.sql, uid_to); - ret = 200; - } else { - ret = 500; - } + if (uid_to > 0) { + if (!UserQueries.isInBLAny(XMPPComponent.sql, uid_to, user_from.getUID())) { + if (PMQueries.createPM(XMPPComponent.sql, user_from.getUID(), uid_to, body)) { + jids_to = UserQueries.getJIDsbyUID(XMPPComponent.sql, uid_to); + ret = 200; } else { - ret = 403; + ret = 500; } } else { - ret = 404; + ret = 403; } + } else { + ret = 404; + } - if (ret == 200) { - Message msg = new Message(); - msg.from = new JID("juick", "juick.com", null); - msg.to = new JID(Integer.toString(uid_to), "push.juick.com", null); - JuickMessage jmsg = new JuickMessage(); - jmsg.setUser(user_from); - jmsg.setText(body); - msg.childs.add(jmsg); - XMPPComponent.connRouter.router.send(msg.toString()); - - msg.to.Host = "ws.juick.com"; - XMPPComponent.connRouter.router.send(msg.toString()); - - for (String jid : jids_to) { - Message mm = new Message(); - mm.to = new JID(jid); - mm.type = Message.Type.chat; - haveInRoster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid); - if (haveInRoster) { - mm.from = new JID(user_from.getUName(), "juick.com", "Juick"); - mm.body = body; - } else { - mm.from = new JID("juick", "juick.com", "Juick"); - mm.body = "Private message from @" + user_from.getUName() + ":\n" + body; - } - XMPPComponent.sendOut(mm); + if (ret == 200) { + Message msg = new Message(); + msg.from = new JID("juick", "juick.com", null); + msg.to = new JID(Integer.toString(uid_to), "push.juick.com", null); + JuickMessage jmsg = new JuickMessage(); + jmsg.setUser(user_from); + jmsg.setText(body); + msg.childs.add(jmsg); + XMPPComponent.connRouter.router.send(msg.toString()); + + msg.to.Host = "ws.juick.com"; + XMPPComponent.connRouter.router.send(msg.toString()); + + for (String jid : jids_to) { + Message mm = new Message(); + mm.to = new JID(jid); + mm.type = Message.Type.chat; + haveInRoster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid); + if (haveInRoster) { + mm.from = new JID(user_from.getUName(), "juick.com", "Juick"); + mm.body = body; + } else { + mm.from = new JID("juick", "juick.com", "Juick"); + mm.body = "Private message from @" + user_from.getUName() + ":\n" + body; } + XMPPComponent.sendOut(mm); } + } - Message reply = new Message(m.to, m.from); - if (ret == 200) { - reply.type = m.type; - reply.body = "Private message sent"; - } else { - reply.type = Message.Type.error; - reply.body = "Error " + ret; - } - XMPPComponent.sendOut(reply); + Message reply = new Message(m.to, m.from); + if (ret == 200) { + reply.type = m.type; + reply.body = "Private message sent"; + } else { + reply.type = Message.Type.error; + reply.body = "Error " + ret; } + XMPPComponent.sendOut(reply); } private static void commandBLShow(Message m, User user_from) throws Exception { - List<User> blusers; - List<String> bltags; - - synchronized (XMPPComponent.sqlSync) { - blusers = UserQueries.getUserBLUsers(XMPPComponent.sql, user_from.getUID()); - bltags = TagQueries.getUserBLTags(XMPPComponent.sql, user_from.getUID()); - } + List<User> blusers = UserQueries.getUserBLUsers(XMPPComponent.sql, user_from.getUID()); + List<String> bltags = TagQueries.getUserBLTags(XMPPComponent.sql, user_from.getUID()); String txt = ""; if (bltags.size() > 0) { |