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.search.queue;
016    
017    import com.liferay.portal.kernel.search.BaseSearchEngine;
018    import com.liferay.portal.kernel.search.IndexSearcher;
019    import com.liferay.portal.kernel.search.IndexWriter;
020    import com.liferay.portal.kernel.search.dummy.DummyIndexSearcher;
021    import com.liferay.portal.kernel.util.ProxyUtil;
022    import com.liferay.portal.kernel.util.QueuingInvocationHandler;
023    
024    /**
025     * @author Michael C. Han
026     */
027    public class QueuingSearchEngine extends BaseSearchEngine {
028    
029            public QueuingSearchEngine(int capacity) {
030                    _queuingInvocationHandler = new QueuingInvocationHandler(capacity);
031    
032                    _indexWriter = (IndexWriter)ProxyUtil.newProxyInstance(
033                            getClass().getClassLoader(), new Class[] {IndexWriter.class},
034                            _queuingInvocationHandler);
035            }
036    
037            public void flush() {
038                    _queuingInvocationHandler.flush();
039            }
040    
041            @Override
042            public IndexSearcher getIndexSearcher() {
043                    return _indexSearcher;
044            }
045    
046            @Override
047            public IndexWriter getIndexWriter() {
048                    return _indexWriter;
049            }
050    
051            public void invokeQueued(IndexWriter indexWriter) throws Exception {
052                    _queuingInvocationHandler.invokeQueued(indexWriter);
053            }
054    
055            private final IndexSearcher _indexSearcher = new DummyIndexSearcher();
056            private final IndexWriter _indexWriter;
057            private final QueuingInvocationHandler _queuingInvocationHandler;
058    
059    }