001    /**
002     * Copyright (c) 2000-2013 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.messaging;
016    
017    import com.liferay.portal.kernel.util.SetUtil;
018    
019    import java.util.List;
020    import java.util.Set;
021    
022    /**
023     * @author Michael C. Han
024     */
025    public class GlobalDestinationEventListener
026            extends BaseDestinationEventListener {
027    
028            public GlobalDestinationEventListener() {
029            }
030    
031            /**
032             * @deprecated
033             */
034            public GlobalDestinationEventListener(
035                    MessageListener messageListener, List<String> ignoredDestinations) {
036    
037                    _messageListener = messageListener;
038                    _ignoredDestinations = SetUtil.fromList(ignoredDestinations);
039            }
040    
041            @Override
042            public void destinationAdded(Destination destination) {
043                    if (!_ignoredDestinations.contains(destination.getName())) {
044                            destination.register(_messageListener);
045                    }
046            }
047    
048            @Override
049            public void destinationRemoved(Destination destination) {
050                    if (!_ignoredDestinations.contains(destination.getName())) {
051                            destination.unregister(_messageListener);
052                    }
053            }
054    
055            public void setIgnoredDestinations(List<String> ignoredDestinations) {
056                    _ignoredDestinations = SetUtil.fromList(ignoredDestinations);
057            }
058    
059            public void setMessageListener(MessageListener messageListener) {
060                    _messageListener = messageListener;
061            }
062    
063            private Set<String> _ignoredDestinations;
064            private MessageListener _messageListener;
065    
066    }