| WebAppPool.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.portal.util;
21
22 import java.util.Map;
23 import java.util.concurrent.ConcurrentHashMap;
24
25 /**
26 * <a href="WebAppPool.java.html"><b><i>View Source</i></b></a>
27 *
28 * @author Brian Wing Shun Chan
29 *
30 */
31 public class WebAppPool {
32
33 public static Object get(String webAppId, String key) {
34 return _instance._get(webAppId, key);
35 }
36
37 public static void put(String webAppId, String key, Object obj) {
38 _instance._put(webAppId, key, obj);
39 }
40
41 public static Object remove(String webAppId, String key) {
42 return _instance._remove(webAppId, key);
43 }
44
45 private WebAppPool() {
46 _webAppPool = new ConcurrentHashMap<String, Map<String, Object>>();
47 }
48
49 private Object _get(String webAppId, String key) {
50 Map<String, Object> map = _webAppPool.get(webAppId);
51
52 if (map == null) {
53 return null;
54 }
55 else {
56 return map.get(key);
57 }
58 }
59
60 private void _put(String webAppId, String key, Object obj) {
61 Map<String, Object> map = _webAppPool.get(webAppId);
62
63 if (map == null) {
64 map = new ConcurrentHashMap<String, Object>();
65
66 _webAppPool.put(webAppId, map);
67 }
68
69 map.put(key, obj);
70 }
71
72 private Object _remove(String webAppId, String key) {
73 Map<String, Object> map = _webAppPool.get(webAppId);
74
75 if (map == null) {
76 return null;
77 }
78 else {
79 return map.remove(key);
80 }
81 }
82
83 private static WebAppPool _instance = new WebAppPool();
84
85 private Map<String, Map<String, Object>> _webAppPool;
86
87 }