EMMA Coverage Report (generated Tue Apr 17 08:51:20 BST 2007)
[all classes][org.jtoolkit.essence.data.impl]

COVERAGE SUMMARY FOR SOURCE FILE [ThreadedListener.java]

nameclass, %method, %block, %line, %
ThreadedListener.java100% (2/2)100% (7/7)92%  (56/61)97%  (14.6/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ThreadedListener100% (1/1)100% (5/5)89%  (40/45)96%  (11.6/12)
onCallback (Event): void 100% (1/1)75%  (15/20)90%  (3.6/4)
ThreadedListener (Event$Listener): void 100% (1/1)100% (12/12)100% (4/4)
access$000 (ThreadedListener): Event$Listener 100% (1/1)100% (3/3)100% (1/1)
getUnderlying (): Event$Listener 100% (1/1)100% (3/3)100% (1/1)
onStatusEvent (boolean): void 100% (1/1)100% (7/7)100% (2/2)
     
class ThreadedListener$1100% (1/1)100% (2/2)100% (16/16)100% (3/3)
ThreadedListener$1 (ThreadedListener, Event): void 100% (1/1)100% (9/9)100% (1/1)
run (): void 100% (1/1)100% (7/7)100% (2/2)

1package org.jtoolkit.essence.data.impl;
2 
3import org.jetbrains.annotations.NotNull;
4import static org.jtoolkit.essence.concurrency.Threads.getCurrentSES;
5import org.jtoolkit.essence.data.Event;
6 
7import java.lang.ref.WeakReference;
8import java.util.concurrent.Executor;
9 
10/*
11   Copyright 2006 Peter Lawrey
12 
13   Licensed under the Apache License, Version 2.0 (the "License");
14   you may not use this file except in compliance with the License.
15   You may obtain a copy of the License at
16 
17       http://www.apache.org/licenses/LICENSE-2.0
18 
19   Unless required by applicable law or agreed to in writing, software
20   distributed under the License is distributed on an "AS IS" BASIS,
21   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   See the License for the specific language governing permissions and
23   limitations under the License.
24*/
25 
26/**
27 * @author Peter Lawrey
28 */
29public class ThreadedListener implements Event.Listener {
30    private final WeakReference<Executor> executor;
31    private final Event.Listener listener;
32 
33    public ThreadedListener(Event.Listener listener) {
34        this.listener = listener;
35        executor = new WeakReference<Executor>(getCurrentSES());
36    }
37 
38    public Event.Listener getUnderlying() {
39        return listener;
40    }
41 
42    private void onCallback(@NotNull final Event e) {
43        Executor executor = this.executor.get();
44        if (executor == null) throw new IllegalStateException("Executor no longer running.");
45        executor.execute(new Runnable() {
46            public void run() {
47                e.notifyListener(listener);
48            }
49        });
50    }
51 
52    public void onStatusEvent(boolean online) throws IllegalStateException {
53        onCallback(new Event.StatusEvent(online));
54    }
55}

[all classes][org.jtoolkit.essence.data.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov