summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache
diff options
context:
space:
mode:
authorJonathan Bauer2016-04-27 17:24:15 +0200
committerJonathan Bauer2016-04-27 17:24:15 +0200
commita40ddb0a580348d68ff0c515275ffa252b686c1e (patch)
treee2436a05c935fd7b6c408e4cafb5be5dce6e16ce /dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache
parent[server] Fix upload handling if image already exists (diff)
downloadtutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.gz
tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.xz
tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.zip
[client] first working draft for published images stuff
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java55
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java26
2 files changed, 79 insertions, 2 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java
new file mode 100644
index 00000000..e57a4a24
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java
@@ -0,0 +1,55 @@
+package org.openslx.dozmod.thrift.cache;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.ImagePublishData;
+import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
+import org.openslx.bwlp.thrift.iface.TAuthorizationException;
+import org.openslx.bwlp.thrift.iface.TInvocationException;
+import org.openslx.dozmod.gui.window.ImageListWindow;
+import org.openslx.dozmod.thrift.Session;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.util.GenericDataCache;
+import org.openslx.util.GenericDataCache.CacheMode;
+
+public class ImagePublishedCache {
+
+ private final static Logger LOGGER = Logger.getLogger(ImagePublishedCache.class);
+
+ private static final int CACHE_TIME_LIST_MS = 30 * 1000;
+
+ private static final GenericDataCache<List<ImageSummaryRead>> listCache = new GenericDataCache<List<ImageSummaryRead>>(
+ CACHE_TIME_LIST_MS) {
+ @Override
+ protected List<ImageSummaryRead> update()
+ throws TAuthorizationException, TInvocationException,
+ TException {
+ List<ImageSummaryRead> result = null;
+ int pageSize = Session.getSatelliteConfig().pageSize;
+ for (int i = 0;; ++i) {
+ List<ImageSummaryRead> page = null;
+ try {
+ page = ThriftManager.getMasterClient().getPublicImages(Session.getMasterToken(), i);
+ } catch (TException e) {
+ LOGGER.error("Could not get the list of public images from the masterserver.", e);
+ }
+ if (result == null) {
+ result = page;
+ } else {
+ result.addAll(page);
+ }
+ if (page.size() < pageSize)
+ break;
+ }
+ return result;
+ }
+ };
+
+ public static List<ImageSummaryRead> get(boolean forceRefresh) {
+ return listCache.get(forceRefresh ? CacheMode.NEVER_CACHED
+ : CacheMode.DEFAULT);
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
index 809c29fd..c831cd54 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
@@ -1,11 +1,13 @@
package org.openslx.dozmod.thrift.cache;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.UserInfo;
-import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.dozmod.thrift.Session;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.GenericDataCache;
@@ -45,6 +47,9 @@ public class UserCache {
}
};
+ // map for caching users found on the masterserver
+ private static final Map<String, UserInfo> cachedUserFromMaster = new HashMap<String, UserInfo>();
+
private UserCache() {
// No instancing
}
@@ -70,11 +75,28 @@ public class UserCache {
UserInfo user = find(userId, list);
if (user != null)
return user;
+ // still no user, look in local cache for master user
+ // TODO check validity of the map?
+ if (cachedUserFromMaster.containsKey(userId))
+ return cachedUserFromMaster.get(userId);
// Try again with a potential refresh
List<UserInfo> newList = cache.get(CacheMode.DEFAULT);
if (list == newList) // Returned list from cache as it was still recent enough
return null;
- return find(userId, newList);
+ user = find(userId, newList);
+ if (user == null) {
+ // not in cached map either, query master
+ try {
+ user = ThriftManager.getMasterClient().getUser(Session.getMasterToken(), userId);
+ } catch (TException e) {
+ LOGGER.error("User with ID '" + userId + "' not found on the masterserver.");
+ return null;
+ }
+ // remember it
+ if (user != null)
+ cachedUserFromMaster.put(userId, user);
+ }
+ return user;
}
private static UserInfo find(String userId, List<UserInfo> list) {