Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 2 | * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/BundleActivator.java,v 1.14 2007/02/21 16:49:05 hargrave Exp $ |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 3 | * |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 4 | * Copyright (c) OSGi Alliance (2000, 2007). All Rights Reserved. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | package org.osgi.framework; |
| 20 | |
| 21 | /** |
| 22 | * Customizes the starting and stopping of a bundle. |
| 23 | * <p> |
| 24 | * <code>BundleActivator</code> is an interface that may be implemented when a |
| 25 | * bundle is started or stopped. The Framework can create instances of a |
| 26 | * bundle's <code>BundleActivator</code> as required. If an instance's |
| 27 | * <code>BundleActivator.start</code> method executes successfully, it is |
| 28 | * guaranteed that the same instance's <code>BundleActivator.stop</code> |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 29 | * method will be called when the bundle is to be stopped. The Framework must |
| 30 | * not concurrently call a <code>BundleActivator</code> object. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 31 | * |
| 32 | * <p> |
| 33 | * <code>BundleActivator</code> is specified through the |
| 34 | * <code>Bundle-Activator</code> Manifest header. A bundle can only specify a |
| 35 | * single <code>BundleActivator</code> in the Manifest file. Fragment bundles |
| 36 | * must not have a <code>BundleActivator</code>. The form of the Manifest |
| 37 | * header is: |
| 38 | * |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 39 | * <p> |
| 40 | * <code>Bundle-Activator: <i>class-name</i></code> |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 41 | * |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 42 | * <p> |
| 43 | * where <code><i>class-name</i></code> is a fully qualified Java classname. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 44 | * <p> |
| 45 | * The specified <code>BundleActivator</code> class must have a public |
| 46 | * constructor that takes no parameters so that a <code>BundleActivator</code> |
| 47 | * object can be created by <code>Class.newInstance()</code>. |
| 48 | * |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 49 | * @NotThreadSafe |
| 50 | * @version $Revision: 1.14 $ |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 51 | */ |
| 52 | |
| 53 | public interface BundleActivator { |
| 54 | /** |
| 55 | * Called when this bundle is started so the Framework can perform the |
| 56 | * bundle-specific activities necessary to start this bundle. This method |
| 57 | * can be used to register services or to allocate any resources that this |
| 58 | * bundle needs. |
| 59 | * |
| 60 | * <p> |
| 61 | * This method must complete and return to its caller in a timely manner. |
| 62 | * |
| 63 | * @param context The execution context of the bundle being started. |
| 64 | * @throws java.lang.Exception If this method throws an exception, this |
| 65 | * bundle is marked as stopped and the Framework will remove this |
| 66 | * bundle's listeners, unregister all services registered by this |
| 67 | * bundle, and release all services used by this bundle. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 68 | */ |
| 69 | public void start(BundleContext context) throws Exception; |
| 70 | |
| 71 | /** |
| 72 | * Called when this bundle is stopped so the Framework can perform the |
| 73 | * bundle-specific activities necessary to stop the bundle. In general, this |
| 74 | * method should undo the work that the <code>BundleActivator.start</code> |
| 75 | * method started. There should be no active threads that were started by |
| 76 | * this bundle when this bundle returns. A stopped bundle must not call any |
| 77 | * Framework objects. |
| 78 | * |
| 79 | * <p> |
| 80 | * This method must complete and return to its caller in a timely manner. |
| 81 | * |
| 82 | * @param context The execution context of the bundle being stopped. |
| 83 | * @throws java.lang.Exception If this method throws an exception, the |
| 84 | * bundle is still marked as stopped, and the Framework will remove |
| 85 | * the bundle's listeners, unregister all services registered by the |
| 86 | * bundle, and release all services used by the bundle. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 87 | */ |
| 88 | public void stop(BundleContext context) throws Exception; |
| 89 | } |