001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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.servlet.filters.cache.CacheUtil;
020    import com.liferay.portlet.journalcontent.util.JournalContentUtil;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class WebServerServletTokenImpl implements WebServerServletToken {
026    
027            public void afterPropertiesSet() {
028                    _portalCache = _multiVMPool.getCache(_CACHE_NAME);
029            }
030    
031            public String getToken(long imageId) {
032                    Long key = imageId;
033    
034                    String token = (String)_portalCache.get(key);
035    
036                    if (token == null) {
037                            token = _createToken(imageId);
038    
039                            _portalCache.put(key, token);
040                    }
041    
042                    return token;
043            }
044    
045            public void resetToken(long imageId) {
046                    _portalCache.remove(imageId);
047    
048                    // Journal content
049    
050                    JournalContentUtil.clearCache();
051    
052                    // Layout cache
053    
054                    CacheUtil.clearCache();
055            }
056    
057            public void setMultiVMPool(MultiVMPool multiVMPool) {
058                    _multiVMPool = multiVMPool;
059            }
060    
061            private String _createToken(long imageId) {
062                    return String.valueOf(System.currentTimeMillis());
063            }
064    
065            private static final String _CACHE_NAME =
066                    WebServerServletToken.class.getName();
067    
068            private MultiVMPool _multiVMPool;
069            private PortalCache _portalCache;
070    
071    }