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 = new HashSet<>(
038                                    cacheManagerListenerConfigurations);
039                    }
040    
041                    _defaultPortalCacheConfiguration = defaultPortalCacheConfiguration;
042    
043                    _portalCacheConfigurations = new ConcurrentHashMap<>();
044    
045                    if (portalCacheConfigurations != null) {
046                            for (PortalCacheConfiguration portalCacheConfiguration :
047                                            portalCacheConfigurations) {
048    
049                                    _portalCacheConfigurations.put(
050                                            portalCacheConfiguration.getPortalCacheName(),
051                                            portalCacheConfiguration);
052                            }
053                    }
054            }
055    
056            public Set<CallbackConfiguration>
057                    getCacheManagerListenerConfigurations() {
058    
059                    return Collections.unmodifiableSet(_cacheManagerListenerConfigurations);
060            }
061    
062            public PortalCacheConfiguration getDefaultPortalCacheConfiguration() {
063                    return _defaultPortalCacheConfiguration;
064            }
065    
066            public PortalCacheConfiguration getPortalCacheConfiguration(
067                    String portalCacheName) {
068    
069                    return _portalCacheConfigurations.get(portalCacheName);
070            }
071    
072            public Set<String> getPortalCacheNames() {
073                    return Collections.unmodifiableSet(_portalCacheConfigurations.keySet());
074            }
075    
076            public PortalCacheConfiguration putPortalCacheConfiguration(
077                    String portalCacheName,
078                    PortalCacheConfiguration portalCacheConfiguration) {
079    
080                    return _portalCacheConfigurations.put(
081                            portalCacheName, portalCacheConfiguration);
082            }
083    
084            private final Set<CallbackConfiguration>
085                    _cacheManagerListenerConfigurations;
086            private final PortalCacheConfiguration _defaultPortalCacheConfiguration;
087            private final Map<String, PortalCacheConfiguration>
088                    _portalCacheConfigurations;
089    
090    }