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.spring.aop.ServiceBeanAopCacheManagerUtil;
023    
024    import java.util.ArrayList;
025    import java.util.HashSet;
026    import java.util.List;
027    import java.util.Map;
028    import java.util.concurrent.ConcurrentHashMap;
029    
030    /**
031     * @author Raymond Aug??
032     */
033    public class IndexerRegistryImpl implements IndexerRegistry {
034    
035            @Override
036            public Indexer getIndexer(String className) {
037                    return _indexers.get(className);
038            }
039    
040            @Override
041            public List<Indexer> getIndexers() {
042                    return new ArrayList<Indexer>(new HashSet<Indexer>(_indexers.values()));
043            }
044    
045            @Override
046            public Indexer nullSafeGetIndexer(String className) {
047                    Indexer indexer = _indexers.get(className);
048    
049                    if (indexer != null) {
050                            return indexer;
051                    }
052    
053                    if (_log.isInfoEnabled()) {
054                            _log.info("No indexer found for " + className);
055                    }
056    
057                    return _dummyIndexer;
058            }
059    
060            @Override
061            public void register(String className, Indexer indexerInstance) {
062                    _indexers.put(className, indexerInstance);
063    
064                    ServiceBeanAopCacheManagerUtil.reset();
065            }
066    
067            @Override
068            public void unregister(String className) {
069                    _indexers.remove(className);
070            }
071    
072            private static Log _log = LogFactoryUtil.getLog(IndexerRegistryImpl.class);
073    
074            private Indexer _dummyIndexer = new DummyIndexer();
075            private Map<String, Indexer> _indexers =
076                    new ConcurrentHashMap<String, Indexer>();
077    
078    }