summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorSimon Rettberg2017-03-03 12:08:54 +0100
committerSimon Rettberg2017-03-03 12:08:54 +0100
commitf1a056e7fed96bdaf27c154f47e17efb1eb6a9ab (patch)
tree9fe69322ad39796b312341e0b693f9aed5b3de30 /dozentenmodul/src/main/java
parent[server] Implement getSupportedFeatures() (diff)
downloadtutor-module-f1a056e7fed96bdaf27c154f47e17efb1eb6a9ab.tar.gz
tutor-module-f1a056e7fed96bdaf27c154f47e17efb1eb6a9ab.tar.xz
tutor-module-f1a056e7fed96bdaf27c154f47e17efb1eb6a9ab.zip
[client] Don't update server storage space too often if user is inactive
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java24
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java21
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java70
3 files changed, 83 insertions, 32 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java
index 71c7add8..6eb8a988 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java
@@ -2,6 +2,7 @@ package org.openslx.dozmod.filetransfer;
import java.io.File;
import java.io.FileNotFoundException;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
@@ -34,6 +35,20 @@ public class UploadTask extends TransferTask {
private final int port;
private final String uploadToken;
private String remoteError = null;
+
+ /**
+ * Keep track of the number of active upload connections
+ */
+ private static AtomicInteger numConnections = new AtomicInteger();
+
+ /**
+ * Get the number of active upload workers. This counts individual
+ * upload connections, not logical uploads which might use more than
+ * one connection at a time.
+ */
+ public static int getNumberOfUploads() {
+ return numConnections.get();
+ }
public UploadTask(String host, int port, String uploadToken, File uploadFile)
throws FileNotFoundException {
@@ -53,6 +68,15 @@ public class UploadTask extends TransferTask {
@Override
public void run() {
+ numConnections.incrementAndGet();
+ try {
+ run2();
+ } finally {
+ numConnections.decrementAndGet();
+ }
+ }
+
+ public void run2() {
try {
uploader = new Uploader(host, port, Config.TRANSFER_TIMEOUT, null, uploadToken);
} catch (Exception e) {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
index 2421bad2..f7f99884 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
@@ -1,5 +1,6 @@
package org.openslx.dozmod.gui;
+import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
@@ -11,6 +12,7 @@ import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
+import java.awt.event.AWTEventListener;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicReference;
@@ -29,6 +31,17 @@ import org.openslx.util.QuickTimer;
public class Gui {
private static final Logger LOGGER = Logger.getLogger(Gui.class);
+
+ private static long lastUserActivity = System.currentTimeMillis();
+
+ static {
+ Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
+ @Override
+ public void eventDispatched(AWTEvent event) {
+ lastUserActivity = System.currentTimeMillis();
+ }
+ }, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
+ }
private static Rectangle clientArea(GraphicsDevice gd) {
Insets inset = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration());
@@ -349,5 +362,13 @@ public class Gui {
}
});
}
+
+ /**
+ * Get last user activity timestamp.
+ * This considers mouse clicks and key presses.
+ */
+ public static long getLastUserActivityMillis() {
+ return lastUserActivity;
+ }
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
index 5fbfbd41..68150210 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
@@ -514,6 +514,7 @@ public abstract class MainWindow {
QuickTimer.scheduleAtFixedDelay(new Task() {
private int failures = 0;
private int ignoreCount = 0;
+ private String remoteString = "";
private boolean timeDiffChecked = false;
@Override
@@ -522,47 +523,52 @@ public abstract class MainWindow {
long maxMemory = rt.maxMemory();
long totalMemory = rt.totalMemory();
long usedMemory = totalMemory - rt.freeMemory();
- String txt = "[" + FormatHelper.bytes(usedMemory, false) + "/"
+ String txt = "[JVM: " + FormatHelper.bytes(usedMemory, false) + "/"
+ FormatHelper.bytes(totalMemory, false);
if (maxMemory != Long.MAX_VALUE) {
txt += ", Limit: " + FormatHelper.bytes(maxMemory, false);
}
txt += "]";
- if (Session.getUserId() != null) {
- if (ignoreCount > 0) {
- ignoreCount -= 1;
- } else {
- try {
- SatelliteStatus status = ThriftManager.getSatClient().getStatus();
- failures = 0;
- txt += " [" + FormatHelper.bytes(status.availableStorageBytes, false) + "]";
- if (!timeDiffChecked) {
- final long now = System.currentTimeMillis() / 1000;
- final long diffSecs = Math.abs(now - status.serverTime);
- LOGGER.debug("Clock diff client<->server: " + diffSecs + "s");
- timeDiffChecked = true;
- if (diffSecs > TimeUnit.MINUTES.toMillis(10)) {
- Gui.asyncMessageBox(
- "ACHTUNG: Die Uhrzeit Ihres Computers weicht von der Uhrzeit auf dem Satellitenserver ab.\n"
- + "Bitte stellen Sie sicher, dass die Uhr Ihres Computers richtig gestellt ist.\n"
- + "Falls Ihre Sytemzeit korrekt gesetzt ist, ist möglicherweise die Uhrzeit auf\n"
- + "dem Satellitenserver nicht korrekt eingestellt.\n"
- + "In diesem Fall kann es - je nach Abweichung - zu unerwarteten Problemen mit den\n"
- + "Start- und Endzeiten von Veranstaltungen kommen. Kontaktieren Sie in diesem\n"
- + "Fall den zuständigen Administrator, damit die Uhrzeit auf dem Satellitenserver\n"
- + "korrigiert werden kann.\n\n" + "Ihr Computer: "
- + FormatHelper.longDate(now) + "\nSatelliten-Server: "
- + FormatHelper.longDate(status.serverTime),
- MessageType.WARNING, LOGGER, null);
- }
+ if (ignoreCount > 0) {
+ ignoreCount -= 1;
+ } else if (Session.getUserId() != null) {
+ try {
+ SatelliteStatus status = ThriftManager.getSatClient().getStatus();
+ failures = 0;
+ remoteString = " [Store: " + FormatHelper.bytes(status.availableStorageBytes, false) + "]";
+ if (!timeDiffChecked) {
+ final long now = System.currentTimeMillis() / 1000;
+ final long diffSecs = Math.abs(now - status.serverTime);
+ LOGGER.debug("Clock diff client<->server: " + diffSecs + "s");
+ timeDiffChecked = true;
+ if (diffSecs > TimeUnit.MINUTES.toMillis(10)) {
+ Gui.asyncMessageBox(
+ "ACHTUNG: Die Uhrzeit Ihres Computers weicht von der Uhrzeit auf dem Satellitenserver ab.\n"
+ + "Bitte stellen Sie sicher, dass die Uhr Ihres Computers richtig gestellt ist.\n"
+ + "Falls Ihre Sytemzeit korrekt gesetzt ist, ist möglicherweise die Uhrzeit auf\n"
+ + "dem Satellitenserver nicht korrekt eingestellt.\n"
+ + "In diesem Fall kann es - je nach Abweichung - zu unerwarteten Problemen mit den\n"
+ + "Start- und Endzeiten von Veranstaltungen kommen. Kontaktieren Sie in diesem\n"
+ + "Fall den zuständigen Administrator, damit die Uhrzeit auf dem Satellitenserver\n"
+ + "korrigiert werden kann.\n\n" + "Ihr Computer: "
+ + FormatHelper.longDate(now) + "\nSatelliten-Server: "
+ + FormatHelper.longDate(status.serverTime),
+ MessageType.WARNING, LOGGER, null);
}
- } catch (TException e) {
- failures += 1;
- ignoreCount = Math.min(10, failures / 3);
}
+ // If user is not active and no upload is running, only update the value once a minute
+ // TODO: Count active uploads
+ long inactiveMins = (System.currentTimeMillis() - Gui.getLastUserActivityMillis()) / 60000l;
+ if (inactiveMins > 10 && UploadTask.getNumberOfUploads() == 0) {
+ ignoreCount = 30;
+ }
+ } catch (TException e) {
+ failures += 1;
+ ignoreCount = Math.min(10, failures / 3);
+ remoteString = " [Store: ???]";
}
}
- final String labelText = txt;
+ final String labelText = txt + remoteString;
Gui.asyncExec(new Runnable() {
@Override
public void run() {