| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.lifecycle; |
| 20 | |
| 21 | import javax.annotation.PostConstruct; |
| 22 | import javax.annotation.PreDestroy; |
| 23 | |
| 24 | /** |
| 25 | * // TODO: Adrian: Document this! |
| 26 | * |
| 27 | * @author Adrian Cole |
| 28 | */ |
| 29 | public interface LifeCycle { |
| 30 | |
| 31 | /** |
| 32 | * @return the current state of the component; |
| 33 | */ |
| 34 | Status getStatus(); |
| 35 | |
| 36 | /** |
| 37 | * @return Exception or null, if there are no fatal Exceptions encountered in the lifecycle of this component. |
| 38 | */ |
| 39 | Exception getException(); |
| 40 | |
| 41 | /** |
| 42 | * Asynchronously starts the component |
| 43 | */ |
| 44 | @PostConstruct |
| 45 | void start(); |
| 46 | |
| 47 | /** |
| 48 | * Requests shutdown of the component. |
| 49 | */ |
| 50 | @PreDestroy |
| 51 | void shutdown(); |
| 52 | |
| 53 | /** |
| 54 | * Requests shutdown, but will only wait @link waitms milliseconds |
| 55 | * |
| 56 | * @param waitMs maximum time to wait in milliseconds |
| 57 | */ |
| 58 | void shutdown(long waitMs); |
| 59 | |
| 60 | /** |
| 61 | * States that are possible for a component. |
| 62 | */ |
| 63 | public static enum Status { |
| 64 | |
| 65 | /** |
| 66 | * The component is inactive / has not been started |
| 67 | */ |
| 68 | INACTIVE, |
| 69 | |
| 70 | /** |
| 71 | * The component is active / processing I/O events. |
| 72 | */ |
| 73 | ACTIVE, |
| 74 | |
| 75 | /** |
| 76 | * Shutdown of the component has been requested. |
| 77 | */ |
| 78 | SHUTDOWN_REQUEST, |
| 79 | |
| 80 | /** |
| 81 | * The component is shutting down. |
| 82 | */ |
| 83 | SHUTTING_DOWN, |
| 84 | |
| 85 | /** |
| 86 | * The component has shut down. |
| 87 | */ |
| 88 | SHUT_DOWN; |
| 89 | } |
| 90 | } |