| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 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 | } |