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                    Class<?> clazz = getClass();
033    
034                    _indexWriter = (IndexWriter)ProxyUtil.newProxyInstance(
035                            clazz.getClassLoader(), new Class[] {IndexWriter.class},
036                            _queuingInvocationHandler);
037            }
038    
039            public void flush() {
040                    _queuingInvocationHandler.flush();
041            }
042    
043            @Override
044            public IndexSearcher getIndexSearcher() {
045                    return _indexSearcher;
046            }
047    
048            @Override
049            public IndexWriter getIndexWriter() {
050                    return _indexWriter;
051            }
052    
053            public void invokeQueued(IndexWriter indexWriter) throws Exception {
054                    _queuingInvocationHandler.invokeQueued(indexWriter);
055            }
056    
057            private final IndexSearcher _indexSearcher = new DummyIndexSearcher();
058            private final IndexWriter _indexWriter;
059            private final QueuingInvocationHandler _queuingInvocationHandler;
060    
061    }