@Override public void unloadPlugin(GoPluginDescriptor pluginDescriptor) { Bundle bundle = pluginDescriptor.bundle(); if (bundle == null) { return; } for (PluginChangeListener listener : pluginChangeListeners) { try { listener.pluginUnLoaded(pluginDescriptor); } catch (Exception e) { LOGGER.warn("A plugin unload listener ({}) failed: {}", listener.toString(), pluginDescriptor, e); } } try { bundle.stop(); bundle.uninstall(); } catch (Exception e) { throw new RuntimeException("Failed to unload plugin: " + bundle, e); } }
@Test public void shouldUnloadAPlugin() throws BundleException { GoPluginDescriptor pluginDescriptor = mock(GoPluginDescriptor.class); when(pluginDescriptor.bundle()).thenReturn(bundle); spy.unloadPlugin(pluginDescriptor); verify(bundle, atLeastOnce()).stop(); verify(bundle, atLeastOnce()).uninstall(); }
@Test public void shouldNotFailToUnloadAPluginWhenAPluginUnloadListenerFails() throws BundleException { GoPluginDescriptor pluginDescriptor = mock(GoPluginDescriptor.class); when(pluginDescriptor.bundle()).thenReturn(bundle); PluginChangeListener listenerWhichThrowsWhenUnloading = mock(PluginChangeListener.class); doThrow(new RuntimeException("Fail!")).when(listenerWhichThrowsWhenUnloading).pluginUnLoaded(pluginDescriptor); spy.addPluginChangeListener(listenerWhichThrowsWhenUnloading); spy.unloadPlugin(pluginDescriptor); verify(bundle, times(1)).stop(); verify(bundle, times(1)).uninstall(); }
@Test public void shouldRunOtherUnloadListenersEvenIfOneFails() throws BundleException { GoPluginDescriptor pluginDescriptor = mock(GoPluginDescriptor.class); when(pluginDescriptor.bundle()).thenReturn(bundle); PluginChangeListener listenerWhichWorks1 = mock(PluginChangeListener.class, "Listener Which Works: 1"); PluginChangeListener listenerWhichWorks2 = mock(PluginChangeListener.class, "Listener Which Works: 2"); PluginChangeListener listenerWhichThrowsWhenUnloading = mock(PluginChangeListener.class, "Listener Which Throws"); doThrow(new RuntimeException("Fail!")).when(listenerWhichThrowsWhenUnloading).pluginUnLoaded(pluginDescriptor); spy.addPluginChangeListener(listenerWhichWorks1); spy.addPluginChangeListener(listenerWhichThrowsWhenUnloading); spy.addPluginChangeListener(listenerWhichWorks2); spy.unloadPlugin(pluginDescriptor); verify(listenerWhichWorks1, times(1)).pluginUnLoaded(pluginDescriptor); verify(listenerWhichThrowsWhenUnloading, times(1)).pluginUnLoaded(pluginDescriptor); verify(listenerWhichWorks2, times(1)).pluginUnLoaded(pluginDescriptor); verify(bundle, times(1)).stop(); verify(bundle, times(1)).uninstall(); }
private void perform(final String commandLine) throws Exception { if ("shutdown".equals(commandLine)) { context.getBundle(0).stop(); return;
private void perform(final String commandLine) throws Exception { if ("shutdown".equals(commandLine)) { context.getBundle(0).stop(); return; } ByteArrayOutputStream sysOut = new ByteArrayOutputStream(); ByteArrayOutputStream sysErr = new ByteArrayOutputStream(); final PrintStream printStreamOut = new PrintStream(sysOut); final PrintStream printErrOut = new PrintStream(sysErr); try { final CommandSession commandSession = getCommandProcessor().createSession(System.in, printStreamOut, printErrOut); Object result = commandSession.execute(commandLine); if (result != null) { printStreamOut.println(commandSession.format(result, Converter.INSPECT)); } if (sysOut.size() > 0) { LOGGER.log(Level.INFO, new String(sysOut.toByteArray())); } if (sysErr.size() > 0) { LOGGER.log(Level.SEVERE, new String(sysErr.toByteArray())); } } catch (Throwable ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); } finally { printStreamOut.close(); printErrOut.close(); } }
protected void close() { try { if (!closing) { bundleContext.getBundle(0).stop(); } } catch (Exception e) { // Ignore } }
protected void close() { try { if (!closing) { bundleContext.getBundle(0).stop(); } } catch (Exception e) { // Ignore } }
public void windowClosing(WindowEvent e) { try { Activator.context.getBundle().stop(); } catch (BundleException ex) { ex.printStackTrace(); } } });
public void windowClosing(WindowEvent e) { try { context.getBundle().stop(); } catch (BundleException ex) { ex.printStackTrace(); } } });
public void run() { try { getBundleContext().getBundle(0).stop(); } catch (BundleException e) { log.info("Caught exception while shutting down framework: " + e, e); } } }.start();
public void run() { try { if (sleep > 0) { System.err.println("Shutdown in " + sleep/1000/60 + " minute(s)"); } Thread.sleep(sleep); getBundleContext().getBundle(0).stop(); } catch (Exception e) { log.error("Error when shutting down", e); } } }.start();
protected void stopBundle(Bundle bundle) { if (bundle.getState() == Bundle.ACTIVE) { LOG.debug("Stopping bundle %s version %s", bundle.getSymbolicName(), bundle.getVersion()); try { bundle.stop(); } catch (BundleException e) { System.out.println("Failed to start " + bundle.getSymbolicName() + " " + bundle.getVersion() + ". " + e); e.printStackTrace(); } } } }
private void shutdown(final long sleep) { new Thread(() -> { try { sleepWithMsg(sleep, "Shutdown in " + sleep / 1000 / 60 + " minute(s)"); getBundleContext().getBundle(0).stop(); } catch (Exception e) { LOGGER.error("Halt error", e); } }).start(); }
private void shutdown(final long sleep) { new Thread(() -> { try { sleepWithMsg(sleep, "Shutdown in " + sleep / 1000 / 60 + " minute(s)"); getBundleContext().getBundle(0).stop(); } catch (Exception e) { LOGGER.error("Halt error", e); } }).start(); }
private void disableBundle(final Bundle bundle) throws BundleException { if (isBundleStoppable(bundle) && isNotOwnBundle(bundle)) { log.info("Bundle {} disabled by configuration (name={}) ", bundle.getSymbolicName(), bundle.getBundleId()); bundle.stop(); } }
public void restart(String bundleId) throws MBeanException { try { List<Bundle> bundles = selectBundles(bundleId); for (Bundle bundle : bundles) { bundle.stop(); bundle.start(); } } catch (Exception e) { throw new MBeanException(null, e.toString()); } }
public void stop(String bundleId) throws MBeanException { try { List<Bundle> bundles = selectBundles(bundleId); for (Bundle bundle : bundles) { bundle.stop(); } } catch (Exception e) { throw new MBeanException(null, e.toString()); } }
public static Bundle installOrStopBundle(BundleContext bundleContext, String bsn, String url) throws BundleException { Bundle bundle = findBundle(bundleContext, bsn); if (bundle == null) { bundle = bundleContext.installBundle(url); } if (bundle.getState() == Bundle.ACTIVE) { bundle.stop(); } return bundle; }
@Override public synchronized void disablePlugin(PluginMetadata pluginMetadata) { try { felix.getBundleContext().getBundle(pluginMetadata.getId()).stop(); logger.warning("Stopped bundle " + pluginMetadata.getName()); } catch (BundleException e) { logger.log(Level.SEVERE, "Failed to stop plugin " + pluginMetadata.getName(), e); throw new PluginManagementException(e); } }