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.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.PortletPreferencesImpl;
26  
27  import java.util.Map;
28  import java.util.concurrent.ConcurrentHashMap;
29  
30  /**
31   * <a href="PortletPreferencesLocalUtil.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Michael Young
35   *
36   */
37  public class PortletPreferencesLocalUtil {
38  
39      public static final String CACHE_NAME =
40          PortletPreferencesLocalUtil.class.getName();
41  
42      protected static void clearPreferencesPool() {
43          _cache.removeAll();
44      }
45  
46      protected static void clearPreferencesPool(long ownerId, int ownerType) {
47          String key = _encodeKey(ownerId, ownerType);
48  
49          _cache.remove(key);
50      }
51  
52      protected static Map<String, PortletPreferencesImpl> getPreferencesPool(
53              long ownerId, int ownerType) {
54          String key = _encodeKey(ownerId, ownerType);
55  
56          Map<String, PortletPreferencesImpl> prefsPool =
57              (Map<String, PortletPreferencesImpl>)MultiVMPoolUtil.get(
58                  _cache, key);
59  
60          if (prefsPool == null) {
61              prefsPool = new ConcurrentHashMap<String, PortletPreferencesImpl>();
62  
63              MultiVMPoolUtil.put(_cache, key, prefsPool);
64          }
65  
66          return prefsPool;
67      }
68  
69      private static String _encodeKey(long ownerId, int ownerType) {
70          StringBuilder sb = new StringBuilder();
71  
72          sb.append(CACHE_NAME);
73          sb.append(StringPool.POUND);
74          sb.append(ownerId);
75          sb.append(StringPool.POUND);
76          sb.append(ownerType);
77  
78          return sb.toString();
79      }
80  
81      private static PortalCache _cache = MultiVMPoolUtil.getCache(CACHE_NAME);
82  
83  }