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.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    }