001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.search;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.search.DummyIndexer;
020    import com.liferay.portal.kernel.search.Indexer;
021    import com.liferay.portal.kernel.search.IndexerRegistry;
022    import com.liferay.portal.kernel.util.ListUtil;
023    import com.liferay.portal.spring.aop.ServiceBeanAopCacheManagerUtil;
024    
025    import java.util.List;
026    import java.util.Map;
027    import java.util.concurrent.ConcurrentHashMap;
028    
029    /**
030     * @author Raymond Aug??
031     */
032    public class IndexerRegistryImpl implements IndexerRegistry {
033    
034            @Override
035            public Indexer getIndexer(String className) {
036                    return _indexers.get(className);
037            }
038    
039            @Override
040            public List<Indexer> getIndexers() {
041                    return ListUtil.fromMapValues(_indexers);
042            }
043    
044            @Override
045            public Indexer nullSafeGetIndexer(String className) {
046                    Indexer indexer = _indexers.get(className);
047    
048                    if (indexer != null) {
049                            return indexer;
050                    }
051    
052                    if (_log.isWarnEnabled()) {
053                            _log.warn("No indexer found for " + className);
054                    }
055    
056                    return _dummyIndexer;
057            }
058    
059            @Override
060            public void register(String className, Indexer indexerInstance) {
061                    _indexers.put(className, indexerInstance);
062    
063                    ServiceBeanAopCacheManagerUtil.reset();
064            }
065    
066            @Override
067            public void unregister(String className) {
068                    _indexers.remove(className);
069            }
070    
071            private static Log _log = LogFactoryUtil.getLog(IndexerRegistryImpl.class);
072    
073            private Indexer _dummyIndexer = new DummyIndexer();
074            private Map<String, Indexer> _indexers =
075                    new ConcurrentHashMap<String, Indexer>();
076    
077    }