EMMA Coverage Report (generated Mon Aug 23 17:21:34 CEST 2010)
[all classes][diskCacheV111.util]

COVERAGE SUMMARY FOR SOURCE FILE [ThreadPoolNG.java]

nameclass, %method, %block, %line, %
ThreadPoolNG.java100% (1/1)33%  (3/9)37%  (30/81)42%  (8/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ThreadPoolNG100% (1/1)33%  (3/9)37%  (30/81)42%  (8/19)
ThreadPoolNG (CellAdapter): void 0%   (0/1)0%   (0/5)0%   (0/2)
getCurrentThreadCount (): int 0%   (0/1)0%   (0/4)0%   (0/1)
getMaxThreadCount (): int 0%   (0/1)0%   (0/4)0%   (0/1)
getWaitingThreadCount (): int 0%   (0/1)0%   (0/2)0%   (0/1)
invokeLater (Runnable, String): void 0%   (0/1)0%   (0/19)0%   (0/4)
toString (): String 0%   (0/1)0%   (0/15)0%   (0/1)
setMaxThreadCount (int): void 100% (1/1)78%  (7/9)75%  (3/4)
ThreadPoolNG (): void 100% (1/1)100% (4/4)100% (2/2)
ThreadPoolNG (ThreadFactory): void 100% (1/1)100% (19/19)100% (3/3)

1package diskCacheV111.util;
2 
3import java.util.concurrent.SynchronousQueue;
4import java.util.concurrent.ThreadPoolExecutor;
5import java.util.concurrent.TimeUnit;
6import java.util.concurrent.ThreadFactory;
7import java.util.concurrent.Executors;
8 
9import dmg.cells.nucleus.CellAdapter;
10import dmg.cells.nucleus.CDC;
11 
12import org.dcache.util.CDCThreadFactory;
13import org.dcache.util.FireAndForgetTask;
14 
15/**
16 *
17 * ThreadPoolNG ( Thread Pool New Generation is a
18 * java concurrent based implementation of dCache
19 * Thread pool. While it's nothing else than wrapper
20 * around ThreadPoolExecutor, it's better to replace all
21 * instances of ThreadPool with pure  ThreadPoolExecutor.
22 *
23 * @since 1.8
24 */
25public class ThreadPoolNG implements ThreadPool {
26 
27    private static final int CORE_SIZE = 0;
28    private static final int MAX_SIZE = Integer.MAX_VALUE;
29    private static final long KEEP_ALIVE = 60L;
30 
31    private final ThreadPoolExecutor _executor;
32 
33    public ThreadPoolNG(CellAdapter cell)
34    {
35        this(cell.getNucleus());
36    }
37 
38    public ThreadPoolNG()
39    {
40        this(Executors.defaultThreadFactory());
41    }
42 
43    private ThreadPoolNG(ThreadFactory factory)
44    {
45        _executor = new ThreadPoolExecutor(CORE_SIZE,
46                                           MAX_SIZE,
47                                           KEEP_ALIVE,
48                                           TimeUnit.SECONDS,
49                                           new SynchronousQueue<Runnable>(),
50                                           new CDCThreadFactory(factory));
51    }
52 
53 
54        public int getCurrentThreadCount() {
55                return _executor.getActiveCount();
56        }
57 
58        public int getMaxThreadCount() {
59                return _executor.getMaximumPoolSize();
60        }
61 
62        public int getWaitingThreadCount() {
63                return 0;
64        }
65 
66    public void invokeLater(final Runnable runner, String name)
67    {
68        final CDC cdc = new CDC();
69        Runnable wrapper = new Runnable() {
70                public void run()
71                {
72                    cdc.apply();
73                    try {
74                        runner.run();
75                    } finally {
76                        CDC.clear();
77                    }
78                }
79            };
80 
81        _executor.execute(new FireAndForgetTask(wrapper));
82    }
83 
84        public void setMaxThreadCount(int maxThreadCount)
85                        throws IllegalArgumentException {
86 
87        /*
88         * Be backward compatible with
89         */
90         if(maxThreadCount == 0)
91             maxThreadCount = MAX_SIZE;
92 
93                _executor.setMaximumPoolSize(maxThreadCount);
94        }
95 
96        public String toString() {
97                return "ThreadPoolNG $Revision: 1.4 $ max/active: " + getMaxThreadCount() + "/" + getCurrentThreadCount();
98        }
99}

[all classes][diskCacheV111.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov