diff options
| author | Jonathan Bauer | 2015-07-14 17:25:45 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-07-14 17:25:45 +0200 |
| commit | 60fb2ddba61caa5155978ea707d7d1389ea444e8 (patch) | |
| tree | 4a999b8ea1cd4f3c877da0811fd6e921b3736fc5 | |
| parent | [client] more steps towards uploading an image: push image metadata to server (diff) | |
| parent | [client] Add user cache (diff) | |
| download | tutor-module-60fb2ddba61caa5155978ea707d7d1389ea444e8.tar.gz tutor-module-60fb2ddba61caa5155978ea707d7d1389ea444e8.tar.xz tutor-module-60fb2ddba61caa5155978ea707d7d1389ea444e8.zip | |
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
| -rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UserCache.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UserCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UserCache.java new file mode 100644 index 00000000..50c02f08 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UserCache.java @@ -0,0 +1,71 @@ +package org.openslx.dozmod.thrift; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.GenericDataCache; + +public class UserCache { + + private static final Logger LOGGER = Logger.getLogger(UserCache.class); + + /** + * How long should the list be cached? + */ + private static final int CACHE_TIME_MS = 5 * 60 * 1000; + + private static final GenericDataCache<List<UserInfo>> cache = new GenericDataCache<List<UserInfo>>( + CACHE_TIME_MS) { + + @Override + protected List<UserInfo> update() throws Exception { + List<UserInfo> result = null; + int pageSize = ThriftManager.getSatClient().getPageSize(); + for (int i = 0;; ++i) { + List<UserInfo> page = ThriftManager.getSatClient() + .getUserList(Session.getSatelliteToken(), i); + if (result == null) { + result = page; + } else { + result.addAll(page); + } + if (page.size() < pageSize) + break; + } + return result; + } + }; + + private UserCache() { + // No instancing + } + + /** + * Get all known users + * + * @return list of users + */ + public static List<UserInfo> getAll() { + return cache.get(); + } + + /** + * Find the user with the given id + * + * @param user id + * @return matching user, or <code>null</code> if not found + */ + public static UserInfo find(String userId) { + List<UserInfo> list = cache.get(); + if (list == null) + return null; + for (UserInfo user : list) { + if (user.userId.equals(userId)) + return user; + } + return null; + } + +} |
