1 /* 2 * Copyright (c) OSGi Alliance (2000, 2013). All Rights Reserved. 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.framework; 18 19 import org.osgi.annotation.versioning.ConsumerType; 20 21 /** 22 * Customizes the starting and stopping of a bundle. 23 * <p> 24 * {@code BundleActivator} is an interface that may be implemented when a bundle 25 * is started or stopped. The Framework can create instances of a bundle's 26 * {@code BundleActivator} as required. If an instance's 27 * {@code BundleActivator.start} method executes successfully, it is guaranteed 28 * that the same instance's {@code BundleActivator.stop} method will be called 29 * when the bundle is to be stopped. The Framework must not concurrently call a 30 * {@code BundleActivator} object. 31 * 32 * <p> 33 * {@code BundleActivator} is specified through the {@code Bundle-Activator} 34 * Manifest header. A bundle can only specify a single {@code BundleActivator} 35 * in the Manifest file. Fragment bundles must not have a 36 * {@code BundleActivator}. The form of the Manifest header is: 37 * 38 * <p> 39 * {@code Bundle-Activator:} <i>class-name</i> 40 * 41 * <p> 42 * where <i>class-name</i> is a fully qualified Java classname. 43 * <p> 44 * The specified {@code BundleActivator} class must have a public constructor 45 * that takes no parameters so that a {@code BundleActivator} object can be 46 * created by {@code Class.newInstance()}. 47 * 48 * @NotThreadSafe 49 * @author $Id: a9d91a8ae13157f49a6a55b0c7f25b63b6bd00bd $ 50 */ 51 @ConsumerType 52 public interface BundleActivator { 53 /** 54 * Called when this bundle is started so the Framework can perform the 55 * bundle-specific activities necessary to start this bundle. This method 56 * can be used to register services or to allocate any resources that this 57 * bundle needs. 58 * 59 * <p> 60 * This method must complete and return to its caller in a timely manner. 61 * 62 * @param context The execution context of the bundle being started. 63 * @throws Exception If this method throws an exception, this bundle is 64 * marked as stopped and the Framework will remove this bundle's 65 * listeners, unregister all services registered by this bundle, and 66 * release all services used by this bundle. 67 */ start(BundleContext context)68 public void start(BundleContext context) throws Exception; 69 70 /** 71 * Called when this bundle is stopped so the Framework can perform the 72 * bundle-specific activities necessary to stop the bundle. In general, this 73 * method should undo the work that the {@code BundleActivator.start} method 74 * started. There should be no active threads that were started by this 75 * bundle when this bundle returns. A stopped bundle must not call any 76 * Framework objects. 77 * 78 * <p> 79 * This method must complete and return to its caller in a timely manner. 80 * 81 * @param context The execution context of the bundle being stopped. 82 * @throws Exception If this method throws an exception, the bundle is still 83 * marked as stopped, and the Framework will remove the bundle's 84 * listeners, unregister all services registered by the bundle, and 85 * release all services used by the bundle. 86 */ stop(BundleContext context)87 public void stop(BundleContext context) throws Exception; 88 } 89