1 // ======================================================================== 2 // Copyright 2004-2005 Mort Bay Consulting Pty. Ltd. 3 // ------------------------------------------------------------------------ 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 // ======================================================================== 14 15 package org.mortbay.component; 16 17 import java.util.EventListener; 18 19 import org.mortbay.util.LazyList; 20 21 /* ------------------------------------------------------------ */ 22 /** 23 * The lifecycle interface for generic components. 24 * <br /> 25 * Classes implementing this interface have a defined life cycle 26 * defined by the methods of this interface. 27 * 28 * @author Greg Wilkins (gregw) 29 */ 30 public interface LifeCycle 31 { 32 /* ------------------------------------------------------------ */ 33 /** 34 * Starts the component. 35 * @throws Exception If the component fails to start 36 * @see #isStarted() 37 * @see #stop() 38 * @see #isFailed() 39 */ 40 public void start() 41 throws Exception; 42 43 /* ------------------------------------------------------------ */ 44 /** 45 * Stops the component. 46 * The component may wait for current activities to complete 47 * normally, but it can be interrupted. 48 * @exception Exception If the component fails to stop 49 * @see #isStopped() 50 * @see #start() 51 * @see #isFailed() 52 */ 53 public void stop() 54 throws Exception; 55 56 /* ------------------------------------------------------------ */ 57 /** 58 * @return true if the component is starting or has been started. 59 */ 60 public boolean isRunning(); 61 62 /* ------------------------------------------------------------ */ 63 /** 64 * @return true if the component has been started. 65 * @see #start() 66 * @see #isStarting() 67 */ 68 public boolean isStarted(); 69 70 /* ------------------------------------------------------------ */ 71 /** 72 * @return true if the component is starting. 73 * @see #isStarted() 74 */ 75 public boolean isStarting(); 76 77 /* ------------------------------------------------------------ */ 78 /** 79 * @return true if the component is stopping. 80 * @see #isStopped() 81 */ 82 public boolean isStopping(); 83 84 /* ------------------------------------------------------------ */ 85 /** 86 * @return true if the component has been stopped. 87 * @see #stop() 88 * @see #isStopping() 89 */ 90 public boolean isStopped(); 91 92 /* ------------------------------------------------------------ */ 93 /** 94 * @return true if the component has failed to start or has failed to stop. 95 */ 96 public boolean isFailed(); 97 98 /* ------------------------------------------------------------ */ 99 public void addLifeCycleListener(LifeCycle.Listener listener); 100 101 /* ------------------------------------------------------------ */ 102 public void removeLifeCycleListener(LifeCycle.Listener listener); 103 104 105 /* ------------------------------------------------------------ */ 106 /** Listener. 107 * A listener for Lifecycle events. 108 */ 109 public interface Listener extends EventListener 110 { 111 public void lifeCycleStarting(LifeCycle event); 112 public void lifeCycleStarted(LifeCycle event); 113 public void lifeCycleFailure(LifeCycle event,Throwable cause); 114 public void lifeCycleStopping(LifeCycle event); 115 public void lifeCycleStopped(LifeCycle event); 116 } 117 }