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

File AbstractThreadEventListener.java

 

Coverage histogram

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

Code metrics

2
4
3
1
71
22
4
1
1.33
3
1.33

Classes

Class Line # Actions
AbstractThreadEventListener 30 4 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 148 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.observation;
21   
22    import org.xwiki.observation.event.Event;
23   
24    /**
25    * Filter events by keeping only events produced by the provided {@link Thread}.
26    *
27    * @version $Id: 50b106ccae4955b72d841da0d42a0aea98d374bc $
28    * @since 3.2M3
29    */
 
30    public abstract class AbstractThreadEventListener implements EventListener
31    {
32    /**
33    * The thread to match to receive events.
34    */
35    private Thread thread;
36   
37    /**
38    * Use {@link Thread#currentThread()}.
39    */
 
40  1134 toggle public AbstractThreadEventListener()
41    {
42  1134 this.thread = Thread.currentThread();
43    }
44   
45    /**
46    * @param thread the thread to match to receive events.
47    */
 
48  1 toggle public AbstractThreadEventListener(Thread thread)
49    {
50  1 this.thread = thread;
51    }
52   
 
53  26847 toggle @Override
54    public void onEvent(Event event, Object source, Object data)
55    {
56  26848 if (this.thread == Thread.currentThread()) {
57  18253 onEventInternal(event, source, data);
58    }
59    }
60   
61    /**
62    * Called when the event has been produce by the proper {@link Thread}.
63    *
64    * @param event the event triggered. Can be used to differentiate different events if your Object supports several
65    * events for example.
66    * @param source the event source i.e. the object for which the event was triggered. For example this would be the
67    * document Object if the event is a document update event.
68    * @param data some additional and optional data passed that can be acted on.
69    */
70    protected abstract void onEventInternal(Event event, Object source, Object data);
71    }