001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.cache.configuration;
016    
017    import java.util.Collections;
018    import java.util.HashSet;
019    import java.util.Map;
020    import java.util.Set;
021    import java.util.concurrent.ConcurrentHashMap;
022    
023    /**
024     * @author Tina Tian
025     */
026    public class PortalCacheManagerConfiguration {
027    
028            public PortalCacheManagerConfiguration(
029                    Set<CallbackConfiguration> cacheManagerListenerConfigurations,
030                    PortalCacheConfiguration defaultPortalCacheConfiguration,
031                    Set<PortalCacheConfiguration> portalCacheConfigurations) {
032    
033                    if (cacheManagerListenerConfigurations == null) {
034                            _cacheManagerListenerConfigurations = Collections.emptySet();
035                    }
036                    else {
037                            _cacheManagerListenerConfigurations =
038                                    new HashSet<CallbackConfiguration>(
039                                            cacheManagerListenerConfigurations);
040                    }
041    
042                    _defaultPortalCacheConfiguration = defaultPortalCacheConfiguration;
043    
044                    _portalCacheConfigurations =
045                            new ConcurrentHashMap<String, PortalCacheConfiguration>();
046    
047                    if (portalCacheConfigurations != null) {
048                            for (PortalCacheConfiguration portalCacheConfiguration :
049                                            portalCacheConfigurations) {
050    
051                                    _portalCacheConfigurations.put(
052                                            portalCacheConfiguration.getPortalCacheName(),
053                                            portalCacheConfiguration);
054                            }
055                    }
056            }
057    
058            public Set<CallbackConfiguration>
059                    getCacheManagerListenerConfigurations() {
060    
061                    return Collections.unmodifiableSet(_cacheManagerListenerConfigurations);
062            }
063    
064            public PortalCacheConfiguration getDefaultPortalCacheConfiguration() {
065                    return _defaultPortalCacheConfiguration;
066            }
067    
068            public PortalCacheConfiguration getPortalCacheConfiguration(
069                    String portalCacheName) {
070    
071                    return _portalCacheConfigurations.get(portalCacheName);
072            }
073    
074            public Set<String> getPortalCacheNames() {
075                    return Collections.unmodifiableSet(_portalCacheConfigurations.keySet());
076            }
077    
078            public PortalCacheConfiguration putPortalCacheConfiguration(
079                    String portalCacheName,
080                    PortalCacheConfiguration portalCacheConfiguration) {
081    
082                    return _portalCacheConfigurations.put(
083                            portalCacheName, portalCacheConfiguration);
084            }
085    
086            private final Set<CallbackConfiguration>
087                    _cacheManagerListenerConfigurations;
088            private final PortalCacheConfiguration _defaultPortalCacheConfiguration;
089            private final Map<String, PortalCacheConfiguration>
090                    _portalCacheConfigurations;
091    
092    }