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