EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.event]

COVERAGE SUMMARY FOR SOURCE FILE [EventDispatcherImpl.java]

nameclass, %method, %block, %line, %
EventDispatcherImpl.java100% (1/1)86%  (6/7)74%  (73/98)70%  (26/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EventDispatcherImpl100% (1/1)86%  (6/7)74%  (73/98)70%  (26/37)
delay (): void 0%   (0/1)0%   (0/10)0%   (0/5)
waitForCompletion (): void 100% (1/1)45%  (5/11)60%  (3/5)
run (): void 100% (1/1)67%  (18/27)64%  (7/11)
EventDispatcherImpl (Log, WhiteBoardUserService, ThreadEventNotifier, Channel... 100% (1/1)100% (24/24)100% (8/8)
fireEvents (Event []): void 100% (1/1)100% (15/15)100% (3/3)
start (): void 100% (1/1)100% (7/7)100% (3/3)
stop (): void 100% (1/1)100% (4/4)100% (2/2)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveboard.event;
16 
17import org.apache.commons.logging.Log;
18import org.apache.hivemind.service.ThreadEventNotifier;
19 
20import net.sourceforge.hiveboard.Event;
21import net.sourceforge.hiveboard.WhiteBoardUserService;
22import net.sourceforge.hiveevents.Channel;
23 
24public class EventDispatcherImpl implements EventDispatcher, Runnable
25{
26        public        EventDispatcherImpl(Log                                                logger,
27                                                                WhiteBoardUserService        service,
28                                                                ThreadEventNotifier                notifier,
29                                                                Channel<Event>                        channel)
30        {
31                _logger = logger;
32                _service = service;
33                _notifier = notifier;
34                _channel = channel;
35                _stop = true;
36                _thread = new Thread(this);
37        }
38 
39        public void        stop()
40        {
41                _stop = true;
42        }
43 
44        public void        start()
45        {
46                _stop = false;
47                _thread.start();
48        }
49 
50        public void        waitForCompletion()
51        {
52                try
53                {
54                        _thread.join();
55                }
56                catch (InterruptedException e)
57                {
58                        _logger.warn("waitForCompletion", e);
59                }
60        }
61        
62        public void        run()
63        {
64                while (!_stop)
65                {
66                        // CSOFF: IllegalCatchCheck
67                        try
68                        {
69                                Event[] events = _service.pull();
70                                if (!_stop)
71                                {
72                                        fireEvents(events);
73                                }
74                        }
75                        catch (Exception e)
76                        {
77                                _logger.warn("pull", e);
78                                delay();
79                        }
80                        // CSON: IllegalCatchCheck
81                }
82                _notifier.fireThreadCleanup();
83        }
84        
85        private void        delay()
86        {
87                try
88                {
89                        Thread.sleep(WAIT_AFTER_EXCEPTION);
90                }
91                catch (InterruptedException e)
92                {
93                        _logger.warn("delay", e);
94                }
95        }
96        
97        protected void        fireEvents(Event[] events)
98        {
99                for (int i = 0; i < events.length; i++)
100                {
101                        _channel.push(events[i]);
102                }
103        }
104 
105        static final private long                        WAIT_AFTER_EXCEPTION = 200L;
106                
107        final private Log                                        _logger;
108        final private WhiteBoardUserService        _service;
109        final private ThreadEventNotifier        _notifier;
110        final private Channel<Event>                _channel;
111        final private Thread                                _thread;
112        private boolean                                                _stop;
113}
114 

[all classes][net.sourceforge.hiveboard.event]
EMMA 2.0.5312 (C) Vladimir Roubtsov