EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveutils.service.impl]

COVERAGE SUMMARY FOR SOURCE FILE [ShutdownCoordinatorImpl.java]

nameclass, %method, %block, %line, %
ShutdownCoordinatorImpl.java100% (2/2)89%  (8/9)84%  (160/191)81%  (39/48)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ShutdownCoordinatorImpl100% (1/1)80%  (4/5)80%  (122/153)76%  (28/37)
removeRegistryShutdownListener (RegistryShutdownListener): void 0%   (0/1)0%   (0/27)0%   (0/7)
addRegistryShutdownListener (RegistryShutdownListener): void 100% (1/1)96%  (85/89)89%  (17/19)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
ShutdownCoordinatorImpl (int, List): void 100% (1/1)100% (14/14)100% (5/5)
shutdown (): void 100% (1/1)100% (19/19)100% (5/5)
     
class ShutdownCoordinatorImpl$ShutdownListener100% (1/1)100% (4/4)100% (38/38)100% (11/11)
<static initializer> 100% (1/1)100% (3/3)100% (1/1)
ShutdownCoordinatorImpl$ShutdownListener (RegistryShutdownListener, int): void 100% (1/1)100% (16/16)100% (5/5)
compareTo (ShutdownCoordinatorImpl$ShutdownListener): int 100% (1/1)100% (16/16)100% (4/4)
getListener (): RegistryShutdownListener 100% (1/1)100% (3/3)100% (1/1)

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.hiveutils.service.impl;
16 
17import java.util.Iterator;
18import java.util.List;
19import java.util.SortedSet;
20import java.util.TreeSet;
21 
22import org.apache.commons.logging.Log;
23import org.apache.commons.logging.LogFactory;
24import org.apache.hivemind.ShutdownCoordinator;
25import org.apache.hivemind.events.RegistryShutdownListener;
26 
27public final class ShutdownCoordinatorImpl implements ShutdownCoordinator
28{
29        static private final Log        _logger = LogFactory.getLog(ShutdownCoordinatorImpl.class);
30 
31        public ShutdownCoordinatorImpl(int defaultPriority, List<ShutdownContribution> priorities)
32        {
33                _priorities = priorities;
34                _defaultPriority = defaultPriority;
35                _listeners = new TreeSet<ShutdownListener>();
36        }
37        
38        public synchronized void        addRegistryShutdownListener(RegistryShutdownListener l)
39        {
40                _logger.debug("addRegistryShutdownListener() " + l);
41                // Check this listener is not already registered
42                for (ShutdownListener listener: _listeners)
43                {
44                        if (listener.getListener() == l)
45                        {
46                                _logger.debug("addRegistryShutdownListener() already registered");
47                                return;
48                        }
49                }
50                // OK, find whether it has a contribution with priority
51                int priority = _defaultPriority;
52                for (ShutdownContribution contrib: _priorities)
53                {
54                        if (contrib.getNameIsClass())
55                        {
56                                if (l.getClass().getName().equals(contrib.getName()))
57                                {
58                                        priority = contrib.getPriority();
59                                        break;
60                                }
61                        }
62                        else
63                        {
64                                if (l.toString().equals(contrib.getName()))
65                                {
66                                        priority = contrib.getPriority();
67                                        break;
68                                }
69                        }
70                }
71                _logger.debug("addRegistryShutdownListener() priority=" + priority);
72 
73                // Add it to the list of listeners
74                _listeners.add(new ShutdownListener(l, priority));
75        }
76        
77        public synchronized void        removeRegistryShutdownListener(RegistryShutdownListener l)
78        {
79                _logger.debug("removeRegistryShutdownListener() " + l);
80                Iterator<ShutdownListener> i = _listeners.iterator();
81                while (i.hasNext())
82                {
83                        if (i.next().getListener() == l)
84                        {
85                                i.remove();
86                                break;
87                        }
88                }
89        }
90        
91        public synchronized void        shutdown()
92        {
93                _logger.debug("shutdown()");
94                for (ShutdownListener listener: _listeners)
95                {
96                        listener.getListener().registryDidShutdown();
97                }
98        }
99        
100        static private class ShutdownListener implements Comparable<ShutdownListener>
101        {
102                public ShutdownListener(RegistryShutdownListener listener, int priority)
103                {
104                        _listener = listener;
105                        _priority = priority;
106                        _order = ++_count;
107                }
108                
109                public RegistryShutdownListener        getListener()
110                {
111                        return _listener;
112                }
113                
114                public int        compareTo(ShutdownListener that)
115                {
116                        int diff = this._priority - that._priority;
117                        if (diff != 0)
118                        {
119                                return diff;
120                        }
121                        else
122                        {
123                                return this._order - that._order;
124                        }
125                }
126                
127                private final RegistryShutdownListener        _listener;
128                private final int                                                _priority;
129                private final int                                                _order;
130                static private int                                                _count = 0;
131        }
132        
133        private final int                                                        _defaultPriority;
134        private final List<ShutdownContribution>        _priorities;
135        private final SortedSet<ShutdownListener>        _listeners;
136}

[all classes][net.sourceforge.hiveutils.service.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov