Log number of IMAP connections

pull/206/head
M66B 3 years ago
parent eaca1deb78
commit 17ac5b7b22

@ -372,6 +372,11 @@ public class IMAPStore extends Store
logger.config("dedicate a store connection"); logger.config("dedicate a store connection");
} }
int getConnections() {
return authenticatedConnections.size() +
(folders == null ? 0 : folders.size()) +
(idleProtocol == null ? 0 : 1);
}
} }
private final ConnectionPool pool; private final ConnectionPool pool;
@ -665,7 +670,7 @@ public class IMAPStore extends Store
synchronized (pool) { synchronized (pool) {
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("host", host); crumb.put("host", host);
crumb.put("connections", Integer.toString(pool.authenticatedConnections.size())); crumb.put("connections", Integer.toString(pool.getConnections()));
crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse)); crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse));
eu.faircode.email.Log.breadcrumb("protocolConnect", crumb); eu.faircode.email.Log.breadcrumb("protocolConnect", crumb);
} }
@ -698,6 +703,7 @@ public class IMAPStore extends Store
synchronized (pool) { synchronized (pool) {
pool.authenticatedConnections.addElement(protocol); pool.authenticatedConnections.addElement(protocol);
eu.faircode.email.Log.persist("protocolConnect " + host + ":" + port + " connections=" + pool.getConnections());
} }
} }
} catch (IMAPReferralException ex) { } catch (IMAPReferralException ex) {
@ -1059,6 +1065,7 @@ public class IMAPStore extends Store
// remove the available connection from the Authenticated queue // remove the available connection from the Authenticated queue
p = pool.authenticatedConnections.lastElement(); p = pool.authenticatedConnections.lastElement();
pool.authenticatedConnections.removeElement(p); pool.authenticatedConnections.removeElement(p);
eu.faircode.email.Log.persist("getProtocol " + host + ":" + port + " connections=" + pool.getConnections());
// check if the connection is still live // check if the connection is still live
long lastUsed = System.currentTimeMillis() - p.getTimestamp(); long lastUsed = System.currentTimeMillis() - p.getTimestamp();
@ -1126,6 +1133,7 @@ public class IMAPStore extends Store
if (pool.folders == null) if (pool.folders == null)
pool.folders = new Vector<>(); pool.folders = new Vector<>();
pool.folders.addElement(folder); pool.folders.addElement(folder);
eu.faircode.email.Log.persist("getProtocol " + host + ":" + port + " connections=" + pool.getConnections());
} }
} }
@ -1159,7 +1167,7 @@ public class IMAPStore extends Store
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("host", host); crumb.put("host", host);
crumb.put("reason", reason); crumb.put("reason", reason);
crumb.put("connections", Integer.toString(pool.authenticatedConnections.size())); crumb.put("connections", Integer.toString(pool.getConnections()));
crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse)); crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse));
eu.faircode.email.Log.breadcrumb("getStoreProtocol", crumb); eu.faircode.email.Log.breadcrumb("getStoreProtocol", crumb);
} }
@ -1194,7 +1202,8 @@ public class IMAPStore extends Store
p.addResponseHandler(this); p.addResponseHandler(this);
pool.authenticatedConnections.addElement(p); pool.authenticatedConnections.addElement(p);
eu.faircode.email.Log.persist(host + ":" + port + " connections=" + pool.getConnections());
} else { } else {
// Always use the first element in the Authenticated queue. // Always use the first element in the Authenticated queue.
if (pool.logger.isLoggable(Level.FINE)) if (pool.logger.isLoggable(Level.FINE))
@ -1338,7 +1347,7 @@ public class IMAPStore extends Store
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("host", host); crumb.put("host", host);
crumb.put("folder", folder.fullName); crumb.put("folder", folder.fullName);
crumb.put("connections", Integer.toString(pool.authenticatedConnections.size())); crumb.put("connections", Integer.toString(pool.getConnections()));
crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse)); crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse));
eu.faircode.email.Log.breadcrumb("releaseProtocol", crumb); eu.faircode.email.Log.breadcrumb("releaseProtocol", crumb);
} }
@ -1350,6 +1359,7 @@ public class IMAPStore extends Store
if (!isConnectionPoolFull()) { if (!isConnectionPoolFull()) {
protocol.addResponseHandler(this); protocol.addResponseHandler(this);
pool.authenticatedConnections.addElement(protocol); pool.authenticatedConnections.addElement(protocol);
eu.faircode.email.Log.persist("releaseProtocol " + host + ":" + port + " connections=" + pool.getConnections());
if (logger.isLoggable(Level.FINE)) if (logger.isLoggable(Level.FINE))
logger.fine( logger.fine(
@ -1364,8 +1374,10 @@ public class IMAPStore extends Store
} }
} }
if (pool.folders != null) if (pool.folders != null) {
pool.folders.removeElement(folder); pool.folders.removeElement(folder);
eu.faircode.email.Log.persist("getProtocol " + host + ":" + port + " connections=" + pool.getConnections());
}
timeoutConnections(); timeoutConnections();
} }
@ -1378,7 +1390,7 @@ public class IMAPStore extends Store
synchronized (pool) { synchronized (pool) {
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("host", host); crumb.put("host", host);
crumb.put("connections", Integer.toString(pool.authenticatedConnections.size())); crumb.put("connections", Integer.toString(pool.getConnections()));
crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse)); crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse));
eu.faircode.email.Log.breadcrumb("releaseStoreProtocol", crumb); eu.faircode.email.Log.breadcrumb("releaseStoreProtocol", crumb);
} }
@ -1428,7 +1440,7 @@ public class IMAPStore extends Store
synchronized (pool) { synchronized (pool) {
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("host", host); crumb.put("host", host);
crumb.put("connections", Integer.toString(pool.authenticatedConnections.size())); crumb.put("connections", Integer.toString(pool.getConnections()));
crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse)); crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse));
eu.faircode.email.Log.breadcrumb("releaseFolderStoreProtocol", crumb); eu.faircode.email.Log.breadcrumb("releaseFolderStoreProtocol", crumb);
} }
@ -1454,7 +1466,7 @@ public class IMAPStore extends Store
synchronized (pool) { synchronized (pool) {
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("host", host); crumb.put("host", host);
crumb.put("connections", Integer.toString(pool.authenticatedConnections.size())); crumb.put("connections", Integer.toString(pool.getConnections()));
crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse)); crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse));
crumb.put("force", Boolean.toString(force)); crumb.put("force", Boolean.toString(force));
eu.faircode.email.Log.breadcrumb("emptyConnectionPool", crumb); eu.faircode.email.Log.breadcrumb("emptyConnectionPool", crumb);
@ -1475,6 +1487,7 @@ public class IMAPStore extends Store
} }
pool.authenticatedConnections.removeAllElements(); pool.authenticatedConnections.removeAllElements();
eu.faircode.email.Log.persist("emptyConnectionPool " + host + ":" + port + " connections=" + pool.getConnections());
} }
pool.logger.fine("removed all authenticated connections from pool"); pool.logger.fine("removed all authenticated connections from pool");
@ -1521,6 +1534,7 @@ public class IMAPStore extends Store
p.removeResponseHandler(this); p.removeResponseHandler(this);
pool.authenticatedConnections.removeElementAt(index); pool.authenticatedConnections.removeElementAt(index);
eu.faircode.email.Log.persist("timeoutConnections " + host + ":" + port + " connections=" + pool.getConnections());
try { try {
p.logout(); p.logout();
@ -1792,7 +1806,7 @@ public class IMAPStore extends Store
synchronized (pool) { synchronized (pool) {
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("host", host); crumb.put("host", host);
crumb.put("connections", Integer.toString(pool.authenticatedConnections.size())); crumb.put("connections", Integer.toString(pool.getConnections()));
crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse)); crumb.put("inuse", Boolean.toString(pool.storeConnectionInUse));
crumb.put("force", Boolean.toString(force)); crumb.put("force", Boolean.toString(force));
eu.faircode.email.Log.breadcrumb("closeAllFolders", crumb); eu.faircode.email.Log.breadcrumb("closeAllFolders", crumb);

Loading…
Cancel
Save