1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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.portal.kernel.util.StringUtil;
21  import com.liferay.portlet.calendar.model.CalEvent;
22  
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.ConcurrentHashMap;
26  
27  /**
28   * <a href="CalEventLocalUtil.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   * @author Michael Young
32   */
33  public class CalEventLocalUtil {
34  
35      public static final String CACHE_NAME = CalEventLocalUtil.class.getName();
36  
37      protected static void clearEventsPool(long groupId) {
38          String key = _encodeKey(groupId);
39  
40          _portalCache.remove(key);
41      }
42  
43      protected static Map<String, List<CalEvent>> getEventsPool(long groupId) {
44          String key = _encodeKey(groupId);
45  
46          Map <String, List<CalEvent>> eventsPool =
47              (Map<String, List<CalEvent>>)_portalCache.get(key);
48  
49          if (eventsPool == null) {
50              eventsPool = new ConcurrentHashMap<String, List<CalEvent>>();
51  
52              _portalCache.put(key, eventsPool);
53          }
54  
55          return eventsPool;
56      }
57  
58      private static String _encodeKey(long groupId) {
59          return CACHE_NAME.concat(StringPool.POUND).concat(
60              StringUtil.toHexString(groupId));
61      }
62  
63      private static PortalCache _portalCache = MultiVMPoolUtil.getCache(
64          CACHE_NAME);
65  
66  }