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.portlet.exportimport.lifecycle;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.messaging.BaseMessageListener;
020    import com.liferay.portal.kernel.messaging.DestinationNames;
021    import com.liferay.portal.kernel.messaging.Message;
022    
023    import java.util.Set;
024    
025    /**
026     * @author Daniel Kocsis
027     */
028    public class ExportImportLifecycleMessageListener extends BaseMessageListener {
029    
030            @Override
031            protected void doReceive(Message message) throws Exception {
032                    Set<ExportImportLifecycleListener> exportImportLifecycleListeners =
033                            getExportImportLifecycleListeners(message);
034    
035                    ExportImportLifecycleEvent exportImportLifecycleEvent =
036                            (ExportImportLifecycleEvent)message.get(
037                                    "exportImportLifecycleEvent");
038    
039                    for (ExportImportLifecycleListener exportImportLifecycleListener :
040                                    exportImportLifecycleListeners) {
041    
042                            try {
043                                    exportImportLifecycleListener.onExportImportLifecycleEvent(
044                                            exportImportLifecycleEvent);
045                            }
046                            catch (Exception e) {
047                                    if (_log.isWarnEnabled()) {
048                                            _log.warn(
049                                                    "Unable to call " +
050                                                            exportImportLifecycleListener.getClass(),
051                                                    e);
052                                    }
053                            }
054                    }
055            }
056    
057            protected Set<ExportImportLifecycleListener>
058                    getExportImportLifecycleListeners(Message message) {
059    
060                    String destinationName = message.getDestinationName();
061    
062                    if (destinationName.equals(
063                                    DestinationNames.EXPORT_IMPORT_LIFECYCLE_EVENT_SYNC)) {
064    
065                            return ExportImportLifecycleEventListenerRegistryUtil.
066                                    getSyncExportImportLifecycleListeners();
067                    }
068    
069                    return ExportImportLifecycleEventListenerRegistryUtil.
070                            getAsyncExportImportLifecycleListeners();
071            }
072    
073            private static final Log _log = LogFactoryUtil.getLog(
074                    ExportImportLifecycleMessageListener.class);
075    
076    }