EMMA Coverage Report (generated Tue Oct 27 11:32:50 PDT 2009)
[all classes][net.spy.memcached.transcoders]

COVERAGE SUMMARY FOR SOURCE FILE [TranscodeService.java]

nameclass, %method, %block, %line, %
TranscodeService.java100% (3/3)91%  (10/11)88%  (101/115)89%  (20.5/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TranscodeService$Task100% (1/1)75%  (3/4)77%  (24/31)80%  (8/10)
get (long, TimeUnit): Object 0%   (0/1)0%   (0/7)0%   (0/2)
TranscodeService$Task (Callable): void 100% (1/1)100% (10/10)100% (3/3)
get (): Object 100% (1/1)100% (5/5)100% (2/2)
run (): void 100% (1/1)100% (9/9)100% (3/3)
     
class TranscodeService100% (1/1)100% (5/5)89%  (59/66)95%  (10.5/11)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
decode (Transcoder, CachedData): Future 100% (1/1)84%  (26/31)91%  (4.5/5)
TranscodeService (): void 100% (1/1)100% (19/19)100% (3/3)
isShutdown (): boolean 100% (1/1)100% (4/4)100% (1/1)
shutdown (): void 100% (1/1)100% (4/4)100% (2/2)
     
class TranscodeService$1100% (1/1)100% (2/2)100% (18/18)100% (2/2)
TranscodeService$1 (TranscodeService, Transcoder, CachedData): void 100% (1/1)100% (12/12)100% (1/1)
call (): Object 100% (1/1)100% (6/6)100% (1/1)

1package net.spy.memcached.transcoders;
2 
3import java.util.concurrent.ArrayBlockingQueue;
4import java.util.concurrent.Callable;
5import java.util.concurrent.ExecutionException;
6import java.util.concurrent.Future;
7import java.util.concurrent.FutureTask;
8import java.util.concurrent.ThreadPoolExecutor;
9import java.util.concurrent.TimeUnit;
10import java.util.concurrent.TimeoutException;
11import java.util.concurrent.atomic.AtomicBoolean;
12 
13import net.spy.memcached.CachedData;
14import net.spy.memcached.compat.SpyObject;
15 
16/**
17 * Asynchronous transcoder.
18 */
19public class TranscodeService extends SpyObject {
20 
21        private final ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 10, 60L,
22                        TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(100),
23                        new ThreadPoolExecutor.DiscardPolicy());
24 
25        /**
26         * Perform a decode.
27         */
28        public <T> Future<T> decode(final Transcoder<T> tc,
29                        final CachedData cachedData) {
30 
31                assert !pool.isShutdown() : "Pool has already shut down.";
32 
33                TranscodeService.Task<T> task = new TranscodeService.Task<T>(
34                                new Callable<T>() {
35                                        public T call() {
36                                                return tc.decode(cachedData);
37                                        }
38                                });
39 
40                if (tc.asyncDecode(cachedData)) {
41                        this.pool.execute(task);
42                }
43                return task;
44        }
45 
46        /**
47         * Shut down the pool.
48         */
49        public void shutdown() {
50                pool.shutdown();
51        }
52 
53        /**
54         * Ask whether this service has been shut down.
55         */
56        public boolean isShutdown() {
57                return pool.isShutdown();
58        }
59 
60        private static class Task<T> extends FutureTask<T> {
61                private final AtomicBoolean isRunning = new AtomicBoolean(false);
62 
63                public Task(Callable<T> callable) {
64                        super(callable);
65                }
66 
67                @Override
68                public T get() throws InterruptedException, ExecutionException {
69                        this.run();
70                        return super.get();
71                }
72 
73                @Override
74                public T get(long timeout, TimeUnit unit) throws InterruptedException,
75                                ExecutionException, TimeoutException {
76                        this.run();
77                        return super.get(timeout, unit);
78                }
79 
80                @Override
81                public void run() {
82                        if (this.isRunning.compareAndSet(false, true)) {
83                                super.run();
84                        }
85                }
86        }
87 
88}

[all classes][net.spy.memcached.transcoders]
EMMA 2.0.5312 (C) Vladimir Roubtsov