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.search.buffer;
016    
017    import com.liferay.portal.kernel.transaction.TransactionCommitCallbackRegistryUtil;
018    import com.liferay.portal.util.PropsValues;
019    
020    import java.util.concurrent.Callable;
021    
022    /**
023     * @author Michael C. Han
024     */
025    public class IndexerRequestBufferTransactionLifecycleListener {
026    
027            public static void committed() {
028    
029                    IndexerRequestBuffer indexerRequestBuffer =
030                            IndexerRequestBuffer.remove();
031    
032                    if ((indexerRequestBuffer != null) && !indexerRequestBuffer.isEmpty()) {
033                            IndexerRequestBufferUtil.execute(indexerRequestBuffer);
034                    }
035            }
036    
037            public static void created() {
038                    if (!PropsValues.INDEX_REQUEST_BUFFER_ENABLED) {
039                            return;
040                    }
041    
042                    TransactionCommitCallbackRegistryUtil.registerCallback(
043                            new Callable<Void>() {
044    
045                                    @Override
046                                    public Void call() throws Exception {
047                                            committed();
048    
049                                            return null;
050                                    }
051    
052                            });
053    
054                    IndexerRequestBuffer.create();
055            }
056    
057            public static void rollbacked() {
058    
059                    IndexerRequestBuffer indexerRequestBuffer =
060                            IndexerRequestBuffer.remove();
061    
062                    if ((indexerRequestBuffer != null) && !indexerRequestBuffer.isEmpty()) {
063                            indexerRequestBuffer.clear();
064                    }
065            }
066    
067    }