View Javadoc

1   //
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.
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  
19  package org.eclipse.jetty.util.component;
20  
21  import java.util.EventListener;
22  
23  import org.eclipse.jetty.util.annotation.ManagedObject;
24  import org.eclipse.jetty.util.annotation.ManagedOperation;
25  
26  /* ------------------------------------------------------------ */
27  /**
28   * The lifecycle interface for generic components.
29   * <br>
30   * Classes implementing this interface have a defined life cycle
31   * defined by the methods of this interface.
32   *
33   * 
34   */
35  @ManagedObject("Lifecycle Interface for startable components")
36  public interface LifeCycle
37  {
38      /* ------------------------------------------------------------ */
39      /**
40       * Starts the component.
41       * @throws Exception If the component fails to start
42       * @see #isStarted()
43       * @see #stop()
44       * @see #isFailed()
45       */
46      @ManagedOperation(value="Starts the instance", impact="ACTION")
47      public void start()
48          throws Exception;
49  
50      /* ------------------------------------------------------------ */
51      /**
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
56       * @see #isStopped()
57       * @see #start()
58       * @see #isFailed()
59       */
60      @ManagedOperation(value="Stops the instance", impact="ACTION")
61      public void stop()
62          throws Exception;
63  
64      /* ------------------------------------------------------------ */
65      /**
66       * @return true if the component is starting or has been started.
67       */
68      public boolean isRunning();
69  
70      /* ------------------------------------------------------------ */
71      /**
72       * @return true if the component has been started.
73       * @see #start()
74       * @see #isStarting()
75       */
76      public boolean isStarted();
77  
78      /* ------------------------------------------------------------ */
79      /**
80       * @return true if the component is starting.
81       * @see #isStarted()
82       */
83      public boolean isStarting();
84  
85      /* ------------------------------------------------------------ */
86      /**
87       * @return true if the component is stopping.
88       * @see #isStopped()
89       */
90      public boolean isStopping();
91  
92      /* ------------------------------------------------------------ */
93      /**
94       * @return true if the component has been stopped.
95       * @see #stop()
96       * @see #isStopping()
97       */
98      public boolean isStopped();
99  
100     /* ------------------------------------------------------------ */
101     /**
102      * @return true if the component has failed to start or has failed to stop.
103      */
104     public boolean isFailed();
105     
106     /* ------------------------------------------------------------ */
107     public void addLifeCycleListener(LifeCycle.Listener listener);
108 
109     /* ------------------------------------------------------------ */
110     public void removeLifeCycleListener(LifeCycle.Listener listener);
111     
112 
113     /* ------------------------------------------------------------ */
114     /** Listener.
115      * A listener for Lifecycle events.
116      */
117     public interface Listener extends EventListener
118     {
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);
124     }
125 }