2 // ========================================================================
3 // Copyright (c) 1995-2016 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.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util.component;
21 import java.util.EventListener;
23 import org.eclipse.jetty.util.annotation.ManagedObject;
24 import org.eclipse.jetty.util.annotation.ManagedOperation;
26 /* ------------------------------------------------------------ */
28 * The lifecycle interface for generic components.
30 * Classes implementing this interface have a defined life cycle
31 * defined by the methods of this interface.
35 @ManagedObject("Lifecycle Interface for startable components")
36 public interface LifeCycle
38 /* ------------------------------------------------------------ */
40 * Starts the component.
41 * @throws Exception If the component fails to start
46 @ManagedOperation(value="Starts the instance", impact="ACTION")
50 /* ------------------------------------------------------------ */
52 * Stops the component.
53 * The component may wait for current activities to complete
54 * normally, but it can be interrupted.
55 * @exception Exception If the component fails to stop
60 @ManagedOperation(value="Stops the instance", impact="ACTION")
64 /* ------------------------------------------------------------ */
66 * @return true if the component is starting or has been started.
68 public boolean isRunning();
70 /* ------------------------------------------------------------ */
72 * @return true if the component has been started.
76 public boolean isStarted();
78 /* ------------------------------------------------------------ */
80 * @return true if the component is starting.
83 public boolean isStarting();
85 /* ------------------------------------------------------------ */
87 * @return true if the component is stopping.
90 public boolean isStopping();
92 /* ------------------------------------------------------------ */
94 * @return true if the component has been stopped.
98 public boolean isStopped();
100 /* ------------------------------------------------------------ */
102 * @return true if the component has failed to start or has failed to stop.
104 public boolean isFailed();
106 /* ------------------------------------------------------------ */
107 public void addLifeCycleListener(LifeCycle.Listener listener);
109 /* ------------------------------------------------------------ */
110 public void removeLifeCycleListener(LifeCycle.Listener listener);
113 /* ------------------------------------------------------------ */
115 * A listener for Lifecycle events.
117 public interface Listener extends EventListener
119 public void lifeCycleStarting(LifeCycle event);
120 public void lifeCycleStarted(LifeCycle event);
121 public void lifeCycleFailure(LifeCycle event,Throwable cause);
122 public void lifeCycleStopping(LifeCycle event);
123 public void lifeCycleStopped(LifeCycle event);