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.Properties;
021    import java.util.Set;
022    import java.util.concurrent.ConcurrentHashMap;
023    
024    /**
025     * @author Tina Tian
026     */
027    public class PortalCacheManagerConfiguration {
028    
029            public PortalCacheManagerConfiguration(
030                    Set<Properties> portalCacheManagerListenerPropertiesSet,
031                    PortalCacheConfiguration defaultPortalCacheConfiguration,
032                    Set<PortalCacheConfiguration> portalCacheConfigurations) {
033    
034                    if (portalCacheManagerListenerPropertiesSet == null) {
035                            _portalCacheManagerListenerPropertiesSet = Collections.emptySet();
036                    }
037                    else {
038                            _portalCacheManagerListenerPropertiesSet = new HashSet<>(
039                                    portalCacheManagerListenerPropertiesSet);
040                    }
041    
042                    _defaultPortalCacheConfiguration = defaultPortalCacheConfiguration;
043    
044                    _portalCacheConfigurations = new ConcurrentHashMap<>();
045    
046                    if (portalCacheConfigurations != null) {
047                            for (PortalCacheConfiguration portalCacheConfiguration :
048                                            portalCacheConfigurations) {
049    
050                                    _portalCacheConfigurations.put(
051                                            portalCacheConfiguration.getPortalCacheName(),
052                                            portalCacheConfiguration);
053                            }
054                    }
055            }
056    
057            public PortalCacheConfiguration getDefaultPortalCacheConfiguration() {
058                    return _defaultPortalCacheConfiguration;
059            }
060    
061            public PortalCacheConfiguration getPortalCacheConfiguration(
062                    String portalCacheName) {
063    
064                    return _portalCacheConfigurations.get(portalCacheName);
065            }
066    
067            public Set<Properties> getPortalCacheManagerListenerPropertiesSet() {
068                    return Collections.unmodifiableSet(
069                            _portalCacheManagerListenerPropertiesSet);
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 PortalCacheConfiguration _defaultPortalCacheConfiguration;
085            private final Map<String, PortalCacheConfiguration>
086                    _portalCacheConfigurations;
087            private final Set<Properties> _portalCacheManagerListenerPropertiesSet;
088    
089    }