001    /**
002     * Copyright (c) 2000-2013 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.portlet.calendar.service.impl;
016    
017    import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
018    import com.liferay.portal.kernel.cache.PortalCache;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.StringUtil;
021    import com.liferay.portlet.calendar.model.CalEvent;
022    
023    import java.io.Serializable;
024    
025    import java.util.List;
026    import java.util.Map;
027    import java.util.concurrent.ConcurrentHashMap;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Michael Young
032     */
033    public class CalEventLocalUtil {
034    
035            protected static void clearEventsPool(long groupId) {
036                    String key = _encodeKey(groupId);
037    
038                    _portalCache.remove(key);
039            }
040    
041            protected static Map<String, List<CalEvent>> getEventsPool(long groupId) {
042                    String key = _encodeKey(groupId);
043    
044                    Map<String, List<CalEvent>> eventsPool =
045                            (ConcurrentHashMap<String, List<CalEvent>>)_portalCache.get(key);
046    
047                    if (eventsPool == null) {
048                            eventsPool = new ConcurrentHashMap<String, List<CalEvent>>();
049    
050                            _portalCache.put(key, (Serializable)eventsPool);
051                    }
052    
053                    return eventsPool;
054            }
055    
056            private static String _encodeKey(long groupId) {
057                    return _CACHE_NAME.concat(StringPool.POUND).concat(
058                            StringUtil.toHexString(groupId));
059            }
060    
061            private static final String _CACHE_NAME = CalEventLocalUtil.class.getName();
062    
063            private static PortalCache<String, Serializable> _portalCache =
064                    MultiVMPoolUtil.getCache(_CACHE_NAME);
065    
066    }