001    /**
002     * Copyright (c) 2000-2013 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.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    }