Skip to main content
summaryrefslogtreecommitdiffstats
blob: 70dc5da1a8cf1ebdb1c0fdcb2d44ed8a007754e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
 * Copyright (c) OSGi Alliance (2008, 2011). All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.osgi.framework.launch;

import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkEvent;

/**
 * A Framework instance. A Framework is also known as a System Bundle.
 * 
 * <p>
 * Framework instances are created using a {@link FrameworkFactory}. The methods
 * of this interface can be used to manage and control the created framework
 * instance.
 * 
 * @ThreadSafe
 * @noimplement
 * @version $Id: ae7fc29f8f5df58e9ed588d3d9e5ce7ebdc16ac5 $
 */
public interface Framework extends Bundle {

	/**
	 * Initialize this Framework. After calling this method, this Framework
	 * must:
	 * <ul>
	 * <li>Have generated a new {@link Constants#FRAMEWORK_UUID framework UUID}.
	 * </li>
	 * <li>Be in the {@link #STARTING} state.</li>
	 * <li>Have a valid Bundle Context.</li>
	 * <li>Be at start level 0.</li>
	 * <li>Have event handling enabled.</li>
	 * <li>Have reified Bundle objects for all installed bundles.</li>
	 * <li>Have registered any framework services. For example,
	 * {@code ConditionalPermissionAdmin}.</li>
	 * <li>Be {@link #adapt(Class) adaptable} to the OSGi defined types to which
	 * a system bundle can be adapted.</li>
	 * </ul>
	 * 
	 * <p>
	 * This Framework will not actually be started until {@link #start() start}
	 * is called.
	 * 
	 * <p>
	 * This method does nothing if called when this Framework is in the
	 * {@link #STARTING}, {@link #ACTIVE} or {@link #STOPPING} states.
	 * 
	 * @throws BundleException If this Framework could not be initialized.
	 * @throws SecurityException If the Java Runtime Environment supports
	 *         permissions and the caller does not have the appropriate
	 *         {@code AdminPermission[this,EXECUTE]} or if there is a security
	 *         manager already installed and the
	 *         {@link Constants#FRAMEWORK_SECURITY} configuration property is
	 *         set.
	 * 
	 */
	void init() throws BundleException;

	/**
	 * Wait until this Framework has completely stopped. The {@code stop}
	 * and {@code update} methods on a Framework performs an asynchronous
	 * stop of the Framework. This method can be used to wait until the
	 * asynchronous stop of this Framework has completed. This method will only
	 * wait if called when this Framework is in the {@link #STARTING},
	 * {@link #ACTIVE}, or {@link #STOPPING} states. Otherwise it will return
	 * immediately.
	 * <p>
	 * A Framework Event is returned to indicate why this Framework has stopped.
	 * 
	 * @param timeout Maximum number of milliseconds to wait until this
	 *        Framework has completely stopped. A value of zero will wait
	 *        indefinitely.
	 * @return A Framework Event indicating the reason this method returned. The
	 *         following {@code FrameworkEvent} types may be returned by
	 *         this method.
	 *         <ul>
	 *         <li>{@link FrameworkEvent#STOPPED STOPPED} - This Framework has
	 *         been stopped. </li>
	 * 
	 *         <li>{@link FrameworkEvent#STOPPED_UPDATE STOPPED_UPDATE} - This
	 *         Framework has been updated which has shutdown and will now
	 *         restart.</li>
	 * 
	 *         <li> {@link FrameworkEvent#STOPPED_BOOTCLASSPATH_MODIFIED
	 *         STOPPED_BOOTCLASSPATH_MODIFIED} - This Framework has been stopped
	 *         and a bootclasspath extension bundle has been installed or
	 *         updated. The VM must be restarted in order for the changed boot
	 *         class path to take effect. </li>
	 * 
	 *         <li>{@link FrameworkEvent#ERROR ERROR} - The Framework
	 *         encountered an error while shutting down or an error has occurred
	 *         which forced the framework to shutdown. </li>
	 * 
	 *         <li> {@link FrameworkEvent#WAIT_TIMEDOUT WAIT_TIMEDOUT} - This
	 *         method has timed out and returned before this Framework has
	 *         stopped.</li>
	 *         </ul>
	 * @throws InterruptedException If another thread interrupted the current
	 *         thread before or while the current thread was waiting for this
	 *         Framework to completely stop. The <i>interrupted status</i> of
	 *         the current thread is cleared when this exception is thrown.
	 * @throws IllegalArgumentException If the value of timeout is negative.
	 */
	FrameworkEvent waitForStop(long timeout) throws InterruptedException;

	/**
	 * Start this Framework.
	 * 
	 * <p>
	 * The following steps are taken to start this Framework:
	 * <ol>
	 * <li>If this Framework is not in the {@link #STARTING} state,
	 * {@link #init() initialize} this Framework.</li>
	 * <li>All installed bundles must be started in accordance with each
	 * bundle's persistent <i>autostart setting</i>. This means some bundles
	 * will not be started, some will be started with <i>eager activation</i>
	 * and some will be started with their <i>declared activation</i> policy.
	 * The start level of this Framework is moved to the start level specified
	 * by the {@link Constants#FRAMEWORK_BEGINNING_STARTLEVEL beginning start
	 * level} framework property, as described in the <i>Start Level
	 * Specification</i>. If this framework property is not specified, then the
	 * start level of this Framework is moved to start level one (1). Any
	 * exceptions that occur during bundle starting must be wrapped in a
	 * {@link BundleException} and then published as a framework event of type
	 * {@link FrameworkEvent#ERROR}</li>
	 * <li>This Framework's state is set to {@link #ACTIVE}.</li>
	 * <li>A framework event of type {@link FrameworkEvent#STARTED} is fired</li>
	 * </ol>
	 * 
	 * @throws BundleException If this Framework could not be started.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
	 *         Environment supports permissions.
	 * @see "Start Level Specification"
	 */
	void start() throws BundleException;

	/**
	 * Start this Framework.
	 * 
	 * <p>
	 * Calling this method is the same as calling {@link #start()}. There are no
	 * start options for the Framework.
	 * 
	 * @param options Ignored. There are no start options for the Framework.
	 * @throws BundleException If this Framework could not be started.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
	 *         Environment supports permissions.
	 * @see #start()
	 */
	void start(int options) throws BundleException;

	/**
	 * Stop this Framework.
	 * 
	 * <p>
	 * The method returns immediately to the caller after initiating the
	 * following steps to be taken on another thread.
	 * <ol>
	 * <li>This Framework's state is set to {@link #STOPPING}.</li>
	 * <li>All installed bundles must be stopped without changing each bundle's
	 * persistent <i>autostart setting</i>. The start level of this Framework is
	 * moved to start level zero (0), as described in the <i>Start Level
	 * Specification</i>. Any exceptions that occur during bundle stopping must
	 * be wrapped in a {@link BundleException} and then published as a framework
	 * event of type {@link FrameworkEvent#ERROR}</li>
	 * <li>Unregister all services registered by this Framework.</li>
	 * <li>Event handling is disabled.</li>
	 * <li>This Framework's state is set to {@link #RESOLVED}.</li>
	 * <li>All resources held by this Framework are released. This includes
	 * threads, bundle class loaders, open files, etc.</li>
	 * <li>Notify all threads that are waiting at {@link #waitForStop(long)
	 * waitForStop} that the stop operation has completed.</li>
	 * </ol>
	 * <p>
	 * After being stopped, this Framework may be discarded, initialized or
	 * started.
	 * 
	 * @throws BundleException If stopping this Framework could not be
	 *         initiated.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
	 *         Environment supports permissions.
	 * @see "Start Level Specification"
	 */
	void stop() throws BundleException;

	/**
	 * Stop this Framework.
	 * 
	 * <p>
	 * Calling this method is the same as calling {@link #stop()}. There are no
	 * stop options for the Framework.
	 * 
	 * @param options Ignored. There are no stop options for the Framework.
	 * @throws BundleException If stopping this Framework could not be
	 *         initiated.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
	 *         Environment supports permissions.
	 * @see #stop()
	 */
	void stop(int options) throws BundleException;

	/**
	 * The Framework cannot be uninstalled.
	 * 
	 * <p>
	 * This method always throws a BundleException.
	 * 
	 * @throws BundleException This Framework cannot be uninstalled.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,LIFECYCLE]}, and the Java
	 *         Runtime Environment supports permissions.
	 */
	void uninstall() throws BundleException;

	/**
	 * Stop and restart this Framework.
	 * 
	 * <p>
	 * The method returns immediately to the caller after initiating the
	 * following steps to be taken on another thread.
	 * <ol>
	 * <li>Perform the steps in the {@link #stop()} method to stop this
	 * Framework.</li>
	 * <li>Perform the steps in the {@link #start()} method to start this
	 * Framework.</li>
	 * </ol>
	 * 
	 * @throws BundleException If stopping and restarting this Framework could
	 *         not be initiated.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,LIFECYCLE]}, and the Java
	 *         Runtime Environment supports permissions.
	 */
	void update() throws BundleException;

	/**
	 * Stop and restart this Framework.
	 * 
	 * <p>
	 * Calling this method is the same as calling {@link #update()} except that
	 * any provided InputStream is immediately closed.
	 * 
	 * @param in Any provided InputStream is immediately closed before returning
	 *        from this method and otherwise ignored.
	 * @throws BundleException If stopping and restarting this Framework could
	 *         not be initiated.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,LIFECYCLE]}, and the Java
	 *         Runtime Environment supports permissions.
	 */
	void update(InputStream in) throws BundleException;

	/**
	 * Returns the Framework unique identifier. This Framework is assigned the
	 * unique identifier zero (0) since this Framework is also a System Bundle.
	 * 
	 * @return 0.
	 * @see Bundle#getBundleId()
	 */
	long getBundleId();

	/**
	 * Returns the Framework location identifier. This Framework is assigned the
	 * unique location &quot;{@code System Bundle}&quot; since this
	 * Framework is also a System Bundle.
	 * 
	 * @return The string &quot;{@code System Bundle}&quot;.
	 * @throws SecurityException If the caller does not have the appropriate
	 *         {@code AdminPermission[this,METADATA]}, and the Java Runtime
	 *         Environment supports permissions.
	 * @see Bundle#getLocation()
	 * @see Constants#SYSTEM_BUNDLE_LOCATION
	 */
	String getLocation();

	/**
	 * Returns the symbolic name of this Framework. The symbolic name is unique
	 * for the implementation of the framework. However, the symbolic name
	 * &quot;{@code system.bundle}&quot; must be recognized as an alias to
	 * the implementation-defined symbolic name since this Framework is also a
	 * System Bundle.
	 * 
	 * @return The symbolic name of this Framework.
	 * @see Bundle#getSymbolicName()
	 * @see Constants#SYSTEM_BUNDLE_SYMBOLICNAME
	 */
	String getSymbolicName();

	/**
	 * Returns {@code null} as a framework implementation does not have a
	 * proper bundle from which to return entry paths.
	 * 
	 * @param path Ignored.
	 * @return {@code null} as a framework implementation does not have a
	 *         proper bundle from which to return entry paths.
	 */
	Enumeration<String> getEntryPaths(String path);

	/**
	 * Returns {@code null} as a framework implementation does not have a
	 * proper bundle from which to return an entry.
	 * 
	 * @param path Ignored.
	 * @return {@code null} as a framework implementation does not have a
	 *         proper bundle from which to return an entry.
	 */
	URL getEntry(String path);

	/**
	 * Returns {@code null} as a framework implementation does not have a proper
	 * bundle from which to return entries.
	 * 
	 * @param path Ignored.
	 * @param filePattern Ignored.
	 * @param recurse Ignored.
	 * @return {@code null} as a framework implementation does not have a proper
	 *         bundle from which to return entries.
	 */
	Enumeration<URL> findEntries(String path, String filePattern,
			boolean recurse);

	/**
	 * Adapt this Framework to the specified type.
	 * 
	 * <p>
	 * Adapting this Framework to the specified type may require certain checks,
	 * including security checks, to succeed. If a check does not succeed, then
	 * this Framework cannot be adapted and {@code null} is returned. If this
	 * Framework is not {@link #init() initialized}, then {@code null} is
	 * returned if the specified type is one of the OSGi defined types to which
	 * a system bundle can be adapted.
	 * 
	 * @param <A> The type to which this Framework is to be adapted.
	 * @param type Class object for the type to which this Framework is to be
	 *        adapted.
	 * @return The object, of the specified type, to which this Framework has
	 *         been adapted or {@code null} if this Framework cannot be adapted
	 */
	<A> A adapt(Class<A> type);
}

Back to the top