1// 2// ======================================================================== 3// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. 4// ------------------------------------------------------------------------ 5// All rights reserved. This program and the accompanying materials 6// are made available under the terms of the Eclipse Public License v1.0 7// and Apache License v2.0 which accompanies this distribution. 8// 9// The Eclipse Public License is available at 10// http://www.eclipse.org/legal/epl-v10.html 11// 12// The Apache License v2.0 is available at 13// http://www.opensource.org/licenses/apache2.0.php 14// 15// You may elect to redistribute this code under either of these licenses. 16// ======================================================================== 17// 18 19package org.eclipse.jetty.util.component; 20 21import java.util.EventListener; 22 23/* ------------------------------------------------------------ */ 24/** 25 * The lifecycle interface for generic components. 26 * <br /> 27 * Classes implementing this interface have a defined life cycle 28 * defined by the methods of this interface. 29 * 30 * 31 */ 32public interface LifeCycle 33{ 34 /* ------------------------------------------------------------ */ 35 /** 36 * Starts the component. 37 * @throws Exception If the component fails to start 38 * @see #isStarted() 39 * @see #stop() 40 * @see #isFailed() 41 */ 42 public void start() 43 throws Exception; 44 45 /* ------------------------------------------------------------ */ 46 /** 47 * Stops the component. 48 * The component may wait for current activities to complete 49 * normally, but it can be interrupted. 50 * @exception Exception If the component fails to stop 51 * @see #isStopped() 52 * @see #start() 53 * @see #isFailed() 54 */ 55 public void stop() 56 throws Exception; 57 58 /* ------------------------------------------------------------ */ 59 /** 60 * @return true if the component is starting or has been started. 61 */ 62 public boolean isRunning(); 63 64 /* ------------------------------------------------------------ */ 65 /** 66 * @return true if the component has been started. 67 * @see #start() 68 * @see #isStarting() 69 */ 70 public boolean isStarted(); 71 72 /* ------------------------------------------------------------ */ 73 /** 74 * @return true if the component is starting. 75 * @see #isStarted() 76 */ 77 public boolean isStarting(); 78 79 /* ------------------------------------------------------------ */ 80 /** 81 * @return true if the component is stopping. 82 * @see #isStopped() 83 */ 84 public boolean isStopping(); 85 86 /* ------------------------------------------------------------ */ 87 /** 88 * @return true if the component has been stopped. 89 * @see #stop() 90 * @see #isStopping() 91 */ 92 public boolean isStopped(); 93 94 /* ------------------------------------------------------------ */ 95 /** 96 * @return true if the component has failed to start or has failed to stop. 97 */ 98 public boolean isFailed(); 99 100 /* ------------------------------------------------------------ */ 101 public void addLifeCycleListener(LifeCycle.Listener listener); 102 103 /* ------------------------------------------------------------ */ 104 public void removeLifeCycleListener(LifeCycle.Listener listener); 105 106 107 /* ------------------------------------------------------------ */ 108 /** Listener. 109 * A listener for Lifecycle events. 110 */ 111 public interface Listener extends EventListener 112 { 113 public void lifeCycleStarting(LifeCycle event); 114 public void lifeCycleStarted(LifeCycle event); 115 public void lifeCycleFailure(LifeCycle event,Throwable cause); 116 public void lifeCycleStopping(LifeCycle event); 117 public void lifeCycleStopped(LifeCycle event); 118 } 119} 120