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 com.liferay.portal.kernel.cache.CacheListenerScope;
018    
019    import java.util.Collections;
020    import java.util.HashMap;
021    import java.util.Map;
022    
023    /**
024     * @author Tina Tian
025     */
026    public class PortalCacheConfiguration {
027    
028            public static final String DEFAULT_PORTAL_CACHE_NAME =
029                    "DEFAULT_PORTAL_CACHE_NAME";
030    
031            public PortalCacheConfiguration(
032                    String portalCacheName,
033                    Map<CallbackConfiguration, CacheListenerScope>
034                            cacheListenerConfigurations,
035                    CallbackConfiguration bootstrapLoaderConfiguration) {
036    
037                    if (portalCacheName == null) {
038                            throw new NullPointerException("Portal cache name is null");
039                    }
040    
041                    _portalCacheName = portalCacheName;
042    
043                    if (cacheListenerConfigurations == null) {
044                            _cacheListenerConfigurations = Collections.emptyMap();
045                    }
046                    else {
047                            _cacheListenerConfigurations = new HashMap<>(
048                                    cacheListenerConfigurations);
049                    }
050    
051                    _bootstrapLoaderConfiguration = bootstrapLoaderConfiguration;
052            }
053    
054            public CallbackConfiguration getBootstrapLoaderConfiguration() {
055                    return _bootstrapLoaderConfiguration;
056            }
057    
058            public Map<CallbackConfiguration, CacheListenerScope>
059                    getCacheListenerConfigurations() {
060    
061                    return Collections.unmodifiableMap(_cacheListenerConfigurations);
062            }
063    
064            public String getPortalCacheName() {
065                    return _portalCacheName;
066            }
067    
068            public PortalCacheConfiguration newPortalCacheConfiguration(
069                    String portalCacheName) {
070    
071                    return new PortalCacheConfiguration(
072                            portalCacheName, _cacheListenerConfigurations,
073                            _bootstrapLoaderConfiguration);
074            }
075    
076            private final CallbackConfiguration _bootstrapLoaderConfiguration;
077            private final Map<CallbackConfiguration, CacheListenerScope>
078                    _cacheListenerConfigurations;
079            private final String _portalCacheName;
080    
081    }