|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ShutdownCoordinatorImpl.java | 75% | 88.9% | 83.3% | 84.4% |
|
1 |
// Copyright 2004 The Apache Software Foundation
|
|
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 |
|
|
15 |
package org.apache.hivemind.impl;
|
|
16 |
|
|
17 |
import java.util.Iterator;
|
|
18 |
|
|
19 |
import org.apache.commons.logging.Log;
|
|
20 |
import org.apache.commons.logging.LogFactory;
|
|
21 |
import org.apache.hivemind.ShutdownCoordinator;
|
|
22 |
import org.apache.hivemind.events.RegistryShutdownListener;
|
|
23 |
import org.apache.hivemind.util.EventListenerList;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Manages a list of objects that implement the
|
|
27 |
* {@link org.apache.hivemind.events.RegistryShutdownListener} interface.
|
|
28 |
*
|
|
29 |
* @author Howard Lewis Ship
|
|
30 |
*/
|
|
31 |
public final class ShutdownCoordinatorImpl implements ShutdownCoordinator |
|
32 |
{ |
|
33 |
private final Log _log;
|
|
34 |
|
|
35 | 85 |
public ShutdownCoordinatorImpl()
|
36 |
{ |
|
37 | 85 |
this(LogFactory.getLog(ShutdownCoordinatorImpl.class)); |
38 |
} |
|
39 |
|
|
40 | 98 |
public ShutdownCoordinatorImpl(Log log)
|
41 |
{ |
|
42 | 98 |
_log = log; |
43 |
} |
|
44 |
|
|
45 |
private EventListenerList _listenerList;
|
|
46 |
|
|
47 | 629 |
public synchronized void addRegistryShutdownListener(RegistryShutdownListener s) |
48 |
{ |
|
49 | 629 |
if (_listenerList == null) |
50 | 88 |
_listenerList = new EventListenerList();
|
51 |
|
|
52 | 629 |
_listenerList.addListener(s); |
53 |
} |
|
54 |
|
|
55 | 0 |
public synchronized void removeRegistryShutdownListener(RegistryShutdownListener s) |
56 |
{ |
|
57 | 0 |
if (_listenerList != null) |
58 | 0 |
_listenerList.removeListener(s); |
59 |
} |
|
60 |
|
|
61 | 28 |
public void shutdown() |
62 |
{ |
|
63 | 28 |
if (_listenerList == null) |
64 | 11 |
return;
|
65 |
|
|
66 | 17 |
Iterator i = _listenerList.getListeners(); |
67 |
|
|
68 | 17 |
_listenerList = null;
|
69 |
|
|
70 | 17 |
while (i.hasNext())
|
71 |
{ |
|
72 | 99 |
RegistryShutdownListener s = (RegistryShutdownListener) i.next(); |
73 |
|
|
74 | 99 |
shutdown(s); |
75 |
} |
|
76 |
|
|
77 | 17 |
_listenerList = null;
|
78 |
} |
|
79 |
|
|
80 | 99 |
private void shutdown(RegistryShutdownListener s) |
81 |
{ |
|
82 | 99 |
try
|
83 |
{ |
|
84 | 99 |
s.registryDidShutdown(); |
85 |
} |
|
86 |
catch (RuntimeException ex)
|
|
87 |
{ |
|
88 | 1 |
_log.error(ImplMessages.shutdownCoordinatorFailure(s, ex), ex); |
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
} |
|
93 |
|
|