Mercurial > hg > release > thermostat-2.0
changeset 2280:a814b1d058be
Code consistency: Rename package 'osgi' => 'internal'.
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-April/018546.html
PR2138
line wrap: on
line diff
--- a/client/swing/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/client/swing/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -166,7 +166,7 @@ <configuration> <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-Activator>com.redhat.thermostat.client.swing.internal.osgi.ThermostatActivator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.client.swing.internal.ThermostatActivator</Bundle-Activator> <Bundle-SymbolicName>com.redhat.thermostat.client.swing</Bundle-SymbolicName> <Export-Package> com.redhat.thermostat.client.swing, @@ -181,7 +181,6 @@ com.redhat.thermostat.client.swing.internal.splitpane, com.redhat.thermostat.client.swing.internal.progress, com.redhat.thermostat.client.swing.internal.components, - com.redhat.thermostat.client.swing.internal.osgi, com.redhat.thermostat.client.swing.internal.views, com.redhat.thermostat.client.swing.internal.vmlist, com.redhat.thermostat.client.swing.internal.vmlist.controller,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/ContextActionServiceTracker.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.swing.internal; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.client.ui.ReferenceContextAction; + +@SuppressWarnings("rawtypes") +public class ContextActionServiceTracker extends ServiceTracker { + + private List<ReferenceContextAction> hostContextActions; + + @SuppressWarnings("unchecked") + public ContextActionServiceTracker(BundleContext context) { + super(context, ReferenceContextAction.class.getName(), null); + this.hostContextActions = new CopyOnWriteArrayList<>(); + } + + @Override + public Object addingService(ServiceReference reference) { + @SuppressWarnings("unchecked") + ReferenceContextAction service = (ReferenceContextAction) super.addingService(reference); + hostContextActions.add(service); + return service; + } + + @SuppressWarnings("unchecked") + @Override + public void removedService(ServiceReference reference, Object service) { + hostContextActions.remove((ReferenceContextAction)service); + super.removedService(reference, service); + } + + public List<ReferenceContextAction> getActions() { + return new ArrayList<>(hostContextActions); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/InformationServiceTracker.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,107 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.swing.internal; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.client.core.InformationService; +import com.redhat.thermostat.common.Constants; +import com.redhat.thermostat.common.utils.LoggingUtils; +import com.redhat.thermostat.storage.core.HostRef; +import com.redhat.thermostat.storage.core.VmRef; + +@SuppressWarnings("rawtypes") +public class InformationServiceTracker extends ServiceTracker { + + private static final Logger logger = LoggingUtils.getLogger(InformationServiceTracker.class); + + private List<InformationService<HostRef>> hostInfoServices; + private List<InformationService<VmRef>> vmInfoServices; + + @SuppressWarnings("unchecked") + public InformationServiceTracker(BundleContext context) { + super(context, InformationService.class.getName(), null); + this.hostInfoServices = new ArrayList<>(); + this.vmInfoServices = new ArrayList<>(); + } + + @Override + public Object addingService(ServiceReference reference) { + Object service = super.addingService(reference); + String genericType = (String) reference.getProperty(Constants.GENERIC_SERVICE_CLASSNAME); + if (genericType.equals(HostRef.class.getName())) { + hostInfoServices.add((InformationService<HostRef>) service); + } else if (genericType.equals(VmRef.class.getName())) { + vmInfoServices.add((InformationService<VmRef>) service); + } else { + logUnknownGenericServiceType(genericType); + } + return service; + } + + @Override + public void removedService(ServiceReference reference, Object service) { + String genericType = (String) reference.getProperty(Constants.GENERIC_SERVICE_CLASSNAME); + if (genericType.equals(HostRef.class.getName())) { + hostInfoServices.remove((InformationService<HostRef>) service); + } else if (genericType.equals(VmRef.class.getName())) { + vmInfoServices.remove((InformationService<VmRef>) service); + } else { + logUnknownGenericServiceType(genericType); + } + super.removedService(reference, service); + } + + public List<InformationService<HostRef>> getHostInformationServices() { + return new ArrayList<>(hostInfoServices); + } + + public List<InformationService<VmRef>> getVmInformationServices() { + return new ArrayList<>(vmInfoServices); + } + + private void logUnknownGenericServiceType(String genericType) { + logger.warning("InformationServiceTracker encountered an unknown generic type: " + genericType); + } +} +
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java Thu Mar 10 14:50:49 2016 +0100 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java Tue Apr 19 15:28:00 2016 +0200 @@ -62,8 +62,6 @@ import com.redhat.thermostat.client.core.views.IssueViewProvider; import com.redhat.thermostat.client.core.views.VersionAndInfoViewProvider; import com.redhat.thermostat.client.core.views.VmInformationViewProvider; -import com.redhat.thermostat.client.swing.internal.osgi.ContextActionServiceTracker; -import com.redhat.thermostat.client.swing.internal.osgi.InformationServiceTracker; import com.redhat.thermostat.client.swing.internal.registry.decorator.DecoratorRegistryController; import com.redhat.thermostat.client.swing.internal.search.ReferenceFieldSearchFilter; import com.redhat.thermostat.client.swing.internal.vmlist.controller.ContextActionController;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/ThermostatActivator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,138 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.swing.internal; + +import java.util.Map; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.client.core.views.AgentInformationViewProvider; +import com.redhat.thermostat.client.core.views.ClientConfigViewProvider; +import com.redhat.thermostat.client.core.views.HostInformationViewProvider; +import com.redhat.thermostat.client.core.views.IssueViewProvider; +import com.redhat.thermostat.client.core.views.VersionAndInfoViewProvider; +import com.redhat.thermostat.client.core.views.VmInformationViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingAgentInformationViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingClientConfigurationViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingHostInformationViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingIssueViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingSummaryViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingVmInformationViewProvider; + +import com.redhat.thermostat.common.ApplicationService; +import com.redhat.thermostat.common.MultipleServiceTracker; +import com.redhat.thermostat.common.MultipleServiceTracker.Action; + +import com.redhat.thermostat.common.cli.CommandRegistry; +import com.redhat.thermostat.common.cli.CommandRegistryImpl; +import com.redhat.thermostat.shared.config.CommonPaths; +import com.redhat.thermostat.shared.config.SSLConfiguration; +import com.redhat.thermostat.utils.keyring.Keyring; + +public class ThermostatActivator implements BundleActivator { + + private CommandRegistry cmdReg; + private MultipleServiceTracker dependencyTracker; + + @Override + public void start(final BundleContext context) throws Exception { + + // Host views + HostInformationViewProvider infoProvider = new SwingHostInformationViewProvider(); + context.registerService(HostInformationViewProvider.class.getName(), infoProvider, null); + + // Vm views + VmInformationViewProvider vmInfoProvider = new SwingVmInformationViewProvider(); + context.registerService(VmInformationViewProvider.class.getName(), vmInfoProvider, null); + + // Summary view + VersionAndInfoViewProvider summaryViewProvider = new SwingSummaryViewProvider(); + context.registerService(VersionAndInfoViewProvider.class.getName(), summaryViewProvider, null); + + // Issues view + IssueViewProvider issuesViewProvider = new SwingIssueViewProvider(); + context.registerService(IssueViewProvider.class.getName(), issuesViewProvider, null); + + // AgentInformation and ClientConfiguraiton view + AgentInformationViewProvider agentViewProvider = new SwingAgentInformationViewProvider(); + context.registerService(AgentInformationViewProvider.class.getName(), agentViewProvider, null); + ClientConfigViewProvider clientConfigViewProvider = new SwingClientConfigurationViewProvider(); + context.registerService(ClientConfigViewProvider.class, clientConfigViewProvider, null); + + Class<?>[] deps = new Class<?>[] { + Keyring.class, + CommonPaths.class, + ApplicationService.class, + SSLConfiguration.class, + }; + dependencyTracker = new MultipleServiceTracker(context, deps, new Action() { + + private Main main; + + @Override + public void dependenciesAvailable(Map<String, Object> services) { + Keyring keyring = (Keyring) services.get(Keyring.class.getName()); + CommonPaths paths = (CommonPaths) services.get(CommonPaths.class.getName()); + ApplicationService appSvc = (ApplicationService) services.get(ApplicationService.class.getName()); + SSLConfiguration sslConf = (SSLConfiguration) services.get(SSLConfiguration.class.getName()); + cmdReg = new CommandRegistryImpl(context); + main = new Main(context, keyring, paths, appSvc, sslConf); + + GUIClientCommand cmd = new GUIClientCommand(main); + cmdReg.registerCommand("gui", cmd); + } + + @Override + public void dependenciesUnavailable() { + if (main != null) { + main.shutdown(); + } + } + }); + dependencyTracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + dependencyTracker.close(); + if (cmdReg != null) { + cmdReg.unregisterCommands(); + } + } +} +
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/osgi/ContextActionServiceTracker.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.swing.internal.osgi; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -import com.redhat.thermostat.client.ui.ReferenceContextAction; - -@SuppressWarnings("rawtypes") -public class ContextActionServiceTracker extends ServiceTracker { - - private List<ReferenceContextAction> hostContextActions; - - @SuppressWarnings("unchecked") - public ContextActionServiceTracker(BundleContext context) { - super(context, ReferenceContextAction.class.getName(), null); - this.hostContextActions = new CopyOnWriteArrayList<>(); - } - - @Override - public Object addingService(ServiceReference reference) { - @SuppressWarnings("unchecked") - ReferenceContextAction service = (ReferenceContextAction) super.addingService(reference); - hostContextActions.add(service); - return service; - } - - @SuppressWarnings("unchecked") - @Override - public void removedService(ServiceReference reference, Object service) { - hostContextActions.remove((ReferenceContextAction)service); - super.removedService(reference, service); - } - - public List<ReferenceContextAction> getActions() { - return new ArrayList<>(hostContextActions); - } -} -
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/osgi/InformationServiceTracker.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.swing.internal.osgi; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -import com.redhat.thermostat.client.core.InformationService; -import com.redhat.thermostat.common.Constants; -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.storage.core.HostRef; -import com.redhat.thermostat.storage.core.VmRef; - -@SuppressWarnings("rawtypes") -public class InformationServiceTracker extends ServiceTracker { - - private static final Logger logger = LoggingUtils.getLogger(InformationServiceTracker.class); - - private List<InformationService<HostRef>> hostInfoServices; - private List<InformationService<VmRef>> vmInfoServices; - - @SuppressWarnings("unchecked") - public InformationServiceTracker(BundleContext context) { - super(context, InformationService.class.getName(), null); - this.hostInfoServices = new ArrayList<>(); - this.vmInfoServices = new ArrayList<>(); - } - - @Override - public Object addingService(ServiceReference reference) { - Object service = super.addingService(reference); - String genericType = (String) reference.getProperty(Constants.GENERIC_SERVICE_CLASSNAME); - if (genericType.equals(HostRef.class.getName())) { - hostInfoServices.add((InformationService<HostRef>) service); - } else if (genericType.equals(VmRef.class.getName())) { - vmInfoServices.add((InformationService<VmRef>) service); - } else { - logUnknownGenericServiceType(genericType); - } - return service; - } - - @Override - public void removedService(ServiceReference reference, Object service) { - String genericType = (String) reference.getProperty(Constants.GENERIC_SERVICE_CLASSNAME); - if (genericType.equals(HostRef.class.getName())) { - hostInfoServices.remove((InformationService<HostRef>) service); - } else if (genericType.equals(VmRef.class.getName())) { - vmInfoServices.remove((InformationService<VmRef>) service); - } else { - logUnknownGenericServiceType(genericType); - } - super.removedService(reference, service); - } - - public List<InformationService<HostRef>> getHostInformationServices() { - return new ArrayList<>(hostInfoServices); - } - - public List<InformationService<VmRef>> getVmInformationServices() { - return new ArrayList<>(vmInfoServices); - } - - private void logUnknownGenericServiceType(String genericType) { - logger.warning("InformationServiceTracker encountered an unknown generic type: " + genericType); - } -} -
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/osgi/ThermostatActivator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.swing.internal.osgi; - -import java.util.Map; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.client.core.views.AgentInformationViewProvider; -import com.redhat.thermostat.client.core.views.ClientConfigViewProvider; -import com.redhat.thermostat.client.core.views.HostInformationViewProvider; -import com.redhat.thermostat.client.core.views.IssueViewProvider; -import com.redhat.thermostat.client.core.views.VersionAndInfoViewProvider; -import com.redhat.thermostat.client.core.views.VmInformationViewProvider; - -import com.redhat.thermostat.client.swing.internal.GUIClientCommand; -import com.redhat.thermostat.client.swing.internal.Main; -import com.redhat.thermostat.client.swing.internal.views.SwingAgentInformationViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingClientConfigurationViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingHostInformationViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingIssueViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingSummaryViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingVmInformationViewProvider; - -import com.redhat.thermostat.common.ApplicationService; -import com.redhat.thermostat.common.MultipleServiceTracker; -import com.redhat.thermostat.common.MultipleServiceTracker.Action; - -import com.redhat.thermostat.common.cli.CommandRegistry; -import com.redhat.thermostat.common.cli.CommandRegistryImpl; -import com.redhat.thermostat.shared.config.CommonPaths; -import com.redhat.thermostat.shared.config.SSLConfiguration; -import com.redhat.thermostat.utils.keyring.Keyring; - -public class ThermostatActivator implements BundleActivator { - - private CommandRegistry cmdReg; - private MultipleServiceTracker dependencyTracker; - - @Override - public void start(final BundleContext context) throws Exception { - - // Host views - HostInformationViewProvider infoProvider = new SwingHostInformationViewProvider(); - context.registerService(HostInformationViewProvider.class.getName(), infoProvider, null); - - // Vm views - VmInformationViewProvider vmInfoProvider = new SwingVmInformationViewProvider(); - context.registerService(VmInformationViewProvider.class.getName(), vmInfoProvider, null); - - // Summary view - VersionAndInfoViewProvider summaryViewProvider = new SwingSummaryViewProvider(); - context.registerService(VersionAndInfoViewProvider.class.getName(), summaryViewProvider, null); - - // Issues view - IssueViewProvider issuesViewProvider = new SwingIssueViewProvider(); - context.registerService(IssueViewProvider.class.getName(), issuesViewProvider, null); - - // AgentInformation and ClientConfiguraiton view - AgentInformationViewProvider agentViewProvider = new SwingAgentInformationViewProvider(); - context.registerService(AgentInformationViewProvider.class.getName(), agentViewProvider, null); - ClientConfigViewProvider clientConfigViewProvider = new SwingClientConfigurationViewProvider(); - context.registerService(ClientConfigViewProvider.class, clientConfigViewProvider, null); - - Class<?>[] deps = new Class<?>[] { - Keyring.class, - CommonPaths.class, - ApplicationService.class, - SSLConfiguration.class, - }; - dependencyTracker = new MultipleServiceTracker(context, deps, new Action() { - - private Main main; - - @Override - public void dependenciesAvailable(Map<String, Object> services) { - Keyring keyring = (Keyring) services.get(Keyring.class.getName()); - CommonPaths paths = (CommonPaths) services.get(CommonPaths.class.getName()); - ApplicationService appSvc = (ApplicationService) services.get(ApplicationService.class.getName()); - SSLConfiguration sslConf = (SSLConfiguration) services.get(SSLConfiguration.class.getName()); - cmdReg = new CommandRegistryImpl(context); - main = new Main(context, keyring, paths, appSvc, sslConf); - - GUIClientCommand cmd = new GUIClientCommand(main); - cmdReg.registerCommand("gui", cmd); - } - - @Override - public void dependenciesUnavailable() { - if (main != null) { - main.shutdown(); - } - } - }); - dependencyTracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - dependencyTracker.close(); - if (cmdReg != null) { - cmdReg.unregisterCommands(); - } - } -} -
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/ContextHandler.java Thu Mar 10 14:50:49 2016 +0100 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/ContextHandler.java Tue Apr 19 15:28:00 2016 +0200 @@ -42,7 +42,7 @@ import javax.swing.SwingUtilities; import com.redhat.thermostat.client.swing.components.ThermostatPopupMenu; -import com.redhat.thermostat.client.swing.internal.osgi.ContextActionServiceTracker; +import com.redhat.thermostat.client.swing.internal.ContextActionServiceTracker; import com.redhat.thermostat.client.ui.ReferenceContextAction; import com.redhat.thermostat.client.ui.ReferenceFilter; import com.redhat.thermostat.common.ActionEvent;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/HostContextActionServiceTrackerTest.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.swing.internal; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import org.junit.Test; +import org.osgi.framework.ServiceRegistration; + +import com.redhat.thermostat.client.swing.internal.ContextActionServiceTracker; +import com.redhat.thermostat.client.ui.ReferenceContextAction; +import com.redhat.thermostat.testutils.StubBundleContext; + +public class HostContextActionServiceTrackerTest { + + @Test + public void verifyHostActionIsAddedToAndRemovedFromUiModel() { + StubBundleContext bundleContext = new StubBundleContext(); + + ReferenceContextAction hostAction = mock(ReferenceContextAction.class); + ServiceRegistration registration = bundleContext.registerService(ReferenceContextAction.class, hostAction, null); + + ContextActionServiceTracker tracker = new ContextActionServiceTracker(bundleContext); + tracker.open(); + + assertTrue(tracker.getActions().contains(hostAction)); + + registration.unregister(); + + tracker.close(); + + assertFalse(tracker.getActions().contains(hostAction)); + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/ThermostatActivatorTest.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,111 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.swing.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import org.junit.Test; + +import com.redhat.thermostat.client.core.views.AgentInformationViewProvider; +import com.redhat.thermostat.client.core.views.ClientConfigViewProvider; +import com.redhat.thermostat.client.core.views.HostInformationViewProvider; +import com.redhat.thermostat.client.core.views.IssueViewProvider; +import com.redhat.thermostat.client.core.views.VersionAndInfoViewProvider; +import com.redhat.thermostat.client.core.views.VmInformationViewProvider; +import com.redhat.thermostat.client.swing.internal.GUIClientCommand; +import com.redhat.thermostat.client.swing.internal.ThermostatActivator; +import com.redhat.thermostat.client.swing.internal.views.SwingAgentInformationViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingClientConfigurationViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingHostInformationViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingIssueViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingSummaryViewProvider; +import com.redhat.thermostat.client.swing.internal.views.SwingVmInformationViewProvider; +import com.redhat.thermostat.common.ApplicationService; +import com.redhat.thermostat.common.cli.Command; +import com.redhat.thermostat.shared.config.CommonPaths; +import com.redhat.thermostat.shared.config.SSLConfiguration; +import com.redhat.thermostat.testutils.StubBundleContext; +import com.redhat.thermostat.utils.keyring.Keyring; + +public class ThermostatActivatorTest { + + @Test + public void verifyAllExpectedServicesAreRegistered() throws Exception { + StubBundleContext ctx = new StubBundleContext(); + + ThermostatActivator activator = new ThermostatActivator(); + + activator.start(ctx); + + assertTrue(ctx.isServiceRegistered(VersionAndInfoViewProvider.class.getName(), SwingSummaryViewProvider.class)); + assertTrue(ctx.isServiceRegistered(IssueViewProvider.class.getName(), SwingIssueViewProvider.class)); + assertTrue(ctx.isServiceRegistered(HostInformationViewProvider.class.getName(), SwingHostInformationViewProvider.class)); + assertTrue(ctx.isServiceRegistered(VmInformationViewProvider.class.getName(), SwingVmInformationViewProvider.class)); + assertTrue(ctx.isServiceRegistered(AgentInformationViewProvider.class.getName(), SwingAgentInformationViewProvider.class)); + assertTrue(ctx.isServiceRegistered(ClientConfigViewProvider.class.getName(), SwingClientConfigurationViewProvider.class)); + + assertEquals(6, ctx.getAllServices().size()); + + activator.stop(ctx); + } + + @Test + public void verifyGuiCommandIsRegisteredWhenDependenciesAreAvailable() throws Exception { + Keyring keyring = mock(Keyring.class); + CommonPaths paths = mock(CommonPaths.class); + ApplicationService appService = mock(ApplicationService.class); + SSLConfiguration sslConf = mock(SSLConfiguration.class); + + StubBundleContext ctx = new StubBundleContext(); + + ThermostatActivator activator = new ThermostatActivator(); + + activator.start(ctx); + + ctx.registerService(Keyring.class, keyring, null); + ctx.registerService(CommonPaths.class, paths, null); + ctx.registerService(ApplicationService.class, appService, null); + ctx.registerService(SSLConfiguration.class, sslConf, null); + + assertTrue(ctx.isServiceRegistered(Command.class.getName(), GUIClientCommand.class)); + + activator.stop(ctx); + } +} +
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/osgi/HostContextActionServiceTrackerTest.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.swing.internal.osgi; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import org.junit.Test; -import org.osgi.framework.ServiceRegistration; - -import com.redhat.thermostat.client.ui.ReferenceContextAction; -import com.redhat.thermostat.testutils.StubBundleContext; - -public class HostContextActionServiceTrackerTest { - - @Test - public void verifyHostActionIsAddedToAndRemovedFromUiModel() { - StubBundleContext bundleContext = new StubBundleContext(); - - ReferenceContextAction hostAction = mock(ReferenceContextAction.class); - ServiceRegistration registration = bundleContext.registerService(ReferenceContextAction.class, hostAction, null); - - ContextActionServiceTracker tracker = new ContextActionServiceTracker(bundleContext); - tracker.open(); - - assertTrue(tracker.getActions().contains(hostAction)); - - registration.unregister(); - - tracker.close(); - - assertFalse(tracker.getActions().contains(hostAction)); - } - -} -
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/osgi/ThermostatActivatorTest.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client.swing.internal.osgi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import org.junit.Test; - -import com.redhat.thermostat.client.core.views.AgentInformationViewProvider; -import com.redhat.thermostat.client.core.views.ClientConfigViewProvider; -import com.redhat.thermostat.client.core.views.HostInformationViewProvider; -import com.redhat.thermostat.client.core.views.IssueViewProvider; -import com.redhat.thermostat.client.core.views.VersionAndInfoViewProvider; -import com.redhat.thermostat.client.core.views.VmInformationViewProvider; -import com.redhat.thermostat.client.swing.internal.GUIClientCommand; -import com.redhat.thermostat.client.swing.internal.views.SwingAgentInformationViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingClientConfigurationViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingHostInformationViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingIssueViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingSummaryViewProvider; -import com.redhat.thermostat.client.swing.internal.views.SwingVmInformationViewProvider; -import com.redhat.thermostat.common.ApplicationService; -import com.redhat.thermostat.common.cli.Command; -import com.redhat.thermostat.shared.config.CommonPaths; -import com.redhat.thermostat.shared.config.SSLConfiguration; -import com.redhat.thermostat.testutils.StubBundleContext; -import com.redhat.thermostat.utils.keyring.Keyring; - -public class ThermostatActivatorTest { - - @Test - public void verifyAllExpectedServicesAreRegistered() throws Exception { - StubBundleContext ctx = new StubBundleContext(); - - ThermostatActivator activator = new ThermostatActivator(); - - activator.start(ctx); - - assertTrue(ctx.isServiceRegistered(VersionAndInfoViewProvider.class.getName(), SwingSummaryViewProvider.class)); - assertTrue(ctx.isServiceRegistered(IssueViewProvider.class.getName(), SwingIssueViewProvider.class)); - assertTrue(ctx.isServiceRegistered(HostInformationViewProvider.class.getName(), SwingHostInformationViewProvider.class)); - assertTrue(ctx.isServiceRegistered(VmInformationViewProvider.class.getName(), SwingVmInformationViewProvider.class)); - assertTrue(ctx.isServiceRegistered(AgentInformationViewProvider.class.getName(), SwingAgentInformationViewProvider.class)); - assertTrue(ctx.isServiceRegistered(ClientConfigViewProvider.class.getName(), SwingClientConfigurationViewProvider.class)); - - assertEquals(6, ctx.getAllServices().size()); - - activator.stop(ctx); - } - - @Test - public void verifyGuiCommandIsRegisteredWhenDependenciesAreAvailable() throws Exception { - Keyring keyring = mock(Keyring.class); - CommonPaths paths = mock(CommonPaths.class); - ApplicationService appService = mock(ApplicationService.class); - SSLConfiguration sslConf = mock(SSLConfiguration.class); - - StubBundleContext ctx = new StubBundleContext(); - - ThermostatActivator activator = new ThermostatActivator(); - - activator.start(ctx); - - ctx.registerService(Keyring.class, keyring, null); - ctx.registerService(CommonPaths.class, paths, null); - ctx.registerService(ApplicationService.class, appService, null); - ctx.registerService(SSLConfiguration.class, sslConf, null); - - assertTrue(ctx.isServiceRegistered(Command.class.getName(), GUIClientCommand.class)); - - activator.stop(ctx); - } -} -
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/ContextHandlerTest.java Thu Mar 10 14:50:49 2016 +0100 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/ContextHandlerTest.java Tue Apr 19 15:28:00 2016 +0200 @@ -63,8 +63,8 @@ import org.mockito.ArgumentCaptor; import com.redhat.thermostat.client.swing.components.ThermostatPopupMenu; +import com.redhat.thermostat.client.swing.internal.ContextActionServiceTracker; import com.redhat.thermostat.client.swing.internal.accordion.AccordionComponent; -import com.redhat.thermostat.client.swing.internal.osgi.ContextActionServiceTracker; import com.redhat.thermostat.client.swing.internal.vmlist.controller.ContextHandler.ContextHandlerAction; import com.redhat.thermostat.client.swing.internal.vmlist.controller.ContextHandler.Payload; import com.redhat.thermostat.client.ui.ReferenceContextAction;
--- a/keyring/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/keyring/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -56,10 +56,9 @@ <extensions>true</extensions> <configuration> <instructions> - <Bundle-Activator>com.redhat.thermostat.utils.keyring.activator.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.utils.keyring.internal.Activator</Bundle-Activator> <Bundle-SymbolicName>com.redhat.thermostat.keyring</Bundle-SymbolicName> <Private-Package> - com.redhat.thermostat.utils.keyring.activator, com.redhat.thermostat.utils.keyring.internal, </Private-Package> <Export-Package>com.redhat.thermostat.utils.keyring</Export-Package>
--- a/keyring/src/main/java/com/redhat/thermostat/utils/keyring/activator/Activator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.utils.keyring.activator; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import com.redhat.thermostat.utils.keyring.Keyring; -import com.redhat.thermostat.utils.keyring.internal.KeyringImpl; - -public class Activator implements BundleActivator { - - @Override - public void start(BundleContext context) throws Exception { - Keyring theKeyring = null; - try { - theKeyring = new KeyringImpl(); - } catch (UnsatisfiedLinkError e) { - theKeyring = new Keyring() { - /* Trivial implementation just to keep the world from blowing up. - * Everything noop. - */ - - @Override - public void savePassword(String url, String username, - char[] password) { - // NOOP - } - - @Override - public char[] getPassword(String url, String username) { - // NOOP - return new char[]{}; - } - - @Override - public void clearPassword(String url, String username) { - // NOOP - } - - }; - } - context.registerService(Keyring.class.getName(), theKeyring, null); - - } - - @Override - public void stop(BundleContext context) throws Exception { - // Nothing to do - } -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/keyring/src/main/java/com/redhat/thermostat/utils/keyring/internal/Activator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,85 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.utils.keyring.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.redhat.thermostat.utils.keyring.Keyring; + +public class Activator implements BundleActivator { + + @Override + public void start(BundleContext context) throws Exception { + Keyring theKeyring = null; + try { + theKeyring = new KeyringImpl(); + } catch (UnsatisfiedLinkError e) { + theKeyring = new Keyring() { + /* Trivial implementation just to keep the world from blowing up. + * Everything noop. + */ + + @Override + public void savePassword(String url, String username, + char[] password) { + // NOOP + } + + @Override + public char[] getPassword(String url, String username) { + // NOOP + return new char[]{}; + } + + @Override + public void clearPassword(String url, String username) { + // NOOP + } + + }; + } + context.registerService(Keyring.class.getName(), theKeyring, null); + + } + + @Override + public void stop(BundleContext context) throws Exception { + // Nothing to do + } +} +
--- a/system-backend/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/system-backend/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -108,11 +108,10 @@ <configuration> <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-Activator>com.redhat.thermostat.backend.system.osgi.SystemBackendActivator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.backend.system.SystemBackendActivator</Bundle-Activator> <Bundle-SymbolicName>com.redhat.thermostat.backend.system</Bundle-SymbolicName> <Private-Package> com.redhat.thermostat.backend.system, - com.redhat.thermostat.backend.system.osgi, </Private-Package> <!-- Do not autogenerate uses clauses in Manifests --> <_nouses>true</_nouses>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/system-backend/src/main/java/com/redhat/thermostat/backend/system/SystemBackendActivator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,118 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.backend.system; + +import java.util.Map; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.redhat.thermostat.agent.VmBlacklist; +import com.redhat.thermostat.agent.utils.username.UserNameUtil; +import com.redhat.thermostat.backend.Backend; +import com.redhat.thermostat.backend.BackendService; +import com.redhat.thermostat.common.MultipleServiceTracker; +import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.storage.core.WriterID; +import com.redhat.thermostat.storage.dao.HostInfoDAO; +import com.redhat.thermostat.storage.dao.NetworkInterfaceInfoDAO; +import com.redhat.thermostat.storage.dao.VmInfoDAO; + +@SuppressWarnings("rawtypes") +public class SystemBackendActivator implements BundleActivator { + + private MultipleServiceTracker tracker; + private SystemBackend backend; + private ServiceRegistration reg; + private VmStatusChangeNotifier notifier; + + @Override + public void start(final BundleContext context) throws Exception { + + notifier = new VmStatusChangeNotifier(context); + notifier.start(); + + Class<?>[] deps = new Class<?>[] { + BackendService.class, + HostInfoDAO.class, + NetworkInterfaceInfoDAO.class, + VmInfoDAO.class, + UserNameUtil.class, + WriterID.class, // system backend uses it + VmBlacklist.class, + }; + tracker = new MultipleServiceTracker(context, deps, new Action() { + @Override + public void dependenciesAvailable(Map<String, Object> services) { + HostInfoDAO hostInfoDAO = (HostInfoDAO) services.get(HostInfoDAO.class.getName()); + NetworkInterfaceInfoDAO netInfoDAO = (NetworkInterfaceInfoDAO) services + .get(NetworkInterfaceInfoDAO.class.getName()); + VmInfoDAO vmInfoDAO = (VmInfoDAO) services.get(VmInfoDAO.class.getName()); + UserNameUtil userNameUtil = (UserNameUtil) services.get(UserNameUtil.class.getName()); + Version version = new Version(context.getBundle()); + WriterID id = (WriterID) services.get(WriterID.class.getName()); + VmBlacklist blacklist = (VmBlacklist) services.get(VmBlacklist.class.getName()); + backend = new SystemBackend(hostInfoDAO, netInfoDAO, vmInfoDAO, version, notifier, + userNameUtil, id, blacklist); + reg = context.registerService(Backend.class, backend, null); + } + + @Override + public void dependenciesUnavailable() { + if (backend.isActive()) { + backend.deactivate(); + } + reg.unregister(); + } + + }); + + tracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + if (backend != null && backend.isActive()) { + backend.deactivate(); + } + tracker.close(); + notifier.stop(); + } +} +
--- a/system-backend/src/main/java/com/redhat/thermostat/backend/system/osgi/SystemBackendActivator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.backend.system.osgi; - -import java.util.Map; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import com.redhat.thermostat.agent.VmBlacklist; -import com.redhat.thermostat.agent.utils.username.UserNameUtil; -import com.redhat.thermostat.backend.Backend; -import com.redhat.thermostat.backend.BackendService; -import com.redhat.thermostat.backend.system.SystemBackend; -import com.redhat.thermostat.backend.system.VmStatusChangeNotifier; -import com.redhat.thermostat.common.MultipleServiceTracker; -import com.redhat.thermostat.common.MultipleServiceTracker.Action; -import com.redhat.thermostat.common.Version; -import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.storage.dao.HostInfoDAO; -import com.redhat.thermostat.storage.dao.NetworkInterfaceInfoDAO; -import com.redhat.thermostat.storage.dao.VmInfoDAO; - -@SuppressWarnings("rawtypes") -public class SystemBackendActivator implements BundleActivator { - - private MultipleServiceTracker tracker; - private SystemBackend backend; - private ServiceRegistration reg; - private VmStatusChangeNotifier notifier; - - @Override - public void start(final BundleContext context) throws Exception { - - notifier = new VmStatusChangeNotifier(context); - notifier.start(); - - Class<?>[] deps = new Class<?>[] { - BackendService.class, - HostInfoDAO.class, - NetworkInterfaceInfoDAO.class, - VmInfoDAO.class, - UserNameUtil.class, - WriterID.class, // system backend uses it - VmBlacklist.class, - }; - tracker = new MultipleServiceTracker(context, deps, new Action() { - @Override - public void dependenciesAvailable(Map<String, Object> services) { - HostInfoDAO hostInfoDAO = (HostInfoDAO) services.get(HostInfoDAO.class.getName()); - NetworkInterfaceInfoDAO netInfoDAO = (NetworkInterfaceInfoDAO) services - .get(NetworkInterfaceInfoDAO.class.getName()); - VmInfoDAO vmInfoDAO = (VmInfoDAO) services.get(VmInfoDAO.class.getName()); - UserNameUtil userNameUtil = (UserNameUtil) services.get(UserNameUtil.class.getName()); - Version version = new Version(context.getBundle()); - WriterID id = (WriterID) services.get(WriterID.class.getName()); - VmBlacklist blacklist = (VmBlacklist) services.get(VmBlacklist.class.getName()); - backend = new SystemBackend(hostInfoDAO, netInfoDAO, vmInfoDAO, version, notifier, - userNameUtil, id, blacklist); - reg = context.registerService(Backend.class, backend, null); - } - - @Override - public void dependenciesUnavailable() { - if (backend.isActive()) { - backend.deactivate(); - } - reg.unregister(); - } - - }); - - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - if (backend != null && backend.isActive()) { - backend.deactivate(); - } - tracker.close(); - notifier.stop(); - } -} -
--- a/thread/client-common/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/thread/client-common/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -114,7 +114,7 @@ <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.thread.client.common</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.thread.client.common.osgi.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.thread.client.common.internal.Activator</Bundle-Activator> <Export-Package> com.redhat.thermostat.thread.client.common, com.redhat.thermostat.thread.client.common.view, @@ -125,7 +125,7 @@ </Export-Package> <Private-Package> com.redhat.thermostat.thread.client.common.collector.internal, - com.redhat.thermostat.thread.client.common.osgi, + com.redhat.thermostat.thread.client.common.internal, </Private-Package> <!-- Do not autogenerate uses clauses in Manifests --> <_nouses>true</_nouses>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/internal/Activator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,102 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.client.common.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.storage.dao.AgentInfoDAO; +import com.redhat.thermostat.thread.client.common.collector.ThreadCollectorFactory; +import com.redhat.thermostat.thread.client.common.collector.internal.ThreadCollectorFactoryImpl; +import com.redhat.thermostat.thread.dao.ThreadDao; + +public class Activator implements BundleActivator { + + private ThreadCollectorFactoryImpl collectorFactory; + private ServiceTracker agentInfoDaoTracker; + private ServiceTracker threadDaoTracker; + + @Override + public void start(final BundleContext context) throws Exception { + + collectorFactory = new ThreadCollectorFactoryImpl(); + context.registerService(ThreadCollectorFactory.class.getName(), collectorFactory, null); + + agentInfoDaoTracker = new ServiceTracker(context, AgentInfoDAO.class.getName(), null) { + @Override + public Object addingService(ServiceReference reference) { + AgentInfoDAO agentDao = (AgentInfoDAO) context.getService(reference); + collectorFactory.setAgentDao(agentDao); + return super.addingService(reference); + } + + @Override + public void removedService(ServiceReference reference, Object service) { + collectorFactory.setAgentDao(null); + context.ungetService(reference); + super.removedService(reference, service); + } + }; + agentInfoDaoTracker.open(); + + threadDaoTracker = new ServiceTracker(context, ThreadDao.class.getName(), null) { + @Override + public Object addingService(ServiceReference reference) { + ThreadDao threadDao = (ThreadDao) context.getService(reference); + collectorFactory.setThreadDao(threadDao); + return super.addingService(reference); + } + + @Override + public void removedService(ServiceReference reference, Object service) { + collectorFactory.setThreadDao(null); + context.ungetService(reference); + super.removedService(reference, service); + } + }; + threadDaoTracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + agentInfoDaoTracker.close(); + threadDaoTracker.close(); + } +} +
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/osgi/Activator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.thread.client.common.osgi; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -import com.redhat.thermostat.storage.dao.AgentInfoDAO; -import com.redhat.thermostat.thread.client.common.collector.ThreadCollectorFactory; -import com.redhat.thermostat.thread.client.common.collector.internal.ThreadCollectorFactoryImpl; -import com.redhat.thermostat.thread.dao.ThreadDao; - -public class Activator implements BundleActivator { - - private ThreadCollectorFactoryImpl collectorFactory; - private ServiceTracker agentInfoDaoTracker; - private ServiceTracker threadDaoTracker; - - @Override - public void start(final BundleContext context) throws Exception { - - collectorFactory = new ThreadCollectorFactoryImpl(); - context.registerService(ThreadCollectorFactory.class.getName(), collectorFactory, null); - - agentInfoDaoTracker = new ServiceTracker(context, AgentInfoDAO.class.getName(), null) { - @Override - public Object addingService(ServiceReference reference) { - AgentInfoDAO agentDao = (AgentInfoDAO) context.getService(reference); - collectorFactory.setAgentDao(agentDao); - return super.addingService(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - collectorFactory.setAgentDao(null); - context.ungetService(reference); - super.removedService(reference, service); - } - }; - agentInfoDaoTracker.open(); - - threadDaoTracker = new ServiceTracker(context, ThreadDao.class.getName(), null) { - @Override - public Object addingService(ServiceReference reference) { - ThreadDao threadDao = (ThreadDao) context.getService(reference); - collectorFactory.setThreadDao(threadDao); - return super.addingService(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - collectorFactory.setThreadDao(null); - context.ungetService(reference); - super.removedService(reference, service); - } - }; - threadDaoTracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - agentInfoDaoTracker.close(); - threadDaoTracker.close(); - } -} -
--- a/thread/client-controllers/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/thread/client-controllers/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -124,13 +124,12 @@ <configuration> <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-Activator>com.redhat.thermostat.thread.client.controller.osgi.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.thread.client.controller.internal.Activator</Bundle-Activator> <Bundle-SymbolicName>com.redhat.thermostat.thread.client.controller</Bundle-SymbolicName> <Export-Package> com.redhat.thermostat.thread.client.controller </Export-Package> <Private-Package> - com.redhat.thermostat.thread.client.controller.osgi, com.redhat.thermostat.thread.client.controller.internal, com.redhat.thermostat.thread.client.controller.internal.cache, </Private-Package>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/internal/Activator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,116 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.client.controller.internal; + +import com.redhat.thermostat.client.core.InformationService; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; +import com.redhat.thermostat.common.ApplicationService; +import com.redhat.thermostat.common.Constants; +import com.redhat.thermostat.common.MultipleServiceTracker; +import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.storage.core.VmRef; +import com.redhat.thermostat.storage.dao.VmInfoDAO; +import com.redhat.thermostat.thread.client.common.ThreadViewProvider; +import com.redhat.thermostat.thread.client.common.collector.ThreadCollectorFactory; +import com.redhat.thermostat.thread.client.controller.ThreadInformationService; +import com.redhat.thermostat.thread.dao.LockInfoDao; + +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.Map; +import java.util.Objects; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +public class Activator implements BundleActivator { + + @SuppressWarnings({ "rawtypes" }) + @Override + public void start(final BundleContext context) throws Exception { + + Class[] classes = new Class[] { + ThreadCollectorFactory.class, + ApplicationService.class, + VmInfoDAO.class, + LockInfoDao.class, + ThreadViewProvider.class, + ProgressNotifier.class, + }; + + Action action = new Action() { + + private ServiceRegistration registration; + + @Override + public void dependenciesAvailable(Map<String, Object> services) { + ThreadCollectorFactory collectorFactory = (ThreadCollectorFactory) services.get(ThreadCollectorFactory.class.getName()); + ApplicationService applicationService = (ApplicationService) services.get(ApplicationService.class.getName()); + VmInfoDAO vmInfoDao = Objects.requireNonNull((VmInfoDAO) services.get(VmInfoDAO.class.getName())); + LockInfoDao lockInfoDao = Objects.requireNonNull((LockInfoDao) services.get(LockInfoDao.class.getName())); + ThreadViewProvider viewFactory = (ThreadViewProvider) services.get(ThreadViewProvider.class.getName()); + ProgressNotifier notifier = (ProgressNotifier) services.get(ProgressNotifier.class.getName()); + + ThreadInformationService vmInfoService = + new ThreadInformationServiceImpl(applicationService, + vmInfoDao, + lockInfoDao, + collectorFactory, + viewFactory, + notifier); + + Dictionary<String, String> properties = new Hashtable<>(); + properties.put(Constants.GENERIC_SERVICE_CLASSNAME, VmRef.class.getName()); + properties.put(InformationService.KEY_SERVICE_ID, ThreadInformationService.SERVICE_ID); + registration = context.registerService(InformationService.class.getName(), vmInfoService, properties); + } + + @Override + public void dependenciesUnavailable() { + registration.unregister(); + } + }; + + MultipleServiceTracker tracker = new MultipleServiceTracker(context, classes, action); + tracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception {} +} +
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/osgi/Activator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.thread.client.controller.osgi; - -import com.redhat.thermostat.client.core.InformationService; -import com.redhat.thermostat.client.core.progress.ProgressNotifier; -import com.redhat.thermostat.common.ApplicationService; -import com.redhat.thermostat.common.Constants; -import com.redhat.thermostat.common.MultipleServiceTracker; -import com.redhat.thermostat.common.MultipleServiceTracker.Action; -import com.redhat.thermostat.storage.core.VmRef; -import com.redhat.thermostat.storage.dao.VmInfoDAO; -import com.redhat.thermostat.thread.client.common.ThreadViewProvider; -import com.redhat.thermostat.thread.client.common.collector.ThreadCollectorFactory; -import com.redhat.thermostat.thread.client.controller.ThreadInformationService; -import com.redhat.thermostat.thread.client.controller.internal.ThreadInformationServiceImpl; -import com.redhat.thermostat.thread.dao.LockInfoDao; - -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.Map; -import java.util.Objects; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -public class Activator implements BundleActivator { - - @SuppressWarnings({ "rawtypes" }) - @Override - public void start(final BundleContext context) throws Exception { - - Class[] classes = new Class[] { - ThreadCollectorFactory.class, - ApplicationService.class, - VmInfoDAO.class, - LockInfoDao.class, - ThreadViewProvider.class, - ProgressNotifier.class, - }; - - Action action = new Action() { - - private ServiceRegistration registration; - - @Override - public void dependenciesAvailable(Map<String, Object> services) { - ThreadCollectorFactory collectorFactory = (ThreadCollectorFactory) services.get(ThreadCollectorFactory.class.getName()); - ApplicationService applicationService = (ApplicationService) services.get(ApplicationService.class.getName()); - VmInfoDAO vmInfoDao = Objects.requireNonNull((VmInfoDAO) services.get(VmInfoDAO.class.getName())); - LockInfoDao lockInfoDao = Objects.requireNonNull((LockInfoDao) services.get(LockInfoDao.class.getName())); - ThreadViewProvider viewFactory = (ThreadViewProvider) services.get(ThreadViewProvider.class.getName()); - ProgressNotifier notifier = (ProgressNotifier) services.get(ProgressNotifier.class.getName()); - - ThreadInformationService vmInfoService = - new ThreadInformationServiceImpl(applicationService, - vmInfoDao, - lockInfoDao, - collectorFactory, - viewFactory, - notifier); - - Dictionary<String, String> properties = new Hashtable<>(); - properties.put(Constants.GENERIC_SERVICE_CLASSNAME, VmRef.class.getName()); - properties.put(InformationService.KEY_SERVICE_ID, ThreadInformationService.SERVICE_ID); - registration = context.registerService(InformationService.class.getName(), vmInfoService, properties); - } - - @Override - public void dependenciesUnavailable() { - registration.unregister(); - } - }; - - MultipleServiceTracker tracker = new MultipleServiceTracker(context, classes, action); - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception {} -} -
--- a/thread/client-swing/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/thread/client-swing/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -113,12 +113,11 @@ <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.thread.client.swing</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.thread.client.swing.osgi.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.thread.client.swing.internal.Activator</Bundle-Activator> <Export-Package> com.redhat.thermostat.thread.client.swing, </Export-Package> <Private-Package> - com.redhat.thermostat.thread.client.swing.osgi, com.redhat.thermostat.thread.client.swing.internal, com.redhat.thermostat.thread.client.swing.internal.timeline, com.redhat.thermostat.thread.client.swing.internal.timeline.model,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/internal/Activator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,88 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.client.swing.internal; + +import com.redhat.thermostat.client.swing.UIDefaults; +import com.redhat.thermostat.common.MultipleServiceTracker; +import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.thread.client.common.ThreadViewProvider; +import com.redhat.thermostat.thread.client.swing.SwingThreadViewService; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +public class Activator implements BundleActivator { + + private List<ServiceRegistration> regs = new ArrayList<>(); + + @Override + public void start(final BundleContext context) throws Exception { + + Class<?> [] classes = { + UIDefaults.class, + }; + + MultipleServiceTracker tracker = new MultipleServiceTracker(context, classes, new Action() { + @Override + public void dependenciesUnavailable() { + for (ServiceRegistration reg : regs) { + reg.unregister(); + } + regs.clear(); + } + + @Override + public void dependenciesAvailable(Map<String, Object> services) { + + UIDefaults uiDefaults = (UIDefaults) services.get(UIDefaults.class.getName()); + ServiceRegistration reg = context.registerService(ThreadViewProvider.class.getName(), + new SwingThreadViewService(uiDefaults), + null); + regs.add(reg); + } + }); + + tracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception {} +} +
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/osgi/Activator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.thread.client.swing.osgi; - -import com.redhat.thermostat.client.swing.UIDefaults; -import com.redhat.thermostat.common.MultipleServiceTracker; -import com.redhat.thermostat.common.MultipleServiceTracker.Action; -import com.redhat.thermostat.thread.client.common.ThreadViewProvider; -import com.redhat.thermostat.thread.client.swing.SwingThreadViewService; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -public class Activator implements BundleActivator { - - private List<ServiceRegistration> regs = new ArrayList<>(); - - @Override - public void start(final BundleContext context) throws Exception { - - Class<?> [] classes = { - UIDefaults.class, - }; - - MultipleServiceTracker tracker = new MultipleServiceTracker(context, classes, new Action() { - @Override - public void dependenciesUnavailable() { - for (ServiceRegistration reg : regs) { - reg.unregister(); - } - regs.clear(); - } - - @Override - public void dependenciesAvailable(Map<String, Object> services) { - - UIDefaults uiDefaults = (UIDefaults) services.get(UIDefaults.class.getName()); - ServiceRegistration reg = context.registerService(ThreadViewProvider.class.getName(), - new SwingThreadViewService(uiDefaults), - null); - regs.add(reg); - } - }); - - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception {} -} -
--- a/thread/collector/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/thread/collector/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -111,7 +111,7 @@ <configuration> <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-Activator>com.redhat.thermostat.thread.common.osgi.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.thread.internal.Activator</Bundle-Activator> <Bundle-SymbolicName>com.redhat.thermostat.thread.collector</Bundle-SymbolicName> <Export-Package> com.redhat.thermostat.thread.collector, @@ -119,7 +119,7 @@ com.redhat.thermostat.thread.model, </Export-Package> <Private-Package> - com.redhat.thermostat.thread.common.osgi, + com.redhat.thermostat.thread.internal, com.redhat.thermostat.thread.dao.internal, com.redhat.thermostat.thread.dao.internal.statement, </Private-Package>
--- a/thread/collector/src/main/java/com/redhat/thermostat/thread/common/osgi/Activator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.thread.common.osgi; - -import java.util.ArrayList; -import java.util.List; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.util.tracker.ServiceTracker; - -import com.redhat.thermostat.storage.core.Storage; -import com.redhat.thermostat.thread.dao.LockInfoDao; -import com.redhat.thermostat.thread.dao.ThreadDao; -import com.redhat.thermostat.thread.dao.internal.LockInfoDaoImpl; -import com.redhat.thermostat.thread.dao.internal.ThreadDaoImpl; - -public class Activator implements BundleActivator { - - @SuppressWarnings("rawtypes") - private List<ServiceRegistration> registrations = new ArrayList<>(); - - @Override - public void start(BundleContext context) throws Exception { - @SuppressWarnings({ "rawtypes", "unchecked" }) - ServiceTracker tracker = new ServiceTracker(context, Storage.class.getName(), null) { - @Override - public Object addingService(ServiceReference reference) { - Storage storage = (Storage) context.getService(reference); - ThreadDao threadDao = new ThreadDaoImpl(storage); - registrations.add(context.registerService(ThreadDao.class.getName(), threadDao, null)); - return super.addingService(reference); - } - }; - tracker.open(); - - ServiceTracker lockInfoDaoTracker = new ServiceTracker(context, Storage.class.getName(), null) { - @Override - public Object addingService(ServiceReference reference) { - Storage storage = (Storage) context.getService(reference); - LockInfoDao lockInfoDao = new LockInfoDaoImpl(storage); - registrations.add(context.registerService(LockInfoDao.class.getName(), lockInfoDao, null)); - return super.addingService(reference); - } - }; - lockInfoDaoTracker.open(); - - } - - @Override - public void stop(BundleContext context) throws Exception { - for (ServiceRegistration reg : registrations) { - reg.unregister(); - } - } - -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thread/collector/src/main/java/com/redhat/thermostat/thread/internal/Activator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,94 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.internal; + +import java.util.ArrayList; +import java.util.List; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.storage.core.Storage; +import com.redhat.thermostat.thread.dao.LockInfoDao; +import com.redhat.thermostat.thread.dao.ThreadDao; +import com.redhat.thermostat.thread.dao.internal.LockInfoDaoImpl; +import com.redhat.thermostat.thread.dao.internal.ThreadDaoImpl; + +public class Activator implements BundleActivator { + + @SuppressWarnings("rawtypes") + private List<ServiceRegistration> registrations = new ArrayList<>(); + + @Override + public void start(BundleContext context) throws Exception { + @SuppressWarnings({ "rawtypes", "unchecked" }) + ServiceTracker tracker = new ServiceTracker(context, Storage.class.getName(), null) { + @Override + public Object addingService(ServiceReference reference) { + Storage storage = (Storage) context.getService(reference); + ThreadDao threadDao = new ThreadDaoImpl(storage); + registrations.add(context.registerService(ThreadDao.class.getName(), threadDao, null)); + return super.addingService(reference); + } + }; + tracker.open(); + + ServiceTracker lockInfoDaoTracker = new ServiceTracker(context, Storage.class.getName(), null) { + @Override + public Object addingService(ServiceReference reference) { + Storage storage = (Storage) context.getService(reference); + LockInfoDao lockInfoDao = new LockInfoDaoImpl(storage); + registrations.add(context.registerService(LockInfoDao.class.getName(), lockInfoDao, null)); + return super.addingService(reference); + } + }; + lockInfoDaoTracker.open(); + + } + + @Override + public void stop(BundleContext context) throws Exception { + for (ServiceRegistration reg : registrations) { + reg.unregister(); + } + } + +} +
--- a/thread/harvester/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/thread/harvester/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -101,11 +101,10 @@ <configuration> <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-Activator>com.redhat.thermostat.thread.harvester.osgi.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.thread.harvester.Activator</Bundle-Activator> <Bundle-SymbolicName>com.redhat.thermostat.thread.harvester</Bundle-SymbolicName> <Private-Package> com.redhat.thermostat.thread.harvester, - com.redhat.thermostat.thread.harvester.osgi, </Private-Package> <!-- Do not autogenerate uses clauses in Manifests --> <_nouses>true</_nouses>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thread/harvester/src/main/java/com/redhat/thermostat/thread/harvester/Activator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,202 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.harvester; + +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.agent.VmStatusListenerRegistrar; +import com.redhat.thermostat.agent.command.ReceiverRegistry; +import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; +import com.redhat.thermostat.backend.Backend; +import com.redhat.thermostat.common.MultipleServiceTracker; +import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.common.Version; +import com.redhat.thermostat.storage.core.WriterID; +import com.redhat.thermostat.thread.dao.LockInfoDao; +import com.redhat.thermostat.thread.dao.ThreadDao; + +public class Activator implements BundleActivator { + + private ScheduledExecutorService executor = Executors.newScheduledThreadPool(24); + + private MultipleServiceTracker connectionPoolTracker; + private ServiceTracker threadDaoTracker; + private ServiceRegistration backendRegistration; + + private ReceiverRegistry registry; + private ThreadHarvester harvester; + private ThreadBackend backend; + + private MultipleServiceTracker threadCountTracker; + + private MultipleServiceTracker lockInfoTracker; + + @Override + public void start(final BundleContext context) throws Exception { + final Version VERSION = new Version(context.getBundle()); + final VmStatusListenerRegistrar VM_STATUS_REGISTRAR + = new VmStatusListenerRegistrar(context); + + Class<?>[] threadCountDeps = new Class<?>[] { + WriterID.class, + ThreadDao.class, + }; + threadCountTracker = new MultipleServiceTracker(context, threadCountDeps, new Action() { + + private ServiceRegistration<Backend> registration; + + @Override + public void dependenciesAvailable(Map<String, Object> services) { + WriterID writerId = (WriterID) services.get(WriterID.class.getName()); + ThreadDao dao = (ThreadDao) services.get(ThreadDao.class.getName()); + Objects.requireNonNull(dao); + ThreadCountBackend threadCountBackend = new ThreadCountBackend(dao, VERSION, VM_STATUS_REGISTRAR, writerId); + registration = context.registerService(Backend.class, threadCountBackend, null); + } + + @Override + public void dependenciesUnavailable() { + registration.unregister(); + registration = null; + } + }); + threadCountTracker.open(); + + Class<?>[] lockInfoDeps = new Class<?>[] { + WriterID.class, + LockInfoDao.class, + }; + lockInfoTracker = new MultipleServiceTracker(context, lockInfoDeps, new Action() { + + private ServiceRegistration<Backend> registration; + + @Override + public void dependenciesAvailable(Map<String, Object> services) { + WriterID writerId = (WriterID) services.get(WriterID.class.getName()); + LockInfoDao dao = (LockInfoDao) services.get(LockInfoDao.class.getName()); + Objects.requireNonNull(dao); + LockInfoBackend lockInfoBackend = new LockInfoBackend(dao, VERSION, VM_STATUS_REGISTRAR, writerId); + registration = context.registerService(Backend.class, lockInfoBackend, null); + } + + @Override + public void dependenciesUnavailable() { + registration.unregister(); + registration = null; + } + }); + lockInfoTracker.open(); + + Class<?>[] deps = new Class<?>[] { + MXBeanConnectionPool.class, + WriterID.class, + }; + connectionPoolTracker = new MultipleServiceTracker(context, deps, new Action() { + + @Override + public void dependenciesAvailable(Map<String, Object> services) { + MXBeanConnectionPool pool = (MXBeanConnectionPool) services.get(MXBeanConnectionPool.class.getName()); + WriterID writerId = (WriterID) services.get(WriterID.class.getName()); + harvester = new ThreadHarvester(executor, pool, writerId); + } + + @Override + public void dependenciesUnavailable() { + harvester = null; + } + }); + connectionPoolTracker.open(); + + registry = new ReceiverRegistry(context); + + /* + * dont register anything just yet, let the backend handle the + * registration, deregistration it when it's activated or deactivated + */ + + backend = new ThreadBackend(VERSION, VM_STATUS_REGISTRAR, registry, harvester); + backendRegistration = context.registerService(Backend.class, backend, null); + + threadDaoTracker = new ServiceTracker(context, ThreadDao.class.getName(), null) { + @Override + public Object addingService(ServiceReference reference) { + ThreadDao threadDao = (ThreadDao) context.getService(reference); + harvester.setThreadDao(threadDao); + return super.addingService(reference); + } + + @Override + public void removedService(ServiceReference reference, Object service) { + if (harvester != null) { + harvester.setThreadDao(null); + } + context.ungetService(reference); + super.removedService(reference, service); + } + }; + threadDaoTracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + if (backend.isActive()) { + backend.deactivate(); + } + + threadCountTracker.close(); + lockInfoTracker.close(); + + backendRegistration.unregister(); + + connectionPoolTracker.close(); + threadDaoTracker.close(); + + if (executor != null) { + executor.shutdown(); + } + } +} +
--- a/thread/harvester/src/main/java/com/redhat/thermostat/thread/harvester/osgi/Activator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,206 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.thread.harvester.osgi; - -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.util.tracker.ServiceTracker; - -import com.redhat.thermostat.agent.VmStatusListenerRegistrar; -import com.redhat.thermostat.agent.command.ReceiverRegistry; -import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; -import com.redhat.thermostat.backend.Backend; -import com.redhat.thermostat.common.MultipleServiceTracker; -import com.redhat.thermostat.common.MultipleServiceTracker.Action; -import com.redhat.thermostat.common.Version; -import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.thread.dao.LockInfoDao; -import com.redhat.thermostat.thread.dao.ThreadDao; -import com.redhat.thermostat.thread.harvester.LockInfoBackend; -import com.redhat.thermostat.thread.harvester.ThreadBackend; -import com.redhat.thermostat.thread.harvester.ThreadCountBackend; -import com.redhat.thermostat.thread.harvester.ThreadHarvester; - -public class Activator implements BundleActivator { - - private ScheduledExecutorService executor = Executors.newScheduledThreadPool(24); - - private MultipleServiceTracker connectionPoolTracker; - private ServiceTracker threadDaoTracker; - private ServiceRegistration backendRegistration; - - private ReceiverRegistry registry; - private ThreadHarvester harvester; - private ThreadBackend backend; - - private MultipleServiceTracker threadCountTracker; - - private MultipleServiceTracker lockInfoTracker; - - @Override - public void start(final BundleContext context) throws Exception { - final Version VERSION = new Version(context.getBundle()); - final VmStatusListenerRegistrar VM_STATUS_REGISTRAR - = new VmStatusListenerRegistrar(context); - - Class<?>[] threadCountDeps = new Class<?>[] { - WriterID.class, - ThreadDao.class, - }; - threadCountTracker = new MultipleServiceTracker(context, threadCountDeps, new Action() { - - private ServiceRegistration<Backend> registration; - - @Override - public void dependenciesAvailable(Map<String, Object> services) { - WriterID writerId = (WriterID) services.get(WriterID.class.getName()); - ThreadDao dao = (ThreadDao) services.get(ThreadDao.class.getName()); - Objects.requireNonNull(dao); - ThreadCountBackend threadCountBackend = new ThreadCountBackend(dao, VERSION, VM_STATUS_REGISTRAR, writerId); - registration = context.registerService(Backend.class, threadCountBackend, null); - } - - @Override - public void dependenciesUnavailable() { - registration.unregister(); - registration = null; - } - }); - threadCountTracker.open(); - - Class<?>[] lockInfoDeps = new Class<?>[] { - WriterID.class, - LockInfoDao.class, - }; - lockInfoTracker = new MultipleServiceTracker(context, lockInfoDeps, new Action() { - - private ServiceRegistration<Backend> registration; - - @Override - public void dependenciesAvailable(Map<String, Object> services) { - WriterID writerId = (WriterID) services.get(WriterID.class.getName()); - LockInfoDao dao = (LockInfoDao) services.get(LockInfoDao.class.getName()); - Objects.requireNonNull(dao); - LockInfoBackend lockInfoBackend = new LockInfoBackend(dao, VERSION, VM_STATUS_REGISTRAR, writerId); - registration = context.registerService(Backend.class, lockInfoBackend, null); - } - - @Override - public void dependenciesUnavailable() { - registration.unregister(); - registration = null; - } - }); - lockInfoTracker.open(); - - Class<?>[] deps = new Class<?>[] { - MXBeanConnectionPool.class, - WriterID.class, - }; - connectionPoolTracker = new MultipleServiceTracker(context, deps, new Action() { - - @Override - public void dependenciesAvailable(Map<String, Object> services) { - MXBeanConnectionPool pool = (MXBeanConnectionPool) services.get(MXBeanConnectionPool.class.getName()); - WriterID writerId = (WriterID) services.get(WriterID.class.getName()); - harvester = new ThreadHarvester(executor, pool, writerId); - } - - @Override - public void dependenciesUnavailable() { - harvester = null; - } - }); - connectionPoolTracker.open(); - - registry = new ReceiverRegistry(context); - - /* - * dont register anything just yet, let the backend handle the - * registration, deregistration it when it's activated or deactivated - */ - - backend = new ThreadBackend(VERSION, VM_STATUS_REGISTRAR, registry, harvester); - backendRegistration = context.registerService(Backend.class, backend, null); - - threadDaoTracker = new ServiceTracker(context, ThreadDao.class.getName(), null) { - @Override - public Object addingService(ServiceReference reference) { - ThreadDao threadDao = (ThreadDao) context.getService(reference); - harvester.setThreadDao(threadDao); - return super.addingService(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - if (harvester != null) { - harvester.setThreadDao(null); - } - context.ungetService(reference); - super.removedService(reference, service); - } - }; - threadDaoTracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - if (backend.isActive()) { - backend.deactivate(); - } - - threadCountTracker.close(); - lockInfoTracker.close(); - - backendRegistration.unregister(); - - connectionPoolTracker.close(); - threadDaoTracker.close(); - - if (executor != null) { - executor.shutdown(); - } - } -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thread/harvester/src/test/java/com/redhat/thermostat/thread/harvester/ActivatorTest.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,90 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.harvester; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.Version; + +import com.redhat.thermostat.backend.VmUpdateListener; +import com.redhat.thermostat.storage.core.WriterID; +import com.redhat.thermostat.testutils.StubBundleContext; +import com.redhat.thermostat.thread.dao.ThreadDao; + +public class ActivatorTest { + + private Bundle bundle; + private Version version; + private WriterID writerId; + private ThreadDao threadDao; + + @Before + public void setUp() { + version = new Version("0.1.2"); + + bundle = mock(Bundle.class); + when(bundle.getVersion()).thenReturn(version); + + writerId = mock(WriterID.class); + + threadDao = mock(ThreadDao.class); + } + + @Ignore("Activator assumes that Harvester is always registered and fails with NullPointerException") + @Test + public void verifyThreadCountUpdaterIsRegistered() throws Exception { + StubBundleContext bundleContext = new StubBundleContext(); + bundleContext.setBundle(bundle); + + bundleContext.registerService(WriterID.class, writerId, null); + bundleContext.registerService(ThreadDao.class, threadDao, null); + + Activator activator = new Activator(); + + activator.start(bundleContext); + + assertTrue(bundleContext.isServiceRegistered(VmUpdateListener.class.getName(), ThreadCountBackend.class)); + + activator.stop(bundleContext); + } +}
--- a/thread/harvester/src/test/java/com/redhat/thermostat/thread/harvester/osgi/ActivatorTest.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.thread.harvester.osgi; - -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.Version; - -import com.redhat.thermostat.backend.VmUpdateListener; -import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.testutils.StubBundleContext; -import com.redhat.thermostat.thread.dao.ThreadDao; -import com.redhat.thermostat.thread.harvester.ThreadCountBackend; - -public class ActivatorTest { - - private Bundle bundle; - private Version version; - private WriterID writerId; - private ThreadDao threadDao; - - @Before - public void setUp() { - version = new Version("0.1.2"); - - bundle = mock(Bundle.class); - when(bundle.getVersion()).thenReturn(version); - - writerId = mock(WriterID.class); - - threadDao = mock(ThreadDao.class); - } - - @Ignore("Activator assumes that Harvester is always registered and fails with NullPointerException") - @Test - public void verifyThreadCountUpdaterIsRegistered() throws Exception { - StubBundleContext bundleContext = new StubBundleContext(); - bundleContext.setBundle(bundle); - - bundleContext.registerService(WriterID.class, writerId, null); - bundleContext.registerService(ThreadDao.class, threadDao, null); - - Activator activator = new Activator(); - - activator.start(bundleContext); - - assertTrue(bundleContext.isServiceRegistered(VmUpdateListener.class.getName(), ThreadCountBackend.class)); - - activator.stop(bundleContext); - } -}
--- a/vm-gc/remote-collector-client-common/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/vm-gc/remote-collector-client-common/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -114,13 +114,13 @@ <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.gc.remote.client.common</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.gc.remote.client.common.osgi.GCCommandActivator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.gc.remote.client.common.internal.GCCommandActivator</Bundle-Activator> <Export-Package> com.redhat.thermostat.gc.remote.client.common, com.redhat.thermostat.gc.remote.common, </Export-Package> <Private-Package> - com.redhat.thermostat.gc.remote.client.common.osgi, + com.redhat.thermostat.gc.remote.client.common.internal, </Private-Package> <!-- Do not autogenerate uses clauses in Manifests --> <_nouses>true</_nouses>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/client/common/internal/GCCommandActivator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,81 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gc.remote.client.common.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.client.command.RequestQueue; +import com.redhat.thermostat.gc.remote.common.GCRequest; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class GCCommandActivator implements BundleActivator { + + private ServiceTracker tracker; + + @Override + public void start(final BundleContext context) throws Exception { + tracker = new ServiceTracker(context, RequestQueue.class, null) { + @Override + public Object addingService(ServiceReference reference) { + + RequestQueue requestqueue = (RequestQueue) context.getService(reference); + + GCRequest gcRequest = new GCRequest(requestqueue); + context.registerService(GCRequest.class, gcRequest, null); + return super.addingService(reference); + } + + @Override + public void removedService(ServiceReference reference, Object service) { + + context.ungetService(reference); + super.removedService(reference, service); + } + }; + + tracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + tracker.close(); + } +} +
--- a/vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/client/common/osgi/GCCommandActivator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.gc.remote.client.common.osgi; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -import com.redhat.thermostat.client.command.RequestQueue; -import com.redhat.thermostat.gc.remote.common.GCRequest; - -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class GCCommandActivator implements BundleActivator { - - private ServiceTracker tracker; - - @Override - public void start(final BundleContext context) throws Exception { - tracker = new ServiceTracker(context, RequestQueue.class, null) { - @Override - public Object addingService(ServiceReference reference) { - - RequestQueue requestqueue = (RequestQueue) context.getService(reference); - - GCRequest gcRequest = new GCRequest(requestqueue); - context.registerService(GCRequest.class, gcRequest, null); - return super.addingService(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - - context.ungetService(reference); - super.removedService(reference, service); - } - }; - - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - tracker.close(); - } -} -
--- a/vm-gc/remote-collector-command/pom.xml Thu Mar 10 14:50:49 2016 +0100 +++ b/vm-gc/remote-collector-command/pom.xml Tue Apr 19 15:28:00 2016 +0200 @@ -106,12 +106,11 @@ <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.gc.remote.command</Bundle-SymbolicName> - <Bundle-Activator>com.redhat.thermostat.gc.remote.command.osgi.Activator</Bundle-Activator> + <Bundle-Activator>com.redhat.thermostat.gc.remote.command.internal.Activator</Bundle-Activator> <Export-Package> com.redhat.thermostat.gc.remote.command, </Export-Package> <Private-Package> - com.redhat.thermostat.gc.remote.command.osgi, com.redhat.thermostat.gc.remote.command.internal, </Private-Package> <!-- Do not autogenerate uses clauses in Manifests -->
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-gc/remote-collector-command/src/main/java/com/redhat/thermostat/gc/remote/command/internal/Activator.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gc.remote.command.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; + +import com.redhat.thermostat.agent.command.ReceiverRegistry; +import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; +import com.redhat.thermostat.gc.remote.command.GCRequestReceiver; + +public class Activator implements BundleActivator { + + private ServiceTracker tracker; + + @Override + public void start(BundleContext context) throws Exception { + final ReceiverRegistry registry = new ReceiverRegistry(context); + + tracker = new ServiceTracker(context, MXBeanConnectionPool.class, null) { + @Override + public MXBeanConnectionPool addingService(ServiceReference reference) { + MXBeanConnectionPool pool = (MXBeanConnectionPool) super.addingService(reference); + registry.registerReceiver(new GCRequestReceiver(pool)); + return pool; + }; + + @Override + public void removedService(ServiceReference reference, Object service) { + registry.unregisterReceivers(); + super.removedService(reference, service); + }; + }; + tracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + tracker.close(); + } +} +
--- a/vm-gc/remote-collector-command/src/main/java/com/redhat/thermostat/gc/remote/command/osgi/Activator.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.gc.remote.command.osgi; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -import com.redhat.thermostat.agent.command.ReceiverRegistry; -import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; -import com.redhat.thermostat.gc.remote.command.GCRequestReceiver; - -public class Activator implements BundleActivator { - - private ServiceTracker tracker; - - @Override - public void start(BundleContext context) throws Exception { - final ReceiverRegistry registry = new ReceiverRegistry(context); - - tracker = new ServiceTracker(context, MXBeanConnectionPool.class, null) { - @Override - public MXBeanConnectionPool addingService(ServiceReference reference) { - MXBeanConnectionPool pool = (MXBeanConnectionPool) super.addingService(reference); - registry.registerReceiver(new GCRequestReceiver(pool)); - return pool; - }; - - @Override - public void removedService(ServiceReference reference, Object service) { - registry.unregisterReceivers(); - super.removedService(reference, service); - }; - }; - tracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - tracker.close(); - } -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vm-gc/remote-collector-command/src/test/java/com/redhat/thermostat/gc/remote/command/internal/ActivatorTest.java Tue Apr 19 15:28:00 2016 +0200 @@ -0,0 +1,83 @@ +/* + * Copyright 2012-2016 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gc.remote.command.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import org.junit.Before; +import org.junit.Test; + +import com.redhat.thermostat.agent.command.RequestReceiver; +import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; +import com.redhat.thermostat.gc.remote.command.GCRequestReceiver; +import com.redhat.thermostat.testutils.StubBundleContext; + +public class ActivatorTest { + + private StubBundleContext context; + private Activator activator; + + @Before + public void setup() { + context = new StubBundleContext(); + activator = new Activator(); + } + + @Test + public void verifyReceiverRegistered() throws Exception { + MXBeanConnectionPool mxBeanConnectionPool = mock(MXBeanConnectionPool.class); + context.registerService(MXBeanConnectionPool.class, mxBeanConnectionPool, null); + + activator.start(context); + + assertEquals(2, context.getAllServices().size()); + assertTrue(context.isServiceRegistered(RequestReceiver.class.getName(), GCRequestReceiver.class)); + + activator.stop(context); + } + + @Test + public void verifyActivatorDoesNotRegisterServiceOnMissingDeps() throws Exception { + activator.start(context); + + assertEquals(0, context.getAllServices().size()); + + activator.stop(context); + } +}
--- a/vm-gc/remote-collector-command/src/test/java/com/redhat/thermostat/gc/remote/command/osgi/ActivatorTest.java Thu Mar 10 14:50:49 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* - * Copyright 2012-2016 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.gc.remote.command.osgi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import org.junit.Before; -import org.junit.Test; - -import com.redhat.thermostat.agent.command.RequestReceiver; -import com.redhat.thermostat.agent.utils.management.MXBeanConnectionPool; -import com.redhat.thermostat.gc.remote.command.GCRequestReceiver; -import com.redhat.thermostat.testutils.StubBundleContext; - -public class ActivatorTest { - - private StubBundleContext context; - private Activator activator; - - @Before - public void setup() { - context = new StubBundleContext(); - activator = new Activator(); - } - - @Test - public void verifyReceiverRegistered() throws Exception { - MXBeanConnectionPool mxBeanConnectionPool = mock(MXBeanConnectionPool.class); - context.registerService(MXBeanConnectionPool.class, mxBeanConnectionPool, null); - - activator.start(context); - - assertEquals(2, context.getAllServices().size()); - assertTrue(context.isServiceRegistered(RequestReceiver.class.getName(), GCRequestReceiver.class)); - - activator.stop(context); - } - - @Test - public void verifyActivatorDoesNotRegisterServiceOnMissingDeps() throws Exception { - activator.start(context); - - assertEquals(0, context.getAllServices().size()); - - activator.stop(context); - } -}