blob: 56660b1b9a7505e77fb83c4eb3411abb68d54262 [file] [log] [blame]
Richard S. Hallc88fca32006-10-18 22:01:22 +00001/*
Richard S. Hallf28d6762009-06-08 19:31:06 +00002 * Copyright (c) OSGi Alliance (2000, 2009). All Rights Reserved.
Richard S. Hallc88fca32006-10-18 22:01:22 +00003 *
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
17package org.osgi.framework;
18
19/**
20 * Customizes the starting and stopping of a bundle.
21 * <p>
22 * <code>BundleActivator</code> is an interface that may be implemented when a
23 * bundle is started or stopped. The Framework can create instances of a
24 * bundle's <code>BundleActivator</code> as required. If an instance's
25 * <code>BundleActivator.start</code> method executes successfully, it is
26 * guaranteed that the same instance's <code>BundleActivator.stop</code>
Richard S. Hall53e70d32008-08-01 19:31:32 +000027 * method will be called when the bundle is to be stopped. The Framework must
28 * not concurrently call a <code>BundleActivator</code> object.
Richard S. Hallc88fca32006-10-18 22:01:22 +000029 *
30 * <p>
31 * <code>BundleActivator</code> is specified through the
32 * <code>Bundle-Activator</code> Manifest header. A bundle can only specify a
33 * single <code>BundleActivator</code> in the Manifest file. Fragment bundles
34 * must not have a <code>BundleActivator</code>. The form of the Manifest
35 * header is:
36 *
Richard S. Hall53e70d32008-08-01 19:31:32 +000037 * <p>
38 * <code>Bundle-Activator: <i>class-name</i></code>
Richard S. Hallc88fca32006-10-18 22:01:22 +000039 *
Richard S. Hall53e70d32008-08-01 19:31:32 +000040 * <p>
41 * where <code><i>class-name</i></code> is a fully qualified Java classname.
Richard S. Hallc88fca32006-10-18 22:01:22 +000042 * <p>
43 * The specified <code>BundleActivator</code> class must have a public
44 * constructor that takes no parameters so that a <code>BundleActivator</code>
45 * object can be created by <code>Class.newInstance()</code>.
46 *
Richard S. Hall53e70d32008-08-01 19:31:32 +000047 * @NotThreadSafe
Richard S. Hallf28d6762009-06-08 19:31:06 +000048 * @version $Revision: 6361 $
Richard S. Hallc88fca32006-10-18 22:01:22 +000049 */
50
51public interface BundleActivator {
52 /**
53 * Called when this bundle is started so the Framework can perform the
54 * bundle-specific activities necessary to start this bundle. This method
55 * can be used to register services or to allocate any resources that this
56 * bundle needs.
57 *
58 * <p>
59 * This method must complete and return to its caller in a timely manner.
60 *
61 * @param context The execution context of the bundle being started.
Richard S. Hallf28d6762009-06-08 19:31:06 +000062 * @throws Exception If this method throws an exception, this
Richard S. Hallc88fca32006-10-18 22:01:22 +000063 * bundle is marked as stopped and the Framework will remove this
64 * bundle's listeners, unregister all services registered by this
65 * bundle, and release all services used by this bundle.
Richard S. Hallc88fca32006-10-18 22:01:22 +000066 */
67 public void start(BundleContext context) throws Exception;
68
69 /**
70 * Called when this bundle is stopped so the Framework can perform the
71 * bundle-specific activities necessary to stop the bundle. In general, this
72 * method should undo the work that the <code>BundleActivator.start</code>
73 * method started. There should be no active threads that were started by
74 * this bundle when this bundle returns. A stopped bundle must not call any
75 * Framework objects.
76 *
77 * <p>
78 * This method must complete and return to its caller in a timely manner.
79 *
80 * @param context The execution context of the bundle being stopped.
Richard S. Hallf28d6762009-06-08 19:31:06 +000081 * @throws Exception If this method throws an exception, the
Richard S. Hallc88fca32006-10-18 22:01:22 +000082 * bundle is still marked as stopped, and the Framework will remove
83 * the bundle's listeners, unregister all services registered by the
84 * bundle, and release all services used by the bundle.
Richard S. Hallc88fca32006-10-18 22:01:22 +000085 */
86 public void stop(BundleContext context) throws Exception;
87}