Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 1 | /* |
Carsten Ziegeler | 3314f91 | 2014-07-30 07:22:32 +0000 | [diff] [blame^] | 2 | * Copyright (c) OSGi Alliance (2002, 2013). All Rights Reserved. |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 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 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.osgi.service.startlevel; |
| 18 | |
| 19 | import org.osgi.framework.Bundle; |
| 20 | |
| 21 | /** |
| 22 | * The StartLevel service allows management agents to manage a start level |
| 23 | * assigned to each bundle and the active start level of the Framework. There is |
| 24 | * at most one StartLevel service present in the OSGi environment. |
| 25 | * |
| 26 | * <p> |
| 27 | * A start level is defined to be a state of execution in which the Framework |
| 28 | * exists. StartLevel values are defined as unsigned integers with 0 (zero) |
| 29 | * being the state where the Framework is not launched. Progressively higher |
| 30 | * integral values represent progressively higher start levels. e.g. 2 is a |
| 31 | * higher start level than 1. |
| 32 | * <p> |
| 33 | * Access to the StartLevel service is protected by corresponding |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 34 | * {@code ServicePermission}. In addition {@code AdminPermission} |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 35 | * is required to actually modify start level information. |
| 36 | * <p> |
| 37 | * Start Level support in the Framework includes the ability to control the |
| 38 | * beginning start level of the Framework, to modify the active start level of |
| 39 | * the Framework and to assign a specific start level to a bundle. How the |
| 40 | * beginning start level of a Framework is specified is implementation |
| 41 | * dependent. It may be a command line argument when invoking the Framework |
| 42 | * implementation. |
| 43 | * <p> |
| 44 | * When the Framework is first started it must be at start level zero. In this |
| 45 | * state, no bundles are running. This is the initial state of the Framework |
| 46 | * before it is launched. |
| 47 | * |
| 48 | * When the Framework is launched, the Framework will enter start level one and |
| 49 | * all bundles which are assigned to start level one and whose autostart setting |
| 50 | * indicates the bundle should be started are started as described in the |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 51 | * {@code Bundle.start} method. The Framework will continue to increase |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 52 | * the start level, starting bundles at each start level, until the Framework |
| 53 | * has reached a beginning start level. At this point the Framework has |
| 54 | * completed starting bundles and will then fire a Framework event of type |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 55 | * {@code FrameworkEvent.STARTED} to announce it has completed its |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 56 | * launch. |
| 57 | * |
| 58 | * <p> |
| 59 | * Within a start level, bundles may be started in an order defined by the |
| 60 | * Framework implementation. This may be something like ascending |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 61 | * {@code Bundle.getBundleId} order or an order based upon dependencies |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 62 | * between bundles. A similar but reversed order may be used when stopping |
| 63 | * bundles within a start level. |
| 64 | * |
| 65 | * <p> |
| 66 | * The StartLevel service can be used by management bundles to alter the active |
| 67 | * start level of the framework. |
| 68 | * |
| 69 | * @ThreadSafe |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 70 | * @noimplement |
Carsten Ziegeler | 3314f91 | 2014-07-30 07:22:32 +0000 | [diff] [blame^] | 71 | * @author $Id: 42f3c6bbf682a69ea3914c737d5b0001694383db $ |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 72 | * @deprecated This service has been replaced by the |
| 73 | * <code>org.osgi.framework.startlevel</code> package. |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 74 | */ |
| 75 | public interface StartLevel { |
| 76 | /** |
| 77 | * Return the active start level value of the Framework. |
| 78 | * |
| 79 | * If the Framework is in the process of changing the start level this |
| 80 | * method must return the active start level if this differs from the |
| 81 | * requested start level. |
| 82 | * |
| 83 | * @return The active start level value of the Framework. |
| 84 | */ |
| 85 | public int getStartLevel(); |
| 86 | |
| 87 | /** |
| 88 | * Modify the active start level of the Framework. |
| 89 | * |
| 90 | * <p> |
| 91 | * The Framework will move to the requested start level. This method will |
| 92 | * return immediately to the caller and the start level change will occur |
| 93 | * asynchronously on another thread. |
| 94 | * |
| 95 | * <p> |
| 96 | * If the specified start level is higher than the active start level, the |
| 97 | * Framework will continue to increase the start level until the Framework |
| 98 | * has reached the specified start level. |
| 99 | * |
| 100 | * At each intermediate start level value on the way to and including the |
| 101 | * target start level, the Framework must: |
| 102 | * <ol> |
Carsten Ziegeler | 3314f91 | 2014-07-30 07:22:32 +0000 | [diff] [blame^] | 103 | * <li>Change the active start level to the intermediate start level value.</li> |
| 104 | * <li>Start bundles at the intermediate start level whose autostart setting |
| 105 | * indicate they must be started. They are started as described in the |
| 106 | * {@link Bundle#start(int)} method using the {@link Bundle#START_TRANSIENT} |
| 107 | * option. The {@link Bundle#START_ACTIVATION_POLICY} option must also be |
| 108 | * used if {@link #isBundleActivationPolicyUsed(Bundle)} returns |
| 109 | * {@code true} for the bundle.</li> |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 110 | * </ol> |
| 111 | * When this process completes after the specified start level is reached, |
| 112 | * the Framework will fire a Framework event of type |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 113 | * {@code FrameworkEvent.STARTLEVEL_CHANGED} to announce it has moved |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 114 | * to the specified start level. |
| 115 | * |
| 116 | * <p> |
| 117 | * If the specified start level is lower than the active start level, the |
| 118 | * Framework will continue to decrease the start level until the Framework |
| 119 | * has reached the specified start level. |
| 120 | * |
| 121 | * At each intermediate start level value on the way to and including the |
| 122 | * specified start level, the framework must: |
| 123 | * <ol> |
| 124 | * <li>Stop bundles at the intermediate start level as described in the |
| 125 | * {@link Bundle#stop(int)} method using the {@link Bundle#STOP_TRANSIENT} |
Carsten Ziegeler | 3314f91 | 2014-07-30 07:22:32 +0000 | [diff] [blame^] | 126 | * option.</li> |
| 127 | * <li>Change the active start level to the intermediate start level value.</li> |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 128 | * </ol> |
| 129 | * When this process completes after the specified start level is reached, |
| 130 | * the Framework will fire a Framework event of type |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 131 | * {@code FrameworkEvent.STARTLEVEL_CHANGED} to announce it has moved |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 132 | * to the specified start level. |
| 133 | * |
| 134 | * <p> |
| 135 | * If the specified start level is equal to the active start level, then no |
| 136 | * bundles are started or stopped, however, the Framework must fire a |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 137 | * Framework event of type {@code FrameworkEvent.STARTLEVEL_CHANGED} |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 138 | * to announce it has finished moving to the specified start level. This |
| 139 | * event may arrive before this method return. |
| 140 | * |
| 141 | * @param startlevel The requested start level for the Framework. |
| 142 | * @throws IllegalArgumentException If the specified start level is less |
| 143 | * than or equal to zero. |
| 144 | * @throws SecurityException If the caller does not have |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 145 | * {@code AdminPermission[System Bundle,STARTLEVEL]} and the |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 146 | * Java runtime environment supports permissions. |
| 147 | */ |
| 148 | public void setStartLevel(int startlevel); |
| 149 | |
| 150 | /** |
| 151 | * Return the assigned start level value for the specified Bundle. |
| 152 | * |
| 153 | * @param bundle The target bundle. |
| 154 | * @return The start level value of the specified Bundle. |
| 155 | * @throws java.lang.IllegalArgumentException If the specified bundle has |
| 156 | * been uninstalled or if the specified bundle was not created by |
| 157 | * the same framework instance that registered this |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 158 | * {@code StartLevel} service. |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 159 | */ |
| 160 | public int getBundleStartLevel(Bundle bundle); |
| 161 | |
| 162 | /** |
| 163 | * Assign a start level value to the specified Bundle. |
| 164 | * |
| 165 | * <p> |
| 166 | * The specified bundle will be assigned the specified start level. The |
| 167 | * start level value assigned to the bundle will be persistently recorded by |
| 168 | * the Framework. |
| 169 | * <p> |
| 170 | * If the new start level for the bundle is lower than or equal to the |
| 171 | * active start level of the Framework and the bundle's autostart setting |
| 172 | * indicates the bundle must be started, the Framework will start the |
| 173 | * specified bundle as described in the {@link Bundle#start(int)} method |
| 174 | * using the {@link Bundle#START_TRANSIENT} option. The |
| 175 | * {@link Bundle#START_ACTIVATION_POLICY} option must also be used if |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 176 | * {@link #isBundleActivationPolicyUsed(Bundle)} returns {@code true} |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 177 | * for the bundle. The actual starting of this bundle must occur |
| 178 | * asynchronously. |
| 179 | * <p> |
| 180 | * If the new start level for the bundle is higher than the active start |
| 181 | * level of the Framework, the Framework will stop the specified bundle as |
| 182 | * described in the {@link Bundle#stop(int)} method using the |
| 183 | * {@link Bundle#STOP_TRANSIENT} option. The actual stopping of this bundle |
| 184 | * must occur asynchronously. |
| 185 | * |
| 186 | * @param bundle The target bundle. |
| 187 | * @param startlevel The new start level for the specified Bundle. |
| 188 | * @throws IllegalArgumentException If the specified bundle has been |
| 189 | * uninstalled, or if the specified start level is less than or |
| 190 | * equal to zero, or if the specified bundle is the system bundle, |
| 191 | * or if the specified bundle was not created by the same framework |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 192 | * instance that registered this {@code StartLevel} service. |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 193 | * @throws SecurityException If the caller does not have |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 194 | * {@code AdminPermission[bundle,EXECUTE]} and the Java runtime |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 195 | * environment supports permissions. |
| 196 | */ |
| 197 | public void setBundleStartLevel(Bundle bundle, int startlevel); |
| 198 | |
| 199 | /** |
| 200 | * Return the initial start level value that is assigned to a Bundle when it |
| 201 | * is first installed. |
| 202 | * |
| 203 | * @return The initial start level value for Bundles. |
Richard S. Hall | dfd78a4 | 2012-05-11 20:19:02 +0000 | [diff] [blame] | 204 | * @see #setInitialBundleStartLevel(int) |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 205 | */ |
| 206 | public int getInitialBundleStartLevel(); |
| 207 | |
| 208 | /** |
| 209 | * Set the initial start level value that is assigned to a Bundle when it is |
| 210 | * first installed. |
| 211 | * |
| 212 | * <p> |
| 213 | * The initial bundle start level will be set to the specified start level. |
| 214 | * The initial bundle start level value will be persistently recorded by the |
| 215 | * Framework. |
| 216 | * |
| 217 | * <p> |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 218 | * When a Bundle is installed via {@code BundleContext.installBundle}, |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 219 | * it is assigned the initial bundle start level value. |
| 220 | * |
| 221 | * <p> |
| 222 | * The default initial bundle start level value is 1 unless this method has |
| 223 | * been called to assign a different initial bundle start level value. |
| 224 | * |
| 225 | * <p> |
| 226 | * This method does not change the start level values of installed bundles. |
| 227 | * |
| 228 | * @param startlevel The initial start level for newly installed bundles. |
| 229 | * @throws IllegalArgumentException If the specified start level is less |
| 230 | * than or equal to zero. |
| 231 | * @throws SecurityException If the caller does not have |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 232 | * {@code AdminPermission[System Bundle,STARTLEVEL]} and the |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 233 | * Java runtime environment supports permissions. |
| 234 | */ |
| 235 | public void setInitialBundleStartLevel(int startlevel); |
| 236 | |
| 237 | /** |
| 238 | * Returns whether the specified bundle's autostart setting indicates the |
| 239 | * bundle must be started. |
| 240 | * <p> |
| 241 | * The autostart setting of a bundle indicates whether the bundle is to be |
| 242 | * started when its start level is reached. |
| 243 | * |
| 244 | * @param bundle The bundle whose autostart setting is to be examined. |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 245 | * @return {@code true} if the autostart setting of the bundle |
| 246 | * indicates the bundle is to be started. {@code false} |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 247 | * otherwise. |
| 248 | * @throws java.lang.IllegalArgumentException If the specified bundle has |
| 249 | * been uninstalled or if the specified bundle was not created by |
| 250 | * the same framework instance that registered this |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 251 | * {@code StartLevel} service. |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 252 | * @see Bundle#START_TRANSIENT |
| 253 | */ |
| 254 | public boolean isBundlePersistentlyStarted(Bundle bundle); |
| 255 | |
| 256 | /** |
| 257 | * Returns whether the specified bundle's autostart setting indicates that |
| 258 | * the activation policy declared in the bundle's manifest must be used. |
| 259 | * <p> |
| 260 | * The autostart setting of a bundle indicates whether the bundle's declared |
| 261 | * activation policy is to be used when the bundle is started. |
| 262 | * |
| 263 | * @param bundle The bundle whose autostart setting is to be examined. |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 264 | * @return {@code true} if the bundle's autostart setting indicates the |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 265 | * activation policy declared in the manifest must be used. |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 266 | * {@code false} if the bundle must be eagerly activated. |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 267 | * @throws java.lang.IllegalArgumentException If the specified bundle has |
| 268 | * been uninstalled or if the specified bundle was not created by |
| 269 | * the same framework instance that registered this |
Richard S. Hall | d0dca9b | 2011-05-18 14:52:16 +0000 | [diff] [blame] | 270 | * {@code StartLevel} service. |
Richard S. Hall | 2532cf8 | 2010-03-24 09:51:11 +0000 | [diff] [blame] | 271 | * @since 1.1 |
| 272 | * @see Bundle#START_ACTIVATION_POLICY |
| 273 | */ |
| 274 | public boolean isBundleActivationPolicyUsed(Bundle bundle); |
| 275 | } |