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

File ActiveInstallsInitializerListener.java

 

Coverage histogram

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

Code metrics

0
5
3
1
91
42
3
0.6
1.67
3
1

Classes

Class Line # Actions
ActiveInstallsInitializerListener 47 5 0% 3 0
1.0100%
 

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 java.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Provider;
29    import javax.inject.Singleton;
30   
31    import org.xwiki.activeinstalls.ActiveInstallsConfiguration;
32    import org.xwiki.bridge.event.ApplicationReadyEvent;
33    import org.xwiki.component.annotation.Component;
34    import org.xwiki.instance.InstanceIdManager;
35    import org.xwiki.observation.EventListener;
36    import org.xwiki.observation.event.Event;
37   
38    /**
39    * Used to trigger a Thread to periodically send a ping to the remote instance that stores it.
40    *
41    * @version $Id: 3e0dfafb366be287907123166ed1f81e4b9ce41c $
42    * @since 5.2M2
43    */
44    @Component
45    @Singleton
46    @Named("ActiveInstallsInitializerListener")
 
47    public class ActiveInstallsInitializerListener implements EventListener
48    {
49    /**
50    * The events observed by this event listener.
51    */
52    private static final List<Event> EVENTS = new ArrayList<Event>(Arrays.asList(new ApplicationReadyEvent()));
53   
54    /**
55    * Used to send the ping to the remote instance.
56    * <p>
57    * Note that we use a Provider since the Observation Manager will register listeners very early in the
58    * initialization process and some of the components injected transitively by the {@link InstanceIdManager}
59    * implementation have initialization code that require an Execution Context to be available, which is not the case
60    * early one in XWiki's initialization since no HTTP request has been made yet...
61    */
62    @Inject
63    private Provider<PingSender> pingSenderProvider;
64   
65    /**
66    * Used to display the remote URL being hit in the logs if the ping fails...
67    */
68    @Inject
69    private ActiveInstallsConfiguration configuration;
70   
 
71  1 toggle @Override
72    public List<Event> getEvents()
73    {
74  1 return EVENTS;
75    }
76   
 
77  4 toggle @Override
78    public String getName()
79    {
80  4 return "ActiveInstallsInitializerListener";
81    }
82   
 
83  1 toggle @Override
84    public void onEvent(Event event, Object source, Object data)
85    {
86    // Start a thread to regularly send pings to the active installs server.
87  1 Thread pingThread = new Thread(new ActiveInstallsPingThread(this.configuration, this.pingSenderProvider.get()));
88  1 pingThread.setName("Active Installs Ping Thread");
89  1 pingThread.start();
90    }
91    }