001
014
015 package com.liferay.portal.webserver;
016
017 import com.liferay.portal.kernel.cache.MultiVMPool;
018 import com.liferay.portal.kernel.cache.PortalCache;
019 import com.liferay.portal.kernel.security.pacl.DoPrivileged;
020 import com.liferay.portal.servlet.filters.cache.CacheUtil;
021
022
026 @DoPrivileged
027 public class WebServerServletTokenImpl implements WebServerServletToken {
028
029 public void afterPropertiesSet() {
030 _portalCache = (PortalCache<Long, String>)_multiVMPool.getCache(
031 _CACHE_NAME);
032 }
033
034 @Override
035 public String getToken(long imageId) {
036 Long key = imageId;
037
038 String token = _portalCache.get(key);
039
040 if (token == null) {
041 token = _createToken();
042
043 _portalCache.put(key, token);
044 }
045
046 return token;
047 }
048
049 @Override
050 public void resetToken(long imageId) {
051 _portalCache.remove(imageId);
052
053
054
055 CacheUtil.clearCache();
056 }
057
058 public void setMultiVMPool(MultiVMPool multiVMPool) {
059 _multiVMPool = multiVMPool;
060 }
061
062 private String _createToken() {
063 return String.valueOf(System.currentTimeMillis());
064 }
065
066 private static final String _CACHE_NAME =
067 WebServerServletToken.class.getName();
068
069 private MultiVMPool _multiVMPool;
070 private PortalCache<Long, String> _portalCache;
071
072 }