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

File DefaultJestClientManager.java

 

Coverage histogram

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

Code metrics

2
8
3
1
78
41
4
0.5
2.67
3
1.33

Classes

Class Line # Actions
DefaultJestClientManager 45 8 0% 4 1
0.923076992.3%
 

Contributing tests

This file is covered by 7 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.activeinstalls.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.activeinstalls.ActiveInstallsConfiguration;
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.manager.ComponentLifecycleException;
28    import org.xwiki.component.phase.Disposable;
29    import org.xwiki.component.phase.Initializable;
30    import org.xwiki.component.phase.InitializationException;
31   
32    import io.searchbox.client.JestClient;
33    import io.searchbox.client.JestClientFactory;
34    import io.searchbox.client.config.HttpClientConfig;
35   
36    /**
37    * Factory to get a singleton {@link JestClient} instance since it's threadsafe. The URL to connect to is defined in
38    * the Active Install configuration.
39    *
40    * @version $Id: 8da96e247f5327d24823b2c10f356cac18ace25a $
41    * @since 5.2M2
42    */
43    @Component
44    @Singleton
 
45    public class DefaultJestClientManager implements JestClientManager, Initializable, Disposable
46    {
47    @Inject
48    private ActiveInstallsConfiguration configuration;
49   
50    /**
51    * The Jest Client singleton instance to use to connect to the remote instance.
52    */
53    private JestClient client;
54   
 
55  8 toggle @Override
56    public void initialize() throws InitializationException
57    {
58  8 String pingURL = this.configuration.getPingInstanceURL();
59  8 HttpClientConfig clientConfig = new HttpClientConfig.Builder(pingURL).multiThreaded(true).build();
60  8 JestClientFactory factory = new XWikiJestClientFactory(this.configuration);
61  8 factory.setHttpClientConfig(clientConfig);
62  8 this.client = factory.getObject();
63    }
64   
 
65  8 toggle @Override
66    public void dispose() throws ComponentLifecycleException
67    {
68  8 if (this.client != null) {
69  8 this.client.shutdownClient();
70    }
71    }
72   
 
73  36 toggle @Override
74    public JestClient getClient()
75    {
76  36 return this.client;
77    }
78    }