aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-06 19:04:41 +0300
committerGravatar Vitaly Takmazov2016-07-06 19:04:41 +0300
commit02fd70cf59c30e3a9702eaf60d9e51f460efd8ca (patch)
treec76d3ec3465437c66c6a63d1afcc921d540edb23 /src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
parentd48e3b71c27d6782a63dda84aced58780b54f309 (diff)
static components are evil
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/XMPPComponent.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/XMPPComponent.java66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
index bb736b5e..2b75fef1 100644
--- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
+++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
@@ -32,45 +32,45 @@ public class XMPPComponent implements ServletContextListener {
private static final Logger LOGGER = Logger.getLogger(XMPPComponent.class.getName());
- public static final ExecutorService executorService = Executors.newCachedThreadPool();
-
- public static String HOSTNAME = null;
- public static String STATSFILE = null;
- public static String keystore;
- public static String keystorePassword;
- public static List<String> brokenSSLhosts;
- public static ConnectionRouter connRouter;
- static final List<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>());
- static final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>());
- static final List<CacheEntry> outCache = Collections.synchronizedList(new ArrayList<>());
- static JdbcTemplate sql;
- final public static HashMap<String, StanzaChild> childParsers = new HashMap<>();
-
- public static void addConnectionIn(ConnectionIn c) {
+ public final ExecutorService executorService = Executors.newCachedThreadPool();
+
+ public String HOSTNAME = null;
+ public String STATSFILE = null;
+ public String keystore;
+ public String keystorePassword;
+ public List<String> brokenSSLhosts;
+ public ConnectionRouter connRouter;
+ final List<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>());
+ final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>());
+ final List<CacheEntry> outCache = Collections.synchronizedList(new ArrayList<>());
+ JdbcTemplate sql;
+ final public HashMap<String, StanzaChild> childParsers = new HashMap<>();
+
+ public void addConnectionIn(ConnectionIn c) {
synchronized (inConnections) {
inConnections.add(c);
}
}
- public static void addConnectionOut(ConnectionOut c) {
+ public void addConnectionOut(ConnectionOut c) {
synchronized (outConnections) {
outConnections.add(c);
}
}
- public static void removeConnectionIn(ConnectionIn c) {
+ public void removeConnectionIn(ConnectionIn c) {
synchronized (inConnections) {
inConnections.remove(c);
}
}
- public static void removeConnectionOut(ConnectionOut c) {
+ public void removeConnectionOut(ConnectionOut c) {
synchronized (outConnections) {
outConnections.remove(c);
}
}
- public static String getFromCache(String hostname) {
+ public String getFromCache(String hostname) {
CacheEntry ret = null;
synchronized (outCache) {
for (Iterator<CacheEntry> i = outCache.iterator(); i.hasNext();) {
@@ -85,7 +85,7 @@ public class XMPPComponent implements ServletContextListener {
return (ret != null) ? ret.xml : null;
}
- public static ConnectionOut getConnectionOut(String hostname, boolean needReady) {
+ public ConnectionOut getConnectionOut(String hostname, boolean needReady) {
synchronized (outConnections) {
for (ConnectionOut c : outConnections) {
if (c.to != null && c.to.equals(hostname) && (!needReady || c.streamReady)) {
@@ -96,7 +96,7 @@ public class XMPPComponent implements ServletContextListener {
return null;
}
- public static ConnectionIn getConnectionIn(String streamID) {
+ public ConnectionIn getConnectionIn(String streamID) {
synchronized (inConnections) {
for (ConnectionIn c : inConnections) {
if (c.streamID != null && c.streamID.equals(streamID)) {
@@ -107,11 +107,11 @@ public class XMPPComponent implements ServletContextListener {
return null;
}
- public static void sendOut(Stanza s) {
+ public void sendOut(Stanza s) {
sendOut(s.to.Host, s.toString());
}
- public static void sendOut(String hostname, String xml) {
+ public void sendOut(String hostname, String xml) {
boolean haveAnyConn = false;
ConnectionOut connOut = null;
@@ -155,8 +155,8 @@ public class XMPPComponent implements ServletContextListener {
if (!haveAnyConn) {
ConnectionOut connectionOut = null;
try {
- connectionOut = new ConnectionOut(hostname);
- XMPPComponent.executorService.submit(connectionOut);
+ connectionOut = new ConnectionOut(this, hostname);
+ executorService.submit(connectionOut);
} catch (CertificateException | UnrecoverableKeyException | NoSuchAlgorithmException | XmlPullParserException | KeyStoreException | KeyManagementException | IOException e) {
LOGGER.log(Level.SEVERE, "s2s out error", e);
}
@@ -185,9 +185,9 @@ public class XMPPComponent implements ServletContextListener {
sql = new JdbcTemplate(dataSource);
childParsers.put(JuickMessage.XMLNS, new JuickMessage());
- executorService.submit(() -> connRouter = new ConnectionRouter(componentName, conf.getProperty("xmpp_password")));
- executorService.submit(new ConnectionListener());
- executorService.submit(new CleaningUp());
+ executorService.submit(() -> connRouter = new ConnectionRouter(this, componentName, conf.getProperty("xmpp_password")));
+ executorService.submit(new ConnectionListener(this));
+ executorService.submit(new CleaningUp(this));
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "XMPPComponent error", e);
}
@@ -198,16 +198,16 @@ public class XMPPComponent implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent sce) {
- synchronized (XMPPComponent.outConnections) {
- for (Iterator<ConnectionOut> i = XMPPComponent.outConnections.iterator(); i.hasNext();) {
+ synchronized (outConnections) {
+ for (Iterator<ConnectionOut> i = outConnections.iterator(); i.hasNext();) {
ConnectionOut c = i.next();
c.closeConnection();
i.remove();
}
}
- synchronized (XMPPComponent.inConnections) {
- for (Iterator<ConnectionIn> i = XMPPComponent.inConnections.iterator(); i.hasNext();) {
+ synchronized (inConnections) {
+ for (Iterator<ConnectionIn> i = inConnections.iterator(); i.hasNext();) {
ConnectionIn c = i.next();
c.closeConnection();
i.remove();
@@ -215,7 +215,7 @@ public class XMPPComponent implements ServletContextListener {
}
try {
- XMPPComponent.connRouter.closeConnection();
+ connRouter.closeConnection();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "router warning", e);
}