From e80e13c27e6f06c52a3dc8602cd1f02abdfc3180 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Wed, 3 Feb 2016 13:54:12 +0300
Subject: WIP
---
src/main/java/com/juick/JuickApplication.java | 91 ++++++++++++++++++++++
src/main/java/com/juick/JuickNotificator.java | 8 --
src/main/java/com/juick/http/www/Main.java | 83 +++-----------------
src/main/java/com/juick/http/www/NewMessage.java | 47 ++++++-----
src/main/java/com/juick/xmpp/JuickBot.java | 52 +++++++------
.../com/juick/xmpp/s2s/ConnectionListener.java | 8 +-
src/main/java/com/juick/xmpp/s2s/S2SComponent.java | 11 ++-
7 files changed, 171 insertions(+), 129 deletions(-)
create mode 100644 src/main/java/com/juick/JuickApplication.java
delete mode 100644 src/main/java/com/juick/JuickNotificator.java
(limited to 'src/main/java/com')
diff --git a/src/main/java/com/juick/JuickApplication.java b/src/main/java/com/juick/JuickApplication.java
new file mode 100644
index 00000000..c4a62c6f
--- /dev/null
+++ b/src/main/java/com/juick/JuickApplication.java
@@ -0,0 +1,91 @@
+package com.juick;
+
+import com.juick.xmpp.JID;
+import com.juick.xmpp.Stream;
+import com.juick.xmpp.StreamComponent;
+import com.juick.xmpp.s2s.S2SComponent;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.channels.AsynchronousSocketChannel;
+import java.nio.channels.Channels;
+import java.nio.channels.CompletionHandler;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Created by vt on 03/02/16.
+ */
+public class JuickApplication {
+
+ private static final Logger logger = Logger.getLogger(JuickApplication.class.getName());
+
+ private ExecutorService executorService;
+ private Stream router;
+ private JdbcTemplate sql;
+ private JdbcTemplate sqlSearch;
+ private List components = new ArrayList<>();
+
+ public JuickApplication(Properties conf) throws IOException {
+ executorService = Executors.newWorkStealingPool();
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
+ dataSource.setUrl(conf.getProperty("datasource_url"));
+ sql = new JdbcTemplate(dataSource);
+ DriverManagerDataSource searchDatasource = new DriverManagerDataSource();
+ searchDatasource.setDriverClassName("com.mysql.jdbc.Driver");
+ searchDatasource.setUrl("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000");
+ sqlSearch = new JdbcTemplate(searchDatasource);
+ AsynchronousSocketChannel socket = AsynchronousSocketChannel.open();
+ socket.connect(new InetSocketAddress("localhost", 5347), socket,
+ new CompletionHandler() {
+ @Override
+ public void completed(Void result, AsynchronousSocketChannel attachment) {
+ router = new StreamComponent(new JID("", "www.juick.com", ""), Channels.newInputStream(socket),
+ Channels.newOutputStream(socket), conf.getProperty("xmpp_password"));
+ router.startParsing();
+ }
+
+ @Override
+ public void failed(Throwable exc, AsynchronousSocketChannel attachment) {
+ logger.log(Level.SEVERE, "www router failed", exc);
+ }
+ });
+ addComponent(new S2SComponent(this, conf));
+ addComponent(new CrosspostComponent(sql, conf));
+ addComponent(new PushComponent(sql, conf));
+ }
+
+ public Stream getRouter() {
+ return router;
+ }
+
+ public JdbcTemplate getSql() {
+ return sql;
+ }
+
+ public void addComponent(JuickComponent component) {
+ components.add(component);
+ }
+
+ public void push(com.juick.xmpp.Message msg) {
+ for(JuickComponent c : components) {
+ c.messageReceived(msg);
+ }
+ }
+
+ public ExecutorService getExecutorService() {
+ return executorService;
+ }
+
+ public JdbcTemplate getSqlSearch() {
+ return sqlSearch;
+ }
+}
diff --git a/src/main/java/com/juick/JuickNotificator.java b/src/main/java/com/juick/JuickNotificator.java
deleted file mode 100644
index c8fb949f..00000000
--- a/src/main/java/com/juick/JuickNotificator.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.juick;
-
-/**
- * Created by vt on 03/02/16.
- */
-public interface JuickNotificator {
- void push (com.juick.xmpp.Message msg);
-}
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java
index 36376d3c..08b92305 100644
--- a/src/main/java/com/juick/http/www/Main.java
+++ b/src/main/java/com/juick/http/www/Main.java
@@ -17,17 +17,10 @@
*/
package com.juick.http.www;
-import com.juick.CrosspostComponent;
-import com.juick.JuickComponent;
-import com.juick.JuickNotificator;
-import com.juick.PushComponent;
+import com.juick.JuickApplication;
import com.juick.server.UserQueries;
-import com.juick.xmpp.JID;
import com.juick.xmpp.Stream;
-import com.juick.xmpp.StreamComponent;
-import com.juick.xmpp.s2s.S2SComponent;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
import ru.sape.Sape;
import javax.servlet.ServletException;
@@ -37,20 +30,13 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.net.URLEncoder;
-import java.nio.channels.AsynchronousSocketChannel;
-import java.nio.channels.Channels;
-import java.nio.channels.CompletionHandler;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
/**
*
@@ -58,7 +44,7 @@ import java.util.concurrent.Executors;
*/
@WebServlet(name = "Main", urlPatterns = {"/"})
@MultipartConfig(fileSizeThreshold = 1024 * 1024, maxRequestSize = 1024 * 1024 * 10)
-public class Main extends HttpServlet implements JuickNotificator, Stream.StreamListener {
+public class Main extends HttpServlet implements Stream.StreamListener {
static ExecutorService executorService;
JdbcTemplate sql;
JdbcTemplate sqlSearch;
@@ -70,14 +56,14 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
Help help = new Help();
User pagesUser = new User();
UserThread pagesUserThread = new UserThread();
- NewMessage pagesNewMessage = new NewMessage();
+ NewMessage pagesNewMessage;
FacebookLogin loginFacebook = new FacebookLogin();
VKontakteLogin loginVK = new VKontakteLogin();
TwitterAuth twitterAuth;
SignUp signup = new SignUp();
Settings settings = new Settings();
RSS rss = new RSS();
- static List components = new ArrayList<>();
+ JuickApplication app;
@Override
public void init() throws ServletException {
@@ -86,63 +72,18 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
try {
Properties conf = new Properties();
conf.load(getServletContext().getResourceAsStream("WEB-INF/juick.conf"));
-
- executorService = Executors.newWorkStealingPool();
- getServletContext().setAttribute("es", executorService);
-
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
- dataSource.setUrl(conf.getProperty("datasource_url"));
- sql = new JdbcTemplate(dataSource);
- getServletContext().setAttribute("sql", sql);
- DriverManagerDataSource searchDatasource = new DriverManagerDataSource();
- searchDatasource.setDriverClassName("com.mysql.jdbc.Driver");
- searchDatasource.setUrl("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000");
- sqlSearch = new JdbcTemplate(searchDatasource);
- getServletContext().setAttribute("sqlSearch", sqlSearch);
- setupXmppComponent(conf.getProperty("xmpp_password"));
twitterAuth = new TwitterAuth(conf.getProperty("twitter_consumer_key"),
conf.getProperty("twitter_consumer_secret"));
PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600);
- components.add(new S2SComponent(sql, executorService, conf));
- components.add(new CrosspostComponent(sql, conf));
- components.add(new PushComponent(sql, conf));
+ app = new JuickApplication(conf);
+ sql = app.getSql();
+ sqlSearch = app.getSqlSearch();
+ pagesNewMessage = new NewMessage(app);
} catch (Exception e) {
log("www failed", e);
}
}
- @Override
- public void push(com.juick.xmpp.Message msg) {
- for (JuickComponent c : components) {
- c.messageReceived(msg);
- }
- }
-
- public void setupXmppComponent(final String password) {
- executorService.submit(() -> {
- try {
- AsynchronousSocketChannel socket = AsynchronousSocketChannel.open();
- socket.connect(new InetSocketAddress("localhost", 5347), socket, new CompletionHandler() {
- @Override
- public void completed(Void result, AsynchronousSocketChannel attachment) {
- xmpp = new StreamComponent(new JID("", "www.juick.com", ""), Channels.newInputStream(socket),
- Channels.newOutputStream(socket), password);
- xmpp.addListener(Main.this);
- xmpp.startParsing();
- }
-
- @Override
- public void failed(Throwable exc, AsynchronousSocketChannel attachment) {
- log("www xmpp failed");
- }
- });
- } catch (IOException e) {
- log("xmpp exception", e);
- }
- });
- }
-
@Override
public void onStreamFail(Exception e) {log("XMPP STREAM FAIL", e);}
@@ -177,7 +118,7 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
} else if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null) {
- pagesNewMessage.doGetNewMessage(sql, request, response, visitor);
+ pagesNewMessage.doGetNewMessage(request, response, visitor);
} else {
Utils.sendTemporaryRedirect(response, "/login");
}
@@ -312,21 +253,21 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null && !visitor.Banned) {
- pagesNewMessage.doPostMessage(sql, request, response, xmpp, visitor);
+ pagesNewMessage.doPostMessage(request, response, visitor);
} else {
response.sendError(403);
}
} else if (uri.equals("/comment")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null && !visitor.Banned) {
- pagesNewMessage.doPostComment(sql, request, response, xmpp, visitor);
+ pagesNewMessage.doPostComment(request, response, visitor);
} else {
response.sendError(403);
}
} else if (uri.equals("/like")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null && !visitor.Banned) {
- pagesNewMessage.doPostRecomm(sql, request, response, xmpp, visitor);
+ pagesNewMessage.doPostRecomm(request, response, visitor);
} else {
response.sendError(403);
}
diff --git a/src/main/java/com/juick/http/www/NewMessage.java b/src/main/java/com/juick/http/www/NewMessage.java
index b3b63b17..d3178c59 100644
--- a/src/main/java/com/juick/http/www/NewMessage.java
+++ b/src/main/java/com/juick/http/www/NewMessage.java
@@ -17,6 +17,7 @@
*/
package com.juick.http.www;
+import com.juick.JuickApplication;
import com.juick.Tag;
import com.juick.server.CrosspostQueries;
import com.juick.server.MessagesQueries;
@@ -54,10 +55,19 @@ public class NewMessage {
private static final Logger logger = Logger.getLogger(NewMessage.class.getName());
- protected void doGetNewMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ JuickApplication app;
+ JdbcTemplate sql;
+ Stream xmpp;
+
+ public NewMessage(JuickApplication application) {
+ this.app = application;
+ this.sql = application.getSql();
+ this.xmpp = application.getRouter();
+ }
+
+ protected void doGetNewMessage(HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "Написать", ""
+ ""
+ ""
@@ -84,17 +94,15 @@ public class NewMessage {
out.println("");
out.println("");
out.println("Теги:
");
- printUserTags(sql, out, visitor);
+ printUserTags(out, visitor);
out.println("");
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- void printUserTags(JdbcTemplate sql, PrintWriter out, com.juick.User visitor) {
+ void printUserTags(PrintWriter out, com.juick.User visitor) {
List tags = TagQueries.getUserTagsAll(sql, visitor.getUID());
if (tags.isEmpty()) {
@@ -140,7 +148,8 @@ public class NewMessage {
out.println("
");
}
- public void doPostMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostMessage(HttpServletRequest request, HttpServletResponse response,
+ com.juick.User visitor) throws ServletException, IOException {
String body = request.getParameter("body");
if (body == null || body.length() < 1 || body.length() > 4096) {
response.sendError(400);
@@ -222,20 +231,20 @@ public class NewMessage {
xmsg.body = "@" + jmsg.getUser().getUName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid;
xmsg.to = new JID("juick", "s2s.juick.com", null);
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "push.juick.com";
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "crosspost.juick.com";
xmsg.to.Username = "twitter";
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Username = "fb";
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "nologin.ru";
xmsg.to.Username = "jubo";
- Main.push(xmsg);
+ app.push(xmsg);
if (xmpp != null) {
xmsg.to.Host = "ws.juick.com";
xmpp.send(xmsg);
@@ -288,7 +297,8 @@ public class NewMessage {
}
}
- public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostComment(HttpServletRequest request, HttpServletResponse response,
+ com.juick.User visitor) throws ServletException, IOException {
int mid = Utils.parseInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
@@ -379,9 +389,9 @@ public class NewMessage {
xmsg.body = "Reply by @" + jmsg.getUser().getUName() + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew;
xmsg.to = new JID("juick", "s2s.juick.com", null);
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "push.juick.com";
- Main.push(xmsg);
+ app.push(xmsg);
if (xmpp != null) {
xmsg.to.Host = "ws.juick.com";
@@ -393,7 +403,8 @@ public class NewMessage {
Utils.sendTemporaryRedirect(response, "/" + msg.getUser().getUName() + "/" + mid + "#" + ridnew);
}
- public void doPostRecomm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostRecomm(HttpServletRequest request, HttpServletResponse response,
+ com.juick.User visitor) throws ServletException, IOException {
int mid = Utils.parseInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
@@ -418,7 +429,7 @@ public class NewMessage {
jmsg.setMID(mid);
jmsg.setUser(new JuickUser(visitor));
xmsg.addChild(jmsg);
- Main.push(xmsg);
+ app.push(xmsg);
Utils.replyJSON(request, response, "{\"status\":\"ok\"}");
} else {
diff --git a/src/main/java/com/juick/xmpp/JuickBot.java b/src/main/java/com/juick/xmpp/JuickBot.java
index 6104d19d..56260f97 100644
--- a/src/main/java/com/juick/xmpp/JuickBot.java
+++ b/src/main/java/com/juick/xmpp/JuickBot.java
@@ -1,6 +1,6 @@
package com.juick.xmpp;
-import com.juick.JuickNotificator;
+import com.juick.JuickApplication;
import com.juick.User;
import com.juick.server.PMQueries;
import com.juick.server.TagQueries;
@@ -22,12 +22,14 @@ public class JuickBot {
JdbcTemplate sql;
Stream xmpp;
- JuickNotificator notificator;
+ JuickApplication notificator;
+ S2SComponent s2s;
- public JuickBot(JuickNotificator notificator, JdbcTemplate sql, Stream xmpp) {
+ public JuickBot(JuickApplication notificator, S2SComponent s2s) {
this.notificator = notificator;
- this.sql = sql;
- this.xmpp = xmpp;
+ sql = notificator.getSql();
+ xmpp = notificator.getRouter();
+ this.s2s = s2s;
}
public static final JID JuickJID = new JID("juick", "juick.com", "Juick");
@@ -74,7 +76,7 @@ public class JuickBot {
reply.from = new JID(p.to.Username, p.to.Host, null);
reply.to = new JID(p.from.Username, p.from.Host, null);
reply.type = Presence.Type.unsubscribe;
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
return true;
} else if (p.type.equals(Presence.Type.probe)) {
int uid_to = 0;
@@ -88,12 +90,12 @@ public class JuickBot {
reply.from.Resource = "Juick";
reply.to = p.from;
reply.priority = 10;
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
} else {
Presence reply = new Presence(p.to, p.from, Presence.Type.error);
reply.id = p.id;
reply.addChild(new Error(Error.Type.cancel, "item-not-found"));
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
return true;
}
return true;
@@ -111,19 +113,19 @@ public class JuickBot {
if (canSubscribe) {
Presence reply = new Presence(p.to, p.from, Presence.Type.subscribed);
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
reply.from.Resource = "Juick";
reply.priority = 10;
reply.type = null;
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
return true;
} else {
Presence reply = new Presence(p.to, p.from, Presence.Type.error);
reply.id = p.id;
reply.addChild(new Error(Error.Type.cancel, "item-not-found"));
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
return true;
}
} else if (p.type.equals(Presence.Type.unsubscribe)) {
@@ -135,7 +137,7 @@ public class JuickBot {
}
Presence reply = new Presence(p.to, p.from, Presence.Type.unsubscribed);
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
}
return false;
@@ -162,7 +164,7 @@ public class JuickBot {
} else {
reply.body = "Внимание, системное сообщение!\nВаш JabberID не обнаружен в списке доверенных. Для того, чтобы отправить сообщение пользователю " + username + "@juick.com, пожалуйста зарегистрируйте свой JabberID в системе: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nWarning, system message!\nYour JabberID is not found in our server's white list. To send a message to " + username + "@juick.com, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account.";
}
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
return true;
}
@@ -176,7 +178,7 @@ public class JuickBot {
Message reply = new Message(msg.to, msg.from, Message.Type.error);
reply.id = msg.id;
reply.addChild(new Error(Error.Type.cancel, "item-not-found"));
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
return true;
}
@@ -217,14 +219,14 @@ public class JuickBot {
mm.from = new JID("juick", "juick.com", "Juick");
mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + msg.body;
}
- S2SComponent.sendOut(mm);
+ s2s.sendOut(mm);
}
} else {
Message reply = new Message(msg.to, msg.from, Message.Type.error);
reply.id = msg.id;
reply.addChild(new Error(Error.Type.cancel, "not-allowed"));
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
}
return true;
@@ -268,26 +270,26 @@ public class JuickBot {
return false;
}
- private static void commandPing(Message m) {
+ private void commandPing(Message m) {
Presence p = new Presence(JuickJID, m.from);
p.priority = 10;
- S2SComponent.sendOut(p);
+ s2s.sendOut(p);
Message reply = new Message(JuickJID, m.from, Message.Type.chat);
reply.body = "PONG";
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
}
- private static void commandHelp(Message m) {
+ private void commandHelp(Message m) {
Message reply = new Message(JuickJID, m.from, Message.Type.chat);
reply.body = HELPTEXT;
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
}
private void commandLogin(Message m, User user_from) {
Message reply = new Message(JuickJID, m.from, Message.Type.chat);
reply.body = "http://juick.com/login?" + UserQueries.getHashByUID(sql, user_from.getUID());
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
}
private void commandPM(Message m, User user_from, String user_to, String body) {
@@ -346,7 +348,7 @@ public class JuickBot {
mm.from = new JID("juick", "juick.com", "Juick");
mm.body = "Private message from @" + user_from.getUName() + ":\n" + body;
}
- S2SComponent.sendOut(mm);
+ s2s.sendOut(mm);
}
}
@@ -358,7 +360,7 @@ public class JuickBot {
reply.type = Message.Type.error;
reply.body = "Error " + ret;
}
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
}
private void commandBLShow(Message m, User user_from) {
@@ -390,6 +392,6 @@ public class JuickBot {
Message reply = new Message(JuickJID, m.from, Message.Type.chat);
reply.body = txt;
- S2SComponent.sendOut(reply);
+ s2s.sendOut(reply);
}
}
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java
index 28ff48f9..320df347 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java
@@ -1,5 +1,6 @@
package com.juick.xmpp.s2s;
+import com.juick.JuickApplication;
import com.juick.xmpp.JuickBot;
import com.juick.xmpp.Stream;
@@ -23,10 +24,11 @@ public class ConnectionListener implements Runnable {
JuickBot bot;
Stream xmpp;
- public ConnectionListener(ExecutorService executorService, JuickBot bot, Stream xmpp) {
- this.executorService = executorService;
+ public ConnectionListener(JuickApplication app, JuickBot bot) {
+ this.executorService = app.getExecutorService();
+ this.xmpp = app.getRouter();
this.bot = bot;
- this.xmpp = xmpp;
+
}
@Override
diff --git a/src/main/java/com/juick/xmpp/s2s/S2SComponent.java b/src/main/java/com/juick/xmpp/s2s/S2SComponent.java
index dcb547fb..b7155643 100644
--- a/src/main/java/com/juick/xmpp/s2s/S2SComponent.java
+++ b/src/main/java/com/juick/xmpp/s2s/S2SComponent.java
@@ -1,5 +1,6 @@
package com.juick.xmpp.s2s;
+import com.juick.JuickApplication;
import com.juick.JuickComponent;
import com.juick.User;
import com.juick.server.MessagesQueries;
@@ -33,6 +34,7 @@ public class S2SComponent implements JuickComponent {
static final List outConnections = Collections.synchronizedList(new ArrayList<>());
static final List outCache = Collections.synchronizedList(new ArrayList<>());
JdbcTemplate sql;
+ JuickBot bot;
final public static HashMap childParsers = new HashMap<>();
public static void addConnectionIn(ConnectionIn c) {
@@ -147,14 +149,15 @@ public class S2SComponent implements JuickComponent {
}
}
- public S2SComponent(JdbcTemplate sql, ExecutorService executorService, Properties conf) {
+ public S2SComponent(JuickApplication application, Properties conf) {
LOGGER.info("component initialized");
HOSTNAME = conf.getProperty("hostname");
componentName = conf.getProperty("componentname");
STATSFILE = conf.getProperty("statsfile");
- this.sql = sql;
- this.executorService = executorService;
- executorService.submit(new ConnectionListener(executorService));
+ this.sql = application.getSql();
+ this.executorService = application.getExecutorService();
+ this.bot = new JuickBot(application, this);
+ executorService.submit(new ConnectionListener(application, bot));
executorService.submit(new CleaningUp());
}
@Override
--
cgit v1.2.3