1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.search.solr.internal

File SolrIndexInitializeListener.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
8
3
1
100
52
5
0.62
2.67
3
1.67

Classes

Class Line # Actions
SolrIndexInitializeListener 49 8 0% 5 2
0.8461538684.6%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.search.solr.internal;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.slf4j.Logger;
31    import org.xwiki.bridge.event.ApplicationReadyEvent;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.observation.EventListener;
34    import org.xwiki.observation.event.Event;
35    import org.xwiki.search.solr.internal.api.SolrConfiguration;
36    import org.xwiki.search.solr.internal.api.SolrIndexer;
37    import org.xwiki.search.solr.internal.api.SolrIndexerException;
38    import org.xwiki.search.solr.internal.job.IndexerRequest;
39   
40    /**
41    * Automatically start synchronization at startup.
42    *
43    * @version $Id: a95495c841d21fcfd9b58a03d4ce0a05d074dfc3 $
44    * @since 5.1RC1
45    */
46    @Component
47    @Named("solr.initializer")
48    @Singleton
 
49    public class SolrIndexInitializeListener implements EventListener
50    {
51    /**
52    * The events to listen to that trigger the index update.
53    */
54    private static final List<Event> EVENTS = Arrays.<Event> asList(new ApplicationReadyEvent());
55   
56    /**
57    * Logging framework.
58    */
59    @Inject
60    protected Logger logger;
61   
62    /**
63    * The solr index.
64    * <p>
65    * Lazily initialize the {@link SolrIndexer} to not initialize it too early.
66    */
67    @Inject
68    private Provider<SolrIndexer> solrIndexer;
69   
70    @Inject
71    private SolrConfiguration configuration;
72   
 
73  3 toggle @Override
74    public List<Event> getEvents()
75    {
76  3 return EVENTS;
77    }
78   
 
79  12 toggle @Override
80    public String getName()
81    {
82  12 return this.getClass().getName();
83    }
84   
 
85  3 toggle @Override
86    public void onEvent(Event event, Object source, Object data)
87    {
88  3 if (this.configuration.synchronizeAtStartup()) {
89    // Start synchronization
90  3 IndexerRequest request = new IndexerRequest();
91  3 request.setId(Arrays.asList("solr", "indexer"));
92   
93  3 try {
94  3 this.solrIndexer.get().startIndex(request);
95    } catch (SolrIndexerException e) {
96  0 this.logger.error("Failed to start initial Solr index synchronization", e);
97    }
98    }
99    }
100    }