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