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

File SolrInstanceProvider.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
5
2
1
76
37
3
0.6
2.5
2
1.5

Classes

Class Line # Actions
SolrInstanceProvider 42 5 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

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 javax.inject.Inject;
23    import javax.inject.Provider;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.manager.ComponentLookupException;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.component.phase.Initializable;
30    import org.xwiki.component.phase.InitializationException;
31    import org.xwiki.search.solr.internal.api.SolrConfiguration;
32    import org.xwiki.search.solr.internal.api.SolrInstance;
33   
34    /**
35    * Provider for {@link SolrInstance} that, based on the current configuration, returns the right component.
36    *
37    * @version $Id: 260622a3d6ba6eb25c3914e0157feb17125993c8 $
38    * @since 4.3M2
39    */
40    @Component
41    @Singleton
 
42    public class SolrInstanceProvider implements Provider<SolrInstance>, Initializable
43    {
44    /**
45    * Solr configuration.
46    */
47    @Inject
48    private SolrConfiguration configuration;
49   
50    /**
51    * The component manager used to lookup the configured component.
52    */
53    @Inject
54    private ComponentManager componentManager;
55   
56    /** The Solr instance configured. Since the configuration is read only once at startup, it can be cached. */
57    private SolrInstance configuredInstance;
58   
 
59  6 toggle @Override
60    public void initialize() throws InitializationException
61    {
62  6 String type = this.configuration.getServerType();
63  6 try {
64  6 this.configuredInstance = this.componentManager.getInstance(SolrInstance.class, type);
65    } catch (ComponentLookupException e) {
66  1 throw new InitializationException(
67    String.format("Failed to lookup configured Solr instance type [%s]", type), e);
68    }
69    }
70   
 
71  1442 toggle @Override
72    public SolrInstance get()
73    {
74  1442 return this.configuredInstance;
75    }
76    }