本文整理了Java中org.osgi.framework.Bundle.uninstall()
方法的一些代码示例,展示了Bundle.uninstall()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.uninstall()
方法的具体详情如下:
包路径:org.osgi.framework.Bundle
类名称:Bundle
方法名:uninstall
[英]Uninstalls this bundle.
This method causes the Framework to notify other bundles that this bundle is being uninstalled, and then puts this bundle into the UNINSTALLED state. The Framework must remove any resources related to this bundle that it is able to remove.
If this bundle has exported any packages, the Framework must continue to make these packages available to their importing bundles until the FrameworkWiring#refreshBundles(java.util.Collection,FrameworkListener...) method has been called or the Framework is relaunched.
The following steps are required to uninstall a bundle:
getState() not in { UNINSTALLED }.
Postconditions, no exceptions thrown
getState() in { UNINSTALLED }.
This bundle has been uninstalled.
Postconditions, when an exception is thrown
getState() not in { UNINSTALLED }.
This Bundle has not been uninstalled.
[中]卸载此捆绑包。
此方法使框架通知其他捆绑包此捆绑包正在卸载,然后将此捆绑包置于卸载状态。框架必须删除它能够删除的与此捆绑包相关的任何资源。
如果此捆绑包已导出任何包,则框架必须继续使这些包对其导入捆绑包可用,直到FrameworkWiring#refreshBundles(java.util.Collection,FrameworkListener…)方法或重新启动框架。
卸载捆绑包需要以下步骤:
1.如果此捆绑包的状态已卸载,则会引发IllegalStateException。
1.如果此捆绑包的状态为活动、启动或停止,则此捆绑包将按照捆绑包中的说明停止。停止方法。如果捆绑。stop引发异常,将触发包含该异常的FrameworkEvent#ERROR类型的框架事件。
1.此捆绑包的状态设置为“已卸载”。
1.触发BundleEvent#UNINSTALLED类型的bundle事件。
1.此捆绑包和框架为此捆绑包提供的任何持久存储区域都将被删除。
前提条件
*getState()不在{unnstalled}中。
后置条件,没有抛出异常
*{UNINSTALLED}中的getState()。
*此捆绑包已卸载。
引发异常时的后置条件
*getState()不在{unnstalled}中。
*此捆绑包尚未卸载。
代码示例来源: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
@Override
public InstallOrUpgradeStatus removeAddOn(BundleSymbolicName bsn) {
synchronized (mutex) {
InstallOrUpgradeStatus status;
try {
Validate.notNull(bsn, "Bundle symbolic name required");
bsn.findBundleWithoutFail(context).uninstall();
LOGGER.log(Level.INFO, String.format("Bundle '%s' : Uninstalled!", bsn.getKey()));
LOGGER.log(Level.INFO, "");
status = InstallOrUpgradeStatus.SUCCESS;
return status;
} catch (BundleException e) {
LOGGER.warning("Unable to remove add-on: " + bsn.getKey());
status = InstallOrUpgradeStatus.FAILED;
return status;
}
}
}
代码示例来源:origin: spring-projects/spring-roo
b.uninstall();
代码示例来源:origin: apache/aries
public void uninstall(Bundle b) throws BundleException
{
b.uninstall();
_bundles.remove(b);
}
}
代码示例来源:origin: org.protege/protege-editor-core-application
public void uninstallPlugins() {
for (Bundle bundle : plugins) {
try {
bundle.uninstall();
}
catch (Throwable t) {
if (logger.isDebugEnabled()) {
logger.debug("Exception caught uninstalling the bundle", t);
}
}
}
}
代码示例来源:origin: org.apache.stratos/org.apache.stratos.adc.mgt
@Override
public void run() {
try {
bundleContext.getBundle().uninstall();
} catch (Throwable e) {
log.warn("Error occurred while uninstalling hosting.mgt UI bundle", e);
}
}
};
代码示例来源:origin: org.apache.geronimo.framework/geronimo-bundle-recorder
private void uninstallBundle(Bundle bundle) {
try {
bundle.uninstall();
} catch (BundleException e) {
log.error("Bundle " + bundle.getBundleId() + " failed to uninstall: " + e.getMessage());
}
}
代码示例来源:origin: apache/felix
public void tryUninstall() throws BundleException
{
// only install if _we_ loaded the driver
if ( !isInUse() && m_dynamic )
{
m_bundle.uninstall();
}
}
代码示例来源:origin: com.yahoo.vespa/jdisc_core
public void stopAndUninstall(Iterable<Bundle> bundles) throws BundleException {
for (Bundle bundle : bundles) {
stop(bundle);
}
for (Bundle bundle : bundles) {
bundle.uninstall();
}
}
代码示例来源:origin: org.glassfish.hk2/osgi-adapter
public void uninstall() {
// This method is called when the hk2-osgi-adapter module is stopped.
// During that time, we need to stop all the modules, hence no sticky check is
// performed in this method.
try {
bundle.uninstall();
} catch (BundleException e) {
throw new RuntimeException(e);
}
registry.remove(this);
this.registry = null;
}
代码示例来源:origin: com.sun.enterprise/osgi-adapter
public void uninstall() {
// This method is called when the hk2-osgi-adapter module is stopped.
// During that time, we need to stop all the modules, hence no sticky check is
// performed in this method.
try {
bundle.uninstall();
} catch (BundleException e) {
throw new RuntimeException(e);
}
registry.remove(this);
this.registry = null;
}
代码示例来源:origin: apache/karaf
public void uninstall(String bundleId) throws MBeanException {
try {
List<Bundle> bundles = selectBundles(bundleId);
for (Bundle bundle : bundles) {
bundle.uninstall();
}
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
代码示例来源:origin: org.apache.karaf.bundle/org.apache.karaf.bundle.core
public void uninstall(String bundleId) throws MBeanException {
try {
List<Bundle> bundles = selectBundles(bundleId);
for (Bundle bundle : bundles) {
bundle.uninstall();
}
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
代码示例来源:origin: org.ops4j.pax.exam/pax-exam-container-native
@Override
public synchronized void uninstallProbe() {
Bundle bundle = framework.getBundleContext().getBundle(probeId);
try {
bundle.uninstall();
probeId = null;
}
catch (BundleException exc) {
throw new TestContainerException(exc);
}
}
}
代码示例来源:origin: org.wisdom-framework/wisdom-monitor
@Override
public Result call() throws Exception {
try {
logger().info("Uninstalling bundle {}", bundle.getSymbolicName());
bundle.uninstall();
return ok();
} catch (BundleException e) {
logger().error("Cannot uninstall bundle {}", bundle.getSymbolicName(), e);
return badRequest(e);
}
}
});
代码示例来源:origin: apache/aries
private void uninstall(ApplicationContextImpl app)
{
Set<Bundle> bundles = app.getApplicationContent();
for (Bundle b : bundles) {
try {
b.uninstall();
} catch (BundleException be) {
// TODO ignoring this feels wrong, but I'm not sure how to communicate to the caller multiple failures.
}
}
app.setState(ApplicationState.UNINSTALLED);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testUninstallAndReinstallBundle() throws Exception {
Bundle bundle = installFromClasspath(BROOKLYN_OSGI_TEST_A_0_1_0_PATH);
checkMath(bundle, 3, 6);
setAMultiplier(bundle, 3);
checkMath(bundle, 3, 9);
bundle.uninstall();
Bundle bundle2 = installFromClasspath(BROOKLYN_OSGI_TEST_A_0_1_0_PATH);
checkMath(bundle2, 3, 6);
}
内容来源于网络,如有侵权,请联系作者删除!