# HG changeset patch # User Omair Majid # Date 1360874101 18000 # Node ID 605f87eac75f122be04d7f0f56d3ec76abf2f4df # Parent 2bab65a9bc4c0a7f5c51b19b5ef8e641021dd0c9 Minor cleanup in LauncherImpl.shutdown() Reviewed-by: jerboaa, neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005674.html diff -r 2bab65a9bc4c -r 605f87eac75f launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java --- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java Thu Feb 14 15:07:59 2013 -0500 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java Thu Feb 14 15:35:01 2013 -0500 @@ -44,10 +44,8 @@ import java.util.logging.Level; import org.apache.commons.cli.Options; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; -import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; import com.redhat.thermostat.common.ActionListener; @@ -68,7 +66,6 @@ import com.redhat.thermostat.common.locale.Translate; import com.redhat.thermostat.common.tools.ApplicationState; import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.common.utils.OSGIUtils; import com.redhat.thermostat.launcher.BundleManager; import com.redhat.thermostat.storage.core.ConnectionException; import com.redhat.thermostat.storage.core.DbService; @@ -159,20 +156,21 @@ private void shutdown() throws InternalError { try { - ApplicationService appSvc = OSGIUtils.getInstance().getService(ApplicationService.class); - appSvc.getApplicationExecutor().shutdown(); - appSvc.getTimerFactory().shutdown(); + ServiceReference appServiceRef = context.getServiceReference(ApplicationService.class); + if (appServiceRef != null) { + ApplicationService appSvc = (ApplicationService) context.getService(appServiceRef); + appSvc.getApplicationExecutor().shutdown(); + appSvc.getTimerFactory().shutdown(); + appSvc = null; + context.ungetService(appServiceRef); + } - Bundle bundle = FrameworkUtil.getBundle(LauncherImpl.class); - if (bundle != null) { - BundleContext ctx = bundle.getBundleContext(); - if (ctx != null) { - ServiceReference storageRef = ctx.getServiceReference(Storage.class); - if (storageRef != null) { - Storage storage = (Storage) ctx.getService(storageRef); - if (storage != null) { - storage.shutdown(); - } + if (context != null) { + ServiceReference storageRef = context.getServiceReference(Storage.class); + if (storageRef != null) { + Storage storage = (Storage) context.getService(storageRef); + if (storage != null) { + storage.shutdown(); } } } diff -r 2bab65a9bc4c -r 605f87eac75f launcher/src/test/java/com/redhat/thermostat/launcher/internal/LauncherImplTest.java --- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LauncherImplTest.java Thu Feb 14 15:07:59 2013 -0500 +++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LauncherImplTest.java Thu Feb 14 15:35:01 2013 -0500 @@ -105,7 +105,7 @@ import com.redhat.thermostat.utils.keyring.KeyringProvider; @RunWith(PowerMockRunner.class) -@PrepareForTest({FrameworkUtil.class, HelpCommand.class, OSGIUtils.class}) +@PrepareForTest({FrameworkUtil.class, HelpCommand.class}) public class LauncherImplTest { private static String defaultKeyringProvider; @@ -256,10 +256,7 @@ ApplicationService appSvc = mock(ApplicationService.class); when(appSvc.getTimerFactory()).thenReturn(timerFactory); when(appSvc.getApplicationExecutor()).thenReturn(exec); - OSGIUtils osgi = mock(OSGIUtils.class); - when(osgi.getService(ApplicationService.class)).thenReturn(appSvc); - PowerMockito.mockStatic(OSGIUtils.class); - when(OSGIUtils.getInstance()).thenReturn(osgi); + bundleContext.registerService(ApplicationService.class, appSvc, null); loggingInitializer = mock(LoggingInitializer.class); dbServiceFactory = mock(DbServiceFactory.class);