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

File ForbiddenThreadsFilter.java

 

Coverage histogram

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

Code metrics

2
5
3
1
67
27
4
0.8
1.67
3
1.33

Classes

Class Line # Actions
ForbiddenThreadsFilter 35 5 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 123 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.logging.logback.internal;
21   
22    import java.util.Collections;
23    import java.util.Set;
24    import java.util.concurrent.ConcurrentHashMap;
25   
26    import ch.qos.logback.classic.spi.ILoggingEvent;
27    import ch.qos.logback.core.filter.Filter;
28    import ch.qos.logback.core.spi.FilterReply;
29   
30    /**
31    * Filters events not from the provided {@link Thread}.
32    *
33    * @version $Id: 582577a097c7d54f4825dcafafc9d647672ce0ef $
34    */
 
35    public class ForbiddenThreadsFilter extends Filter<ILoggingEvent>
36    {
37    /**
38    * The forbidden thread.
39    */
40    private Set<Thread> threads = Collections.newSetFromMap(new ConcurrentHashMap<Thread, Boolean>());
41   
 
42  46699 toggle @Override
43    public FilterReply decide(ILoggingEvent event)
44    {
45  46699 if (this.threads.contains(Thread.currentThread())) {
46  3319 return FilterReply.DENY;
47    }
48   
49  43379 return FilterReply.NEUTRAL;
50    }
51   
52    /**
53    * @param thread the new forbidden thread
54    */
 
55  450 toggle public void addThread(Thread thread)
56    {
57  450 this.threads.add(thread);
58    }
59   
60    /**
61    * @param thread the thread to remove from the list of forbidden threads
62    */
 
63  449 toggle public void removeThread(Thread thread)
64    {
65  449 this.threads.remove(thread);
66    }
67    }