KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > core > StartLevelImpl


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.osgi.framework.internal.core;
13
14 import org.osgi.framework.Bundle;
15 import org.osgi.service.startlevel.StartLevel;
16
17 /**
18  * StartLevel service for the OSGi specification.
19  *
20  * Framework service which allows management of framework and bundle startlevels.
21  *
22  * If present, there will only be a single instance of this service
23  * registered in the framework.
24  *
25  */

26 public class StartLevelImpl implements StartLevel {
27
28     protected StartLevelManager manager;
29     protected Bundle owner;
30
31     /** This constructor is called by the StartLevel factory */
32     protected StartLevelImpl(Bundle owner, Framework framework) {
33         this.owner = owner;
34         this.manager = framework.startLevelManager;
35     }
36
37     /**
38      * Return the initial start level value that is assigned
39      * to a Bundle when it is first installed.
40      *
41      * @return The initial start level value for Bundles.
42      * @see #setInitialBundleStartLevel
43      */

44     public int getInitialBundleStartLevel() {
45         return manager.getInitialBundleStartLevel();
46     }
47
48     /**
49      * Set the initial start level value that is assigned
50      * to a Bundle when it is first installed.
51      *
52      * <p>The initial bundle start level will be set to the specified start level. The
53      * initial bundle start level value will be persistently recorded
54      * by the Framework.
55      *
56      * <p>When a Bundle is installed via <tt>BundleContext.installBundle</tt>,
57      * it is assigned the initial bundle start level value.
58      *
59      * <p>The default initial bundle start level value is 1
60      * unless this method has been
61      * called to assign a different initial bundle
62      * start level value.
63      *
64      * <p>This method does not change the start level values of installed
65      * bundles.
66      *
67      * @param startlevel The initial start level for newly installed bundles.
68      * @throws IllegalArgumentException If the specified start level is less than or
69      * equal to zero.
70      * @throws SecurityException if the caller does not have the
71      * <tt>AdminPermission</tt> and the Java runtime environment supports
72      * permissions.
73      */

74     public void setInitialBundleStartLevel(int startlevel) {
75         manager.setInitialBundleStartLevel(startlevel);
76     }
77
78     /**
79      * Return the active start level value of the Framework.
80      *
81      * If the Framework is in the process of changing the start level
82      * this method must return the active start level if this
83      * differs from the requested start level.
84      *
85      * @return The active start level value of the Framework.
86      */

87     public int getStartLevel() {
88         return manager.getStartLevel();
89     }
90
91     /**
92      * Modify the active start level of the Framework.
93      *
94      * <p>The Framework will move to the requested start level. This method
95      * will return immediately to the caller and the start level
96      * change will occur asynchronously on another thread.
97      *
98      * <p>If the specified start level is
99      * higher than the active start level, the
100      * Framework will continue to increase the start level
101      * until the Framework has reached the specified start level,
102      * starting bundles at each
103      * start level which are persistently marked to be started as described in the
104      * <tt>Bundle.start</tt> method.
105      *
106      * At each intermediate start level value on the
107      * way to and including the target start level, the framework must:
108      * <ol>
109      * <li>Change the active start level to the intermediate start level value.
110      * <li>Start bundles at the intermediate start level in
111      * ascending order by <tt>Bundle.getBundleId</tt>.
112      * </ol>
113      * When this process completes after the specified start level is reached,
114      * the Framework will broadcast a Framework event of
115      * type <tt>FrameworkEvent.STARTLEVEL_CHANGED</tt> to announce it has moved to the specified
116      * start level.
117      *
118      * <p>If the specified start level is lower than the active start level, the
119      * Framework will continue to decrease the start level
120      * until the Framework has reached the specified start level
121      * stopping bundles at each
122      * start level as described in the <tt>Bundle.stop</tt> method except that their
123      * persistently recorded state indicates that they must be restarted in the
124      * future.
125      *
126      * At each intermediate start level value on the
127      * way to and including the specified start level, the framework must:
128      * <ol>
129      * <li>Stop bundles at the intermediate start level in
130      * descending order by <tt>Bundle.getBundleId</tt>.
131      * <li>Change the active start level to the intermediate start level value.
132      * </ol>
133      * When this process completes after the specified start level is reached,
134      * the Framework will broadcast a Framework event of
135      * type <tt>FrameworkEvent.STARTLEVEL_CHANGED</tt> to announce it has moved to the specified
136      * start level.
137      *
138      * <p>If the specified start level is equal to the active start level, then
139      * no bundles are started or stopped, however, the Framework must broadcast
140      * a Framework event of type <tt>FrameworkEvent.STARTLEVEL_CHANGED</tt> to
141      * announce it has finished moving to the specified start level. This
142      * event may arrive before the this method return.
143      *
144      * @param newSL The requested start level for the Framework.
145      * @throws IllegalArgumentException If the specified start level is less than or
146      * equal to zero.
147      * @throws SecurityException If the caller does not have the
148      * <tt>AdminPermission</tt> and the Java runtime environment supports
149      * permissions.
150      */

151     public void setStartLevel(int newSL) {
152         manager.setStartLevel(newSL, owner);
153     }
154
155     /**
156      * Return the persistent state of the specified bundle.
157      *
158      * <p>This method returns the persistent state of a bundle.
159      * The persistent state of a bundle indicates whether a bundle
160      * is persistently marked to be started when it's start level is
161      * reached.
162      *
163      * @return <tt>true</tt> if the bundle is persistently marked to be started,
164      * <tt>false</tt> if the bundle is not persistently marked to be started.
165      * @exception java.lang.IllegalArgumentException If the specified bundle has been uninstalled.
166      */

167     public boolean isBundlePersistentlyStarted(Bundle bundle) {
168         return manager.isBundlePersistentlyStarted(bundle);
169     }
170
171     
172     public boolean isBundleActivationPolicyUsed(Bundle bundle) {
173         return manager.isBundleActivationPolicyUsed(bundle);
174     }
175
176     /**
177      * Return the assigned start level value for the specified Bundle.
178      *
179      * @param bundle The target bundle.
180      * @return The start level value of the specified Bundle.
181      * @exception java.lang.IllegalArgumentException If the specified bundle has been uninstalled.
182      */

183     public int getBundleStartLevel(Bundle bundle) {
184         return manager.getBundleStartLevel(bundle);
185     }
186
187     /**
188      * Assign a start level value to the specified Bundle.
189      *
190      * <p>The specified bundle will be assigned the specified start level. The
191      * start level value assigned to the bundle will be persistently recorded
192      * by the Framework.
193      *
194      * If the new start level for the bundle is lower than or equal to the active start level of
195      * the Framework, the Framework will start the specified bundle as described
196      * in the <tt>Bundle.start</tt> method if the bundle is persistently marked
197      * to be started. The actual starting of this bundle must occur asynchronously.
198      *
199      * If the new start level for the bundle is higher than the active start level of
200      * the Framework, the Framework will stop the specified bundle as described
201      * in the <tt>Bundle.stop</tt> method except that the persistently recorded
202      * state for the bundle indicates that the bundle must be restarted in the
203      * future. The actual stopping of this bundle must occur asynchronously.
204      *
205      * @param bundle The target bundle.
206      * @param newSL The new start level for the specified Bundle.
207      * @throws IllegalArgumentException
208      * If the specified bundle has been uninstalled or
209      * if the specified start level is less than or equal to zero, or the specified bundle is
210      * the system bundle.
211      * @throws SecurityException if the caller does not have the
212      * <tt>AdminPermission</tt> and the Java runtime environment supports
213      * permissions.
214      */

215     public void setBundleStartLevel(Bundle bundle, int newSL) {
216         manager.setBundleStartLevel(bundle, newSL);
217     }
218
219     public boolean isSettingStartLevel() {
220         return manager.isSettingStartLevel();
221     }
222 }
223
Popular Tags