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;
016    
017    import java.util.Collections;
018    import java.util.Set;
019    import java.util.concurrent.CopyOnWriteArraySet;
020    
021    /**
022     * @author Tina Tian
023     */
024    public class AggregatedPortalCacheManagerListener
025            implements PortalCacheManagerListener {
026    
027            public boolean addPortalCacheListener(
028                    PortalCacheManagerListener portalCacheManagerListener) {
029    
030                    if (portalCacheManagerListener == null) {
031                            return false;
032                    }
033    
034                    return _portalCacheManagerListeners.add(portalCacheManagerListener);
035            }
036    
037            public void clearAll() {
038                    _portalCacheManagerListeners.clear();
039            }
040    
041            @Override
042            public void dispose() throws PortalCacheException {
043                    for (PortalCacheManagerListener portalCacheManagerListener :
044                                    _portalCacheManagerListeners) {
045    
046                            portalCacheManagerListener.dispose();
047                    }
048            }
049    
050            public Set<PortalCacheManagerListener> getPortalCacheManagerListeners() {
051                    return Collections.unmodifiableSet(_portalCacheManagerListeners);
052            }
053    
054            @Override
055            public void init() throws PortalCacheException {
056                    for (PortalCacheManagerListener portalCacheManagerListener :
057                                    _portalCacheManagerListeners) {
058    
059                            portalCacheManagerListener.init();
060                    }
061            }
062    
063            @Override
064            public void notifyPortalCacheAdded(String portalCacheName) {
065                    for (PortalCacheManagerListener portalCacheManagerListener :
066                                    _portalCacheManagerListeners) {
067    
068                            portalCacheManagerListener.notifyPortalCacheAdded(portalCacheName);
069                    }
070            }
071    
072            @Override
073            public void notifyPortalCacheRemoved(String portalCacheName) {
074                    for (PortalCacheManagerListener portalCacheManagerListener :
075                                    _portalCacheManagerListeners) {
076    
077                            portalCacheManagerListener.notifyPortalCacheRemoved(
078                                    portalCacheName);
079                    }
080            }
081    
082            public boolean removePortalCacheListener(
083                    PortalCacheManagerListener portalCacheManagerListener) {
084    
085                    if (portalCacheManagerListener == null) {
086                            return false;
087                    }
088    
089                    return _portalCacheManagerListeners.remove(portalCacheManagerListener);
090            }
091    
092            private final Set<PortalCacheManagerListener> _portalCacheManagerListeners =
093                    new CopyOnWriteArraySet<>();
094    
095    }