in features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java [189:254]
public void uninstallFeature(String groupName, String name, String version, boolean noRefresh) throws Exception {
// check if the group exists
Group group = groupManager.findGroupByName(groupName);
if (group == null) {
throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist");
}
// check if the producer is ON
if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
throw new IllegalStateException("Cluster event producer is OFF");
}
// check if the feature is allowed outbound
CellarSupport support = new CellarSupport();
support.setClusterManager(this.clusterManager);
support.setGroupManager(this.groupManager);
support.setConfigurationAdmin(this.configurationAdmin);
if (!support.isAllowed(group, Constants.CATEGORY, name, EventType.OUTBOUND)) {
throw new IllegalArgumentException("Feature " + name + " is blocked outbound for cluster group " + groupName);
}
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
// get the features in the cluster group
Map<String, FeatureState> clusterFeatures = clusterManager.getMap(Constants.FEATURES_MAP + Configurations.SEPARATOR + groupName);
// check if the feature exist
FeatureState feature = null;
String key = null;
for (String k : clusterFeatures.keySet()) {
FeatureState state = clusterFeatures.get(k);
key = k;
if (version == null) {
if (state.getName().equals(name)) {
feature = state;
break;
}
} else {
if (state.getName().equals(name) && state.getVersion().equals(version)) {
feature = state;
break;
}
}
}
if (feature == null) {
if (version == null)
throw new IllegalArgumentException("Feature " + name + " doesn't exist in cluster group " + groupName);
else
throw new IllegalArgumentException("Feature " + name + "/" + version + " doesn't exist in cluster group " + groupName);
}
// update the cluster group
feature.setInstalled(false);
clusterFeatures.put(key, feature);
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
// broadcast the cluster event
ClusterFeaturesEvent event = new ClusterFeaturesEvent(name, version, noRefresh, false, false, false, FeatureEvent.EventType.FeatureUninstalled);
event.setSourceGroup(group);
eventProducer.produce(event);
}