Coverage Report - org.apache.camel.util.ServiceHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceHelper
75% 
87% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.util;
 18  
 
 19  
 import java.util.Collection;
 20  
 
 21  
 import org.apache.camel.Service;
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 /**
 26  
  * A collection of helper methods for working with {@link Service} objects
 27  
  * 
 28  
  * @version $Revision: 563607 $
 29  
  */
 30  
 public class ServiceHelper {
 31  3
     private static final transient Log LOG = LogFactory.getLog(ServiceHelper.class);
 32  
     
 33  
     /**
 34  
      * Utility classes should not have a public constructor.
 35  
      */
 36  0
     private ServiceHelper() {        
 37  0
     }
 38  
     
 39  
     public static void startService(Object value) throws Exception {
 40  1860
         if (value instanceof Service) {
 41  1038
             Service service = (Service)value;
 42  1038
             service.start();
 43  1038
         } else if (value instanceof Collection) {
 44  6
             startServices((Collection)value);
 45  
         }
 46  1860
     }
 47  
 
 48  
     /**
 49  
      * Starts all of the given services
 50  
      */
 51  
     public static void startServices(Object... services) throws Exception {
 52  3399
         for (Object value : services) {
 53  1836
             startService(value);
 54  
         }
 55  1563
     }
 56  
 
 57  
     /**
 58  
      * Starts all of the given services
 59  
      */
 60  
     public static void startServices(Collection services) throws Exception {
 61  321
         for (Object value : services) {
 62  609
             if (value instanceof Service) {
 63  597
                 Service service = (Service)value;
 64  597
                 service.start();
 65  
             }
 66  609
         }
 67  321
     }
 68  
 
 69  
     /**
 70  
      * Stops all of the given services, throwing the first exception caught
 71  
      */
 72  
     public static void stopServices(Object... services) throws Exception {
 73  963
         Exception firstException = null;
 74  2196
         for (Object value : services) {
 75  1233
             if (value instanceof Service) {
 76  993
                 Service service = (Service)value;
 77  
                 try {
 78  993
                     service.stop();
 79  0
                 } catch (Exception e) {
 80  0
                     LOG.debug("Caught exception shutting down: " + e, e);
 81  0
                     if (firstException == null) {
 82  0
                         firstException = e;
 83  
                     }
 84  993
                 }
 85  
             }
 86  
         }
 87  963
         if (firstException != null) {
 88  0
             throw firstException;
 89  
         }
 90  963
     }
 91  
 
 92  
     public static void stopService(Object value) throws Exception {
 93  24
         if (value instanceof Service) {
 94  24
             Service service = (Service)value;
 95  24
             service.stop();
 96  24
         } else if (value instanceof Collection) {
 97  0
             stopServices((Collection)value);
 98  
         }
 99  24
     }
 100  
 
 101  
     /**
 102  
      * Stops all of the given services, throwing the first exception caught
 103  
      */
 104  
     public static void stopServices(Collection services) throws Exception {
 105  315
         Exception firstException = null;
 106  315
         for (Object value : services) {
 107  597
             if (value instanceof Service) {
 108  585
                 Service service = (Service)value;
 109  
                 try {
 110  585
                     service.stop();
 111  0
                 } catch (Exception e) {
 112  0
                     LOG.debug("Caught exception shutting down: " + e, e);
 113  0
                     if (firstException == null) {
 114  0
                         firstException = e;
 115  
                     }
 116  585
                 }
 117  
             }
 118  597
         }
 119  315
         if (firstException != null) {
 120  0
             throw firstException;
 121  
         }
 122  315
     }
 123  
 }