Coverage Report - org.apache.camel.impl.ServiceSupport
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceSupport
100% 
100% 
1.286
 
 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.impl;
 19  
 
 20  
 import java.util.concurrent.atomic.AtomicBoolean;
 21  
 
 22  
 import org.apache.camel.Service;
 23  
 
 24  
 /**
 25  
  * A useful base class which ensures that a service is only initialized once and provides some helper methods for
 26  
  * enquiring of its status
 27  
  * 
 28  
  * @version $Revision: 534063 $
 29  
  */
 30  642
 public abstract class ServiceSupport implements Service {
 31  642
     private AtomicBoolean started = new AtomicBoolean(false);
 32  642
     private AtomicBoolean stopping = new AtomicBoolean(false);
 33  642
     private AtomicBoolean stopped = new AtomicBoolean(false);
 34  
 
 35  
     public void start() throws Exception {
 36  383
         if (started.compareAndSet(false, true)) {
 37  339
             doStart();
 38  
         }
 39  383
     }
 40  
 
 41  
     public void stop() throws Exception {
 42  522
         if (stopped.compareAndSet(false, true)) {
 43  479
             stopping.set(true);
 44  
             try {
 45  479
                 doStop();
 46  
             }
 47  
             finally {
 48  479
                 stopped.set(true);
 49  479
                 started.set(false);
 50  479
                 stopping.set(false);
 51  479
             }
 52  
         }
 53  522
     }
 54  
 
 55  
     /**
 56  
      * @return true if this service has been started
 57  
      */
 58  
     public boolean isStarted() {
 59  103
         return started.get();
 60  
     }
 61  
 
 62  
     /**
 63  
      * @return true if this service is in the process of closing
 64  
      */
 65  
     public boolean isStopping() {
 66  10
         return stopping.get();
 67  
     }
 68  
 
 69  
 
 70  
     /**
 71  
      * @return true if this service is closed
 72  
      */
 73  
     public boolean isStopped() {
 74  3
         return stopped.get();
 75  
     }
 76  
 
 77  
     protected abstract void doStart() throws Exception;
 78  
     
 79  
     protected abstract void doStop() throws Exception;
 80  
 
 81  
 }