diff options
| author | Simon Rettberg | 2015-07-14 17:10:51 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-07-14 17:10:51 +0200 |
| commit | fc2aafbe481754420fc49cf244fdb10d9ab20786 (patch) | |
| tree | 4e8f57f3358f12ed23d2fca9455b7cae1b7440c9 | |
| parent | [client] Filter now is case insensitive. Filter and ordering now stable with ... (diff) | |
| download | tutor-module-fc2aafbe481754420fc49cf244fdb10d9ab20786.tar.gz tutor-module-fc2aafbe481754420fc49cf244fdb10d9ab20786.tar.xz tutor-module-fc2aafbe481754420fc49cf244fdb10d9ab20786.zip | |
[client] Add user cache
| -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; + } + +} |
