| CalEventLocalUtil.java |
1 /**
2 * Copyright (c) 2000-2009 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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 * SOFTWARE.
18 */
19
20 package com.liferay.portlet.calendar.service.impl;
21
22 import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
23 import com.liferay.portal.kernel.cache.PortalCache;
24 import com.liferay.portal.kernel.util.StringPool;
25 import com.liferay.portlet.calendar.model.CalEvent;
26
27 import java.util.List;
28 import java.util.Map;
29 import java.util.concurrent.ConcurrentHashMap;
30
31 /**
32 * <a href="CalEventLocalUtil.java.html"><b><i>View Source</i></b></a>
33 *
34 * @author Brian Wing Shun Chan
35 * @author Michael Young
36 *
37 */
38 public class CalEventLocalUtil {
39
40 public static final String CACHE_NAME = CalEventLocalUtil.class.getName();
41
42 protected static void clearEventsPool(long groupId) {
43 String key = _encodeKey(groupId);
44
45 _cache.remove(key);
46 }
47
48 protected static Map<String, List<CalEvent>> getEventsPool(long groupId) {
49 String key = _encodeKey(groupId);
50
51 Map <String, List<CalEvent>> eventsPool =
52 (Map<String, List<CalEvent>>)MultiVMPoolUtil.get(_cache, key);
53
54 if (eventsPool == null) {
55 eventsPool = new ConcurrentHashMap<String, List<CalEvent>>();
56
57 MultiVMPoolUtil.put(_cache, key, eventsPool);
58 }
59
60 return eventsPool;
61 }
62
63 private static String _encodeKey(long groupId) {
64 StringBuilder sb = new StringBuilder();
65
66 sb.append(CACHE_NAME);
67 sb.append(StringPool.POUND);
68 sb.append(groupId);
69
70 return sb.toString();
71 }
72
73 private static PortalCache _cache = MultiVMPoolUtil.getCache(CACHE_NAME);
74
75 }