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.lar;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portlet.exportimport.lifecycle.BaseProcessExportImportLifecycleListener;
020    
021    import java.io.Serializable;
022    
023    import java.util.List;
024    import java.util.concurrent.Callable;
025    
026    /**
027     * @author Daniel Kocsis
028     */
029    public class ExportImportProcessCallbackLifecycleListener
030            extends BaseProcessExportImportLifecycleListener {
031    
032            @Override
033            public boolean isParallel() {
034                    return false;
035            }
036    
037            @Override
038            protected void onProcessFailed(List<Serializable> attributes)
039                    throws Exception {
040    
041                    ExportImportProcessCallbackUtil.popCallbackList();
042            }
043    
044            @Override
045            protected void onProcessStarted(List<Serializable> attributes)
046                    throws Exception {
047    
048                    ExportImportProcessCallbackUtil.pushCallbackList();
049            }
050    
051            @Override
052            protected void onProcessSucceeded(List<Serializable> attributes)
053                    throws Exception {
054    
055                    List<Callable<?>> callables =
056                            ExportImportProcessCallbackUtil.popCallbackList();
057    
058                    for (Callable<?> callable : callables) {
059                            try {
060                                    callable.call();
061                            }
062                            catch (Exception e) {
063                                    _log.error(
064                                            "Unable to execute export import process callback", e);
065                            }
066                    }
067            }
068    
069            private static final Log _log = LogFactoryUtil.getLog(
070                    ExportImportProcessCallbackLifecycleListener.class);
071    
072    };