org.osgi.framework.Bundle.stop()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中org.osgi.framework.Bundle.stop()方法的一些代码示例,展示了Bundle.stop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.stop()方法的具体详情如下:
包路径:org.osgi.framework.Bundle
类名称:Bundle
方法名:stop

Bundle.stop介绍

[英]Stops this bundle with no options.

This method performs the same function as calling stop(0).
[中]停止此捆绑包,但没有任何选项。
此方法执行与调用stop(0)相同的功能。

代码示例

代码示例来源:origin: gocd/gocd

@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);
  }
}

代码示例来源:origin: gocd/gocd

@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();
}

代码示例来源:origin: gocd/gocd

@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();
}

代码示例来源:origin: gocd/gocd

@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();
}

代码示例来源:origin: spring-projects/spring-roo

private void perform(final String commandLine) throws Exception {
 if ("shutdown".equals(commandLine)) {
  context.getBundle(0).stop();
  return;

代码示例来源:origin: spring-projects/spring-roo

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();
 }
}

代码示例来源:origin: apache/karaf

protected void close() {
  try {
    if (!closing) {
      bundleContext.getBundle(0).stop();
    }
  } catch (Exception e) {
    // Ignore
  }
}

代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.core

protected void close() {
  try {
    if (!closing) {
      bundleContext.getBundle(0).stop();
    }
  } catch (Exception e) {
    // Ignore
  }
}

代码示例来源:origin: apache/felix

public void windowClosing(WindowEvent e) 
  {
    try {
      Activator.context.getBundle().stop();
    } catch (BundleException ex) {
      ex.printStackTrace();
    }
  }
});

代码示例来源:origin: apache/felix

public void windowClosing(WindowEvent e) 
  {
    try {
      context.getBundle().stop();
    } catch (BundleException ex) {
      ex.printStackTrace();
    }
  }
});

代码示例来源:origin: org.apache.servicemix.kernel.gshell/org.apache.servicemix.kernel.gshell.core

public void run() {
    try {
      getBundleContext().getBundle(0).stop();
    } catch (BundleException e) {
      log.info("Caught exception while shutting down framework: " + e, e);
    }
  }
}.start();

代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.osgi

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();

代码示例来源:origin: io.fabric8.fab/fab-osgi

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();
      }
    }
  }
}

代码示例来源:origin: org.apache.karaf.system/org.apache.karaf.system.core

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();
}

代码示例来源:origin: apache/karaf

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();
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

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();
  }
}

代码示例来源:origin: apache/karaf

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());
  }
}

代码示例来源:origin: apache/karaf

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());
  }
}

代码示例来源:origin: org.fusesource.fabric/fabric-utils

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;
}

代码示例来源:origin: org.aperteworkflow/integration

@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);
  }
}

相关文章