DaanHoogland commented on code in PR #13058:
URL: https://github.com/apache/cloudstack/pull/13058#discussion_r3765780945
##########
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java:
##########
@@ -16,98 +16,119 @@
// under the License.
package com.cloud.consoleproxy;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
+
/**
*
* ConsoleProxyGCThread does house-keeping work for the process, it helps
cleanup log files,
* recycle idle client sessions without front-end activities and report client
stats to external
* management software
*/
public class ConsoleProxyGCThread extends Thread {
- protected Logger logger = LogManager.getLogger(ConsoleProxyGCThread.class);
+ private static final Logger logger =
LogManager.getLogger(ConsoleProxyGCThread.class);
- private final static int MAX_SESSION_IDLE_SECONDS = 180;
private final Map<String, ConsoleProxyClient> connMap;
private final Set<String> removedSessionsSet;
private long lastLogScan = 0;
+
public ConsoleProxyGCThread(Map<String, ConsoleProxyClient> connMap,
Set<String> removedSet) {
this.connMap = connMap;
this.removedSessionsSet = removedSet;
}
+
private void cleanupLogging() {
- if (lastLogScan != 0 && System.currentTimeMillis() - lastLogScan <
3600000)
+ if (lastLogScan != 0 && System.currentTimeMillis() - lastLogScan <
3600000) {
return;
+ }
+
lastLogScan = System.currentTimeMillis();
+
File logDir = new File("./logs");
- File files[] = logDir.listFiles();
+ File[] files = logDir.listFiles();
if (files != null) {
for (File file : files) {
if (System.currentTimeMillis() - file.lastModified() >=
86400000L) {
try {
file.delete();
} catch (Throwable e) {
- logger.info("[ignored]"
- + "failed to delete file: " +
e.getLocalizedMessage());
+ logger.info("[ignored] failed to delete file: " +
e.getLocalizedMessage());
}
}
}
}
}
+
@Override
public void run() {
+
boolean bReportLoad = false;
long lastReportTick = System.currentTimeMillis();
+
while (true) {
cleanupLogging();
bReportLoad = false;
+
if (logger.isDebugEnabled()) {
- logger.debug(String.format("connMap=%s, removedSessions=%s",
connMap, removedSessionsSet));
+ logger.debug(String.format("ConsoleProxyGCThread loop:
connMap=%s, removedSessions=%s", connMap, removedSessionsSet));
}
- Set<String> e = connMap.keySet();
- Iterator<String> iterator = e.iterator();
+ Set<String> keys = connMap.keySet();
+ Iterator<String> iterator = keys.iterator();
while (iterator.hasNext()) {
Review Comment:
```suggestion
List<String> keys;
synchronized (connMap) {
keys = new ArrayList<>(connMap.keySet());
}
for (String key : keys) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]