public static void changeStartLevel(final BundleContext context, final int level, final long timeout, final TimeUnit units) throws InterruptedException, TimeoutException {
final ServiceReference sref = context.getServiceReference(StartLevel.class.getName());
final StartLevel startLevel = (StartLevel) context.getService(sref);
if (level != startLevel.getStartLevel()) {
final CountDownLatch latch = new CountDownLatch(1);
context.addFrameworkListener(new FrameworkListener() {
public void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED && level == startLevel.getStartLevel()) {
latch.countDown();
}
}