1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.calendar.service.impl;
16  
17  import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
18  import com.liferay.portal.kernel.cache.PortalCache;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portlet.calendar.model.CalEvent;
21  
22  import java.util.List;
23  import java.util.Map;
24  import java.util.concurrent.ConcurrentHashMap;
25  
26  /**
27   * <a href="CalEventLocalUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   * @author Michael Young
31   */
32  public class CalEventLocalUtil {
33  
34      public static final String CACHE_NAME = CalEventLocalUtil.class.getName();
35  
36      protected static void clearEventsPool(long groupId) {
37          String key = _encodeKey(groupId);
38  
39          _cache.remove(key);
40      }
41  
42      protected static Map<String, List<CalEvent>> getEventsPool(long groupId) {
43          String key = _encodeKey(groupId);
44  
45          Map <String, List<CalEvent>> eventsPool =
46              (Map<String, List<CalEvent>>)_cache.get(key);
47  
48          if (eventsPool == null) {
49              eventsPool = new ConcurrentHashMap<String, List<CalEvent>>();
50  
51              _cache.put(key, eventsPool);
52          }
53  
54          return eventsPool;
55      }
56  
57      private static String _encodeKey(long groupId) {
58          return CACHE_NAME.concat(StringPool.POUND).concat(
59              String.valueOf(groupId));
60      }
61  
62      private static PortalCache _cache = MultiVMPoolUtil.getCache(CACHE_NAME);
63  
64  }