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