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  /* ------------------------------------------------------------ */
18  /**
19   * The lifecycle interface for generic components.
20   * <br />
21   * Classes implementing this interface have a defined life cycle
22   * defined by the methods of this interface.
23   *
24   * @author Greg Wilkins (gregw)
25   */
26  public interface LifeCycle
27  {
28      /* ------------------------------------------------------------ */
29      /**
30       * Starts the component.
31       * @throws Exception If the component fails to start
32       * @see #isStarted()
33       * @see #stop()
34       * @see #isFailed()
35       */
36      public void start()
37          throws Exception;
38  
39      /* ------------------------------------------------------------ */
40      /**
41       * Stops the component.
42       * The component may wait for current activities to complete
43       * normally, but it can be interrupted.
44       * @exception Exception If the component fails to stop
45       * @see #isStopped()
46       * @see #start()
47       * @see #isFailed()
48       */
49      public void stop()
50          throws Exception;
51  
52      /* ------------------------------------------------------------ */
53      /**
54       * @return true if the component is starting or has been started.
55       */
56      public boolean isRunning();
57  
58      /* ------------------------------------------------------------ */
59      /**
60       * @return true if the component has been started.
61       * @see #start()
62       * @see #isStarting()
63       */
64      public boolean isStarted();
65  
66      /* ------------------------------------------------------------ */
67      /**
68       * @return true if the component is starting.
69       * @see #isStarted()
70       */
71      public boolean isStarting();
72  
73      /* ------------------------------------------------------------ */
74      /**
75       * @return true if the component is stopping.
76       * @see #isStopped()
77       */
78      public boolean isStopping();
79  
80      /* ------------------------------------------------------------ */
81      /**
82       * @return true if the component has been stopped.
83       * @see #stop()
84       * @see #isStopping()
85       */
86      public boolean isStopped();
87  
88      /* ------------------------------------------------------------ */
89      /**
90       * @return true if the component has failed to start or has failed to stop.
91       */
92      public boolean isFailed();
93  }