2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:33:43 PST
file stats: LOC: 110   Methods: 6
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ShutdownCoordinatorImpl.java 83.3% 91.3% 83.3% 87.8%
coverage coverage
 1    // Copyright 2004, 2005 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.HashSet;
 18    import java.util.Iterator;
 19    import java.util.Set;
 20   
 21    import org.apache.commons.logging.Log;
 22    import org.apache.commons.logging.LogFactory;
 23    import org.apache.hivemind.ShutdownCoordinator;
 24    import org.apache.hivemind.events.RegistryShutdownListener;
 25    import org.apache.hivemind.util.EventListenerList;
 26   
 27    /**
 28    * Manages a list of objects that implement the
 29    * {@link org.apache.hivemind.events.RegistryShutdownListener} interface.
 30    *
 31    * @author Howard Lewis Ship
 32    */
 33    public final class ShutdownCoordinatorImpl implements ShutdownCoordinator
 34    {
 35    private final Log _log;
 36   
 37    private Set alreadyShutdown;
 38   
 39  131 public ShutdownCoordinatorImpl()
 40    {
 41  131 this(LogFactory.getLog(ShutdownCoordinatorImpl.class));
 42    }
 43   
 44  163 public ShutdownCoordinatorImpl(Log log)
 45    {
 46  163 _log = log;
 47    }
 48   
 49    private EventListenerList _listenerList;
 50   
 51  1705 public synchronized void addRegistryShutdownListener(
 52    RegistryShutdownListener s)
 53    {
 54  1705 if (_listenerList == null)
 55  140 _listenerList = new EventListenerList();
 56   
 57  1705 _listenerList.addListener(s);
 58    }
 59   
 60  0 public synchronized void removeRegistryShutdownListener(
 61    RegistryShutdownListener s)
 62    {
 63  0 if (_listenerList != null)
 64  0 _listenerList.removeListener(s);
 65    }
 66   
 67  60 public void shutdown()
 68    {
 69  60 if (_listenerList == null)
 70  20 return;
 71   
 72  40 Iterator i = _listenerList.getListeners();
 73   
 74  40 _listenerList = null;
 75   
 76  40 while (i.hasNext())
 77    {
 78  407 RegistryShutdownListener s = (RegistryShutdownListener) i.next();
 79   
 80  407 shutdown(s);
 81    }
 82   
 83  40 _listenerList = null;
 84    }
 85   
 86  407 private void shutdown(RegistryShutdownListener s)
 87    {
 88  407 if (alreadyShutdown == null)
 89    {
 90  40 alreadyShutdown = new HashSet();
 91    }
 92  407 final Long id = new Long(System.identityHashCode(s));
 93  407 if (!alreadyShutdown.contains(id))
 94    {
 95  402 try
 96    {
 97  402 s.registryDidShutdown();
 98    }
 99    catch (RuntimeException ex)
 100    {
 101  1 _log.error(ImplMessages.shutdownCoordinatorFailure(s, ex), ex);
 102    }
 103    finally
 104    {
 105  402 alreadyShutdown.add(id);
 106    }
 107    }
 108    }
 109   
 110    }