summaryrefslogtreecommitdiffstats
path: root/dozentenmodul
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-27 15:49:54 +0200
committerSimon Rettberg2015-08-27 15:49:54 +0200
commit951db6e8742a9abdc0a9420432c5825dcf428480 (patch)
tree57ceda25dba41f37f306dcdb2dff5573b5a0010a /dozentenmodul
parent[client] Fix comments in QFileChooser (diff)
downloadtutor-module-951db6e8742a9abdc0a9420432c5825dcf428480.tar.gz
tutor-module-951db6e8742a9abdc0a9420432c5825dcf428480.tar.xz
tutor-module-951db6e8742a9abdc0a9420432c5825dcf428480.zip
[client] More agressive cache usage for .get*byId .find in Thift Cache helpers
Diffstat (limited to 'dozentenmodul')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java45
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/OrganizationCache.java38
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java24
3 files changed, 81 insertions, 26 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java
index 340d95e8..98f54d36 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java
@@ -8,6 +8,7 @@ import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.GenericDataCache;
+import org.openslx.util.GenericDataCache.CacheMode;
public class MetaDataCache {
@@ -54,12 +55,24 @@ public class MetaDataCache {
}
public static OperatingSystem getOsById(int id) {
- List<OperatingSystem> list = getOperatingSystems();
- if (list == null)
+ // First, try in "always cached" mode
+ List<OperatingSystem> list = osCache.get(CacheMode.ALWAYS_CACHED);
+ OperatingSystem os = getOsById(id, list);
+ if (os != null)
+ return os;
+ // Try again with a potential refresh
+ List<OperatingSystem> newList = osCache.get(CacheMode.DEFAULT);
+ if (list == newList) // Returned list from cache as it was still recent enough
return null;
- for (OperatingSystem os : list) {
- if (os.getOsId() == id)
- return os;
+ return getOsById(id, newList);
+ }
+
+ private static OperatingSystem getOsById(int id, List<OperatingSystem> list) {
+ if (list != null) {
+ for (OperatingSystem os : list) {
+ if (os.getOsId() == id)
+ return os;
+ }
}
return null;
}
@@ -74,12 +87,24 @@ public class MetaDataCache {
}
public static Virtualizer getVirtualizerById(String virtId) {
- List<Virtualizer> list = getVirtualizers();
- if (list == null)
+ // First, try in "always cached" mode
+ List<Virtualizer> list = virtualizerCache.get(CacheMode.ALWAYS_CACHED);
+ Virtualizer virt = getVirtualizerById(virtId, list);
+ if (virt != null)
+ return virt;
+ // Try again with a potential refresh
+ List<Virtualizer> newList = virtualizerCache.get(CacheMode.DEFAULT);
+ if (list == newList) // Returned list from cache as it was still recent enough
return null;
- for (Virtualizer virt : list) {
- if (virt.getVirtId().equals(virtId))
- return virt;
+ return getVirtualizerById(virtId, newList);
+ }
+
+ private static Virtualizer getVirtualizerById(String virtId, List<Virtualizer> list) {
+ if (list != null) {
+ for (Virtualizer virt : list) {
+ if (virt.getVirtId().equals(virtId))
+ return virt;
+ }
}
return null;
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/OrganizationCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/OrganizationCache.java
index 4d1c1225..95a6aa2e 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/OrganizationCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/OrganizationCache.java
@@ -7,24 +7,28 @@ import org.openslx.bwlp.thrift.iface.Organization;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.GenericDataCache;
+import org.openslx.util.GenericDataCache.CacheMode;
public class OrganizationCache {
-
+
private static final Logger LOGGER = Logger.getLogger(OrganizationCache.class);
-
+
/**
* How long should the list be cached?
*/
private static final int CACHE_TIME_MS = 20 * 60 * 1000;
- private static final GenericDataCache<List<Organization>> cache = new GenericDataCache<List<Organization>>(CACHE_TIME_MS) {
-
+ private static final GenericDataCache<List<Organization>> cache = new GenericDataCache<List<Organization>>(
+ CACHE_TIME_MS) {
+
@Override
protected List<Organization> update() throws Exception {
try {
return ThriftManager.getMasterClient().getOrganizations();
} catch (Exception e) {
- LOGGER.warn("Failed to get organization list from master server, trying satellite for backup..", e);
+ LOGGER.warn(
+ "Failed to get organization list from master server, trying satellite for backup..",
+ e);
}
return ThriftManager.getSatClient().getAllOrganizations();
// TODO: Sort list by display name?
@@ -53,7 +57,7 @@ public class OrganizationCache {
public static Organization find(UserInfo user) {
return find(user.organizationId);
}
-
+
/**
* Find the organization with the given id
*
@@ -61,12 +65,24 @@ public class OrganizationCache {
* @return matching organization, or <code>null</code> if not found
*/
public static Organization find(String organizationId) {
- List<Organization> list = cache.get();
- if (list == null)
+ // First, try in "always cached" mode
+ List<Organization> list = cache.get(CacheMode.ALWAYS_CACHED);
+ Organization org = find(organizationId, list);
+ if (org != null)
+ return org;
+ // Try again with a potential refresh
+ List<Organization> newList = cache.get(CacheMode.DEFAULT);
+ if (list == newList) // Returned list from cache as it was still recent enough
return null;
- for (Organization org : list) {
- if (org.organizationId.equals(organizationId))
- return org;
+ return find(organizationId, newList);
+ }
+
+ private static Organization find(String organizationId, List<Organization> list) {
+ if (list != null) {
+ for (Organization org : list) {
+ if (org.organizationId.equals(organizationId))
+ return org;
+ }
}
return null;
}
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 d73f650d..fd23c376 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
@@ -5,9 +5,11 @@ import java.util.List;
import org.apache.log4j.Logger;
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;
+import org.openslx.util.GenericDataCache.CacheMode;
public class UserCache {
@@ -63,12 +65,24 @@ public class UserCache {
* @return matching user, or <code>null</code> if not found
*/
public static UserInfo find(String userId) {
- List<UserInfo> list = cache.get();
- if (list == null)
+ // First, try in "always cached" mode
+ List<UserInfo> list = cache.get(CacheMode.ALWAYS_CACHED);
+ UserInfo user = find(userId, list);
+ if (user != null)
+ return user;
+ // 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;
- for (UserInfo user : list) {
- if (user.userId.equals(userId))
- return user;
+ return find(userId, newList);
+ }
+
+ private static UserInfo find(String userId, List<UserInfo> list) {
+ if (list != null) {
+ for (UserInfo user : list) {
+ if (user.userId.equals(userId))
+ return user;
+ }
}
return null;
}