001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }