View Javadoc

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