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 /* ------------------------------------------------------------ */ 20 /** 21 * The lifecycle interface for generic components. 22 * <br /> 23 * Classes implementing this interface have a defined life cycle 24 * defined by the methods of this interface. 25 * 26 * @author Greg Wilkins (gregw) 27 */ 28 public interface LifeCycle 29 { 30 /* ------------------------------------------------------------ */ 31 /** 32 * Starts the component. 33 * @throws Exception If the component fails to start 34 * @see #isStarted() 35 * @see #stop() 36 * @see #isFailed() 37 */ 38 public void start() 39 throws Exception; 40 41 /* ------------------------------------------------------------ */ 42 /** 43 * Stops the component. 44 * The component may wait for current activities to complete 45 * normally, but it can be interrupted. 46 * @exception Exception If the component fails to stop 47 * @see #isStopped() 48 * @see #start() 49 * @see #isFailed() 50 */ 51 public void stop() 52 throws Exception; 53 54 /* ------------------------------------------------------------ */ 55 /** 56 * @return true if the component is starting or has been started. 57 */ 58 public boolean isRunning(); 59 60 /* ------------------------------------------------------------ */ 61 /** 62 * @return true if the component has been started. 63 * @see #start() 64 * @see #isStarting() 65 */ 66 public boolean isStarted(); 67 68 /* ------------------------------------------------------------ */ 69 /** 70 * @return true if the component is starting. 71 * @see #isStarted() 72 */ 73 public boolean isStarting(); 74 75 /* ------------------------------------------------------------ */ 76 /** 77 * @return true if the component is stopping. 78 * @see #isStopped() 79 */ 80 public boolean isStopping(); 81 82 /* ------------------------------------------------------------ */ 83 /** 84 * @return true if the component has been stopped. 85 * @see #stop() 86 * @see #isStopping() 87 */ 88 public boolean isStopped(); 89 90 /* ------------------------------------------------------------ */ 91 /** 92 * @return true if the component has failed to start or has failed to stop. 93 */ 94 public boolean isFailed(); 95 96 /* ------------------------------------------------------------ */ 97 public void addLifeCycleListener(LifeCycle.Listener listener); 98 99 /* ------------------------------------------------------------ */ 100 public void removeLifeCycleListener(LifeCycle.Listener listener); 101 102 103 /* ------------------------------------------------------------ */ 104 /** Listener. 105 * A listener for Lifecycle events. 106 */ 107 public interface Listener extends EventListener 108 { 109 public void lifeCycleStarting(LifeCycle event); 110 public void lifeCycleStarted(LifeCycle event); 111 public void lifeCycleFailure(LifeCycle event,Throwable cause); 112 public void lifeCycleStopping(LifeCycle event); 113 public void lifeCycleStopped(LifeCycle event); 114 } 115 }