summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-08 19:40:22 +0200
committerSimon Rettberg2015-07-08 19:40:22 +0200
commitf99ba9714f704ae7bc043eb4ff9ded3f8bf27026 (patch)
tree46004703ccab656860ff4eacb5b41d0ded055285 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java
parent[client] Redo package structure, add comments/TODOs, rename GUI classes (diff)
downloadtutor-module-f99ba9714f704ae7bc043eb4ff9ded3f8bf27026.tar.gz
tutor-module-f99ba9714f704ae7bc043eb4ff9ded3f8bf27026.tar.xz
tutor-module-f99ba9714f704ae7bc043eb4ff9ded3f8bf27026.zip
[server] Implement OS list fetching, caching, and fallback to local DB
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java33
1 files changed, 30 insertions, 3 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java
index ea81a452..87898d33 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java
@@ -1,8 +1,13 @@
package org.openslx.bwlp.sat.thrift.cache;
+import java.sql.SQLException;
import java.util.List;
+import org.apache.log4j.Logger;
import org.apache.thrift.TException;
+import org.openslx.bwlp.sat.database.mappers.DbOsVirt;
+import org.openslx.bwlp.sat.util.QuickTimer;
+import org.openslx.bwlp.sat.util.QuickTimer.Task;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.thrifthelper.ThriftManager;
@@ -12,6 +17,8 @@ import org.openslx.thrifthelper.ThriftManager;
*/
public class OperatingSystemList extends CacheBase<List<OperatingSystem>> {
+ private static final Logger LOGGER = Logger.getLogger(OperatingSystemList.class);
+
private static final OperatingSystemList instance = new OperatingSystemList();
public static List<OperatingSystem> get() {
@@ -19,9 +26,29 @@ public class OperatingSystemList extends CacheBase<List<OperatingSystem>> {
}
@Override
- protected List<OperatingSystem> getCallback() throws TException {
- return ThriftManager.getMasterClient().getOperatingSystems();
- // TODO: Store in DB
+ protected List<OperatingSystem> getCallback() {
+ final List<OperatingSystem> list;
+ try {
+ list = ThriftManager.getMasterClient().getOperatingSystems();
+ } catch (TException e1) {
+ LOGGER.warn("Could not fetch OS list from master, using local data...", e1);
+ try {
+ return DbOsVirt.getOsList();
+ } catch (SQLException e) {
+ LOGGER.warn("Using local OS list from database also failed.", e);
+ }
+ return null;
+ }
+ QuickTimer.scheduleOnce(new Task() {
+ @Override
+ public void fire() {
+ try {
+ DbOsVirt.storeOsList(list);
+ } catch (SQLException e) {
+ }
+ }
+ });
+ return list;
}
}