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 import com.liferay.portlet.journalcontent.util.JournalContentUtil;
022
023
027 @DoPrivileged
028 public class WebServerServletTokenImpl implements WebServerServletToken {
029
030 public void afterPropertiesSet() {
031 _portalCache = (PortalCache<Long, String>)_multiVMPool.getCache(
032 _CACHE_NAME);
033 }
034
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(imageId);
042
043 _portalCache.put(key, token);
044 }
045
046 return token;
047 }
048
049 public void resetToken(long imageId) {
050 _portalCache.remove(imageId);
051
052
053
054 JournalContentUtil.clearCache();
055
056
057
058 CacheUtil.clearCache();
059 }
060
061 public void setMultiVMPool(MultiVMPool multiVMPool) {
062 _multiVMPool = multiVMPool;
063 }
064
065 private String _createToken(long imageId) {
066 return String.valueOf(System.currentTimeMillis());
067 }
068
069 private static final String _CACHE_NAME =
070 WebServerServletToken.class.getName();
071
072 private MultiVMPool _multiVMPool;
073 private PortalCache<Long, String> _portalCache;
074
075 }