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

File ActiveInstallsPingThread.java

 

Coverage histogram

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

Code metrics

0
9
2
1
89
36
4
0.44
4.5
2
2

Classes

Class Line # Actions
ActiveInstallsPingThread 37 9 0% 4 2
0.818181881.8%
 

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.activeinstalls.internal.client;
21   
22    import org.apache.commons.lang.exception.ExceptionUtils;
23    import org.slf4j.Logger;
24    import org.slf4j.LoggerFactory;
25    import org.xwiki.activeinstalls.ActiveInstallsConfiguration;
26   
27    import com.xpn.xwiki.util.AbstractXWikiRunnable;
28   
29    /**
30    * Thread that regularly sends information about the current instance (its unique id + the id and versions of all
31    * installed extensions) to a central active installs Elastic Search server in order to count the number of active
32    * installs of XWiki (and to know what extensions and in which versions they use).
33    *
34    * @version $Id: 5b5ee05932744621284e0b9b8c6fd6e0d8ff47c9 $
35    * @since 5.2M2
36    */
 
37    public class ActiveInstallsPingThread extends AbstractXWikiRunnable
38    {
39    /**
40    * The logger to use when logging in this class.
41    */
42    private static final Logger LOGGER = LoggerFactory.getLogger(ActiveInstallsPingThread.class);
43   
44    /**
45    * Once every 24 hours.
46    */
47    private static final long WAIT_TIME = 1000L * 60L * 60L * 24L;
48   
49    /**
50    * @see #ActiveInstallsPingThread(org.xwiki.activeinstalls.ActiveInstallsConfiguration, PingSender)
51    */
52    private PingSender manager;
53   
54    /**
55    * @see #ActiveInstallsPingThread(org.xwiki.activeinstalls.ActiveInstallsConfiguration, PingSender)
56    */
57    private ActiveInstallsConfiguration configuration;
58   
59    /**
60    * @param configuration used to nicely display the ping URL in logs if there's an error...
61    * @param manager used to send the ping to the remote instance
62    */
 
63  1 toggle public ActiveInstallsPingThread(ActiveInstallsConfiguration configuration, PingSender manager)
64    {
65  1 this.configuration = configuration;
66  1 this.manager = manager;
67    }
68   
 
69  1 toggle @Override
70    protected void runInternal()
71    {
72  1 while (true) {
73  1 try {
74  1 this.manager.sendPing();
75    } catch (Exception e) {
76    // Failed to connect or send the ping to the remote Elastic Search instance, will try again after the
77    // sleep.
78  0 LOGGER.warn(
79    "Failed to send Active Installation ping to [{}]. Error = [{}]. Will retry in [{}] seconds...",
80    this.configuration.getPingInstanceURL(), ExceptionUtils.getRootCauseMessage(e), WAIT_TIME / 1000);
81    }
82  1 try {
83  1 Thread.sleep(WAIT_TIME);
84    } catch (InterruptedException e) {
85  0 break;
86    }
87    }
88    }
89    }