本文整理汇总了Java中org.apache.karaf.features.Feature类的典型用法代码示例。如果您正苦于以下问题:Java Feature类的具体用法?Java Feature怎么用?Java Feature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Feature类属于org.apache.karaf.features包,在下文中一共展示了Feature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: installAppFeatures
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private synchronized boolean installAppFeatures(Application app) throws Exception {
boolean changed = false;
for (String name : app.features()) {
Feature feature = featuresService.getFeature(name);
// If we see an attempt at activation of a non-existent feature
// attempt to install the app artifacts first and then retry.
// This can be triggered by a race condition between different ONOS
// instances "installing" the apps from disk at their own pace.
// Perhaps there is a more elegant solution to be explored in the
// future.
if (feature == null) {
installAppArtifacts(app);
feature = featuresService.getFeature(name);
}
if (feature != null && !featuresService.isInstalled(feature)) {
featuresService.installFeature(name);
changed = true;
} else if (feature == null) {
log.warn("Feature {} not found", name);
}
}
return changed;
}
示例2: FeatureConfigSnapshotHolder
import org.apache.karaf.features.Feature; //导入依赖的package包/类
public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo,
final Feature feature) throws JAXBException, XMLStreamException {
Preconditions.checkNotNull(fileInfo);
Preconditions.checkNotNull(fileInfo.getFinalname());
Preconditions.checkNotNull(feature);
this.fileInfo = fileInfo;
this.featureChain.add(feature);
// TODO extract utility method for umarshalling config snapshots
JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class);
Unmarshaller um = jaxbContext.createUnmarshaller();
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
}
示例3: getChildFeatures
import org.apache.karaf.features.Feature; //导入依赖的package包/类
public Set<? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
List<Dependency> dependencies = feature.getDependencies();
Set<ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
Feature fi = extractFeatureFromDependency(dependency);
if (fi != null) {
if (featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi
.getVersion());
} else {
ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService);
childFeatures.add(wrappedFeature);
}
}
}
}
return childFeatures;
}
示例4: extractFeatureFromDependency
import org.apache.karaf.features.Feature; //导入依赖的package包/类
protected Feature extractFeatureFromDependency(final Dependency dependency) throws Exception {
Feature[] features = featuresService.listFeatures();
VersionRange range = org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency
.getVersion()) ? VersionRange.ANY_VERSION : new VersionRange(dependency.getVersion(), true, true);
Feature fi = null;
for (Feature f : features) {
if (f.getName().equals(dependency.getName())) {
Version version = VersionTable.getVersion(f.getVersion());
if (range.contains(version) && (fi == null || VersionTable.getVersion(fi.getVersion())
.compareTo(version) < 0)) {
fi = f;
break;
}
}
}
return fi;
}
示例5: addingService
import org.apache.karaf.features.Feature; //导入依赖的package包/类
@Override
@SuppressWarnings("IllegalCatch")
public FeaturesService addingService(final ServiceReference<FeaturesService> reference) {
BundleContext bc = reference.getBundle().getBundleContext();
final FeaturesService featureService = bc.getService(reference);
final Optional<XmlFileStorageAdapter> currentPersister = XmlFileStorageAdapter.getInstance();
if (XmlFileStorageAdapter.getInstance().isPresent()) {
final Set<String> installedFeatureIds = Sets.newHashSet();
try {
for (final Feature installedFeature : featureService.listInstalledFeatures()) {
installedFeatureIds.add(installedFeature.getId());
}
} catch (final Exception e) {
LOG.error("Error listing installed features", e);
}
currentPersister.get().setFeaturesService(() -> installedFeatureIds);
}
ConfigFeaturesListener configFeaturesListener = new ConfigFeaturesListener(configPusher, featureService);
registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null);
return featureService;
}
示例6: pushConfig
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private Set<FeatureConfigSnapshotHolder> pushConfig(final Set<FeatureConfigSnapshotHolder> configs,
final Feature feature) throws InterruptedException {
Set<FeatureConfigSnapshotHolder> configsToPush = new LinkedHashSet<>(configs);
configsToPush.removeAll(pushedConfigs);
if (!configsToPush.isEmpty()) {
// Ignore features that are present in persisted current config
final Optional<XmlFileStorageAdapter> currentCfgPusher = XmlFileStorageAdapter.getInstance();
if (currentCfgPusher.isPresent() && currentCfgPusher.get().getPersistedFeatures()
.contains(feature.getId())) {
LOG.warn("Ignoring default configuration {} for feature {}, the configuration is present in {}",
configsToPush, feature.getId(), currentCfgPusher.get());
} else {
pusher.pushConfigs(new ArrayList<>(configsToPush));
}
pushedConfigs.addAll(configsToPush);
}
Set<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
configsPushed.retainAll(configs);
return configsPushed;
}
示例7: isInstalled
import org.apache.karaf.features.Feature; //导入依赖的package包/类
@SuppressWarnings("IllegalCatch")
private boolean isInstalled(final Feature feature) throws InterruptedException {
for (int retries = 0; retries < MAX_RETRIES; retries++) {
try {
List<Feature> installedFeatures = Arrays.asList(featuresService.listInstalledFeatures());
if (installedFeatures.contains(feature)) {
return true;
}
LOG.info("Karaf Feature Service has not yet finished installing feature {}/{} (retry {})", feature
.getName(), feature.getVersion(), retries);
} catch (final Exception e) {
LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e);
}
TimeUnit.MILLISECONDS.sleep(RETRY_PAUSE_MILLIS);
}
LOG.error("Giving up (after {} retries) on Karaf featuresService.listInstalledFeatures() which has not yet "
+ "finished installing feature {} {}", MAX_RETRIES, feature.getName(), feature.getVersion());
return false;
}
示例8: uninstallNewFeatures
import org.apache.karaf.features.Feature; //导入依赖的package包/类
/**
* The feature service does not uninstall feature dependencies when uninstalling a single feature.
* So we need to make sure we uninstall all features that were newly installed.
*
* @param featuresBefore
* @throws Exception
*/
protected void uninstallNewFeatures(Set<Feature> featuresBefore)
throws Exception {
Feature[] features = featureService.listInstalledFeatures();
for (Feature curFeature : features) {
if (!featuresBefore.contains(curFeature)) {
try {
System.out.println("Uninstalling " + curFeature.getName());
featureService.uninstallFeature(curFeature.getName(), curFeature.getVersion(),
EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
示例9: installNexusEdition
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private static void installNexusEdition(final BundleContext ctx, @Nullable final String editionName)
throws Exception
{
if (editionName != null && editionName.length() > 0) {
final ServiceTracker<?, FeaturesService> tracker = new ServiceTracker<>(ctx, FeaturesService.class, null);
tracker.open();
try {
FeaturesService featuresService = tracker.waitForService(1000);
Feature editionFeature = featuresService.getFeature(editionName);
log.info("Installing: {}", editionFeature);
// edition might already be installed in the cache; if so then skip installation
if (!featuresService.isInstalled(editionFeature)) {
// avoid auto-refreshing bundles as that could trigger unwanted restart/lifecycle events
EnumSet<Option> options = EnumSet.of(NoAutoRefreshBundles, NoAutoRefreshManagedBundles);
featuresService.installFeature(editionFeature.getId(), options);
}
log.info("Installed: {}", editionFeature);
}
finally {
tracker.close();
}
}
}
示例10: getFeaturesReport
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private String getFeaturesReport( FeaturesService featuresService, List<String> uninstalledFeatures )
throws Exception {
ServiceReference<BundleService> serviceReferenceBundleService =
bundleContext.getServiceReference( BundleService.class );
BundleService bundleService = bundleContext.getService( serviceReferenceBundleService );
List<BundleStateService> bundleStateServices = getBundleStateServices();
String featuresReport = System.lineSeparator() + "--------- Karaf Feature Watcher Report Begin ---------";
for ( String uninstalledFeature : uninstalledFeatures ) {
Feature feature = featuresService.getFeature( uninstalledFeature );
featuresReport +=
System.lineSeparator() + getFeatureReport( featuresService, bundleService, bundleStateServices, feature );
}
return featuresReport + System.lineSeparator() + "--------- Karaf Feature Watcher Report End ---------";
}
示例11: createMockFeature
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private Dependency createMockFeature( String name, String version, boolean installed, List<Dependency> dependencies,
List<BundleInfo> bundles, FeaturesService featuresService ) throws Exception {
Feature feature = mock( Feature.class );
when( feature.getName() ).thenReturn( name );
when( featuresService.getFeature( name ) ).thenReturn( feature );
if ( version != null ) {
when( feature.hasVersion() ).thenReturn( true );
when( feature.getVersion() ).thenReturn( version );
when( featuresService.getFeature( name, version ) ).thenReturn( feature );
} else {
when( feature.hasVersion() ).thenReturn( false );
}
when( feature.getDependencies() ).thenReturn( dependencies );
when( feature.getBundles() ).thenReturn( bundles );
when( featuresService.isInstalled( feature ) ).thenReturn( installed );
Dependency dependency = mock( Dependency.class );
when( dependency.getName() ).thenReturn( name );
when( dependency.getVersion() ).thenReturn( version );
return dependency;
}
示例12: validateBundlesAvailable
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private void validateBundlesAvailable(Repository repository) throws Exception {
for (Feature feature : repository.getFeatures()) {
for (String bundle : getBundleLocations(feature)) {
if (!isMavenProtocol(bundle) && skipNonMavenProtocols) {
continue;
}
// this will throw an exception if the artifact can not be resolved
final Object artifact = resolve(bundle);
bundles.put(bundle, artifact);
if (isBundle(bundle, artifact)) {
manifests.put(artifact, getManifest(bundle, artifact));
} else {
throw new Exception(String.format("%s is not an OSGi bundle", bundle));
}
}
}
}
示例13: getDependencyFeatureExports
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private Set<Clause> getDependencyFeatureExports(Feature feature) throws Exception {
Set<Clause> exports = new HashSet<Clause>();
for (Dependency dependency : feature.getDependencies()) {
if (featureExports.containsKey(dependency.getName())) {
exports.addAll(featureExports.get(dependency.getName()));
} else {
validateImportsExports(features.get(dependency.getName(), dependency.getVersion()));
exports.addAll(featureExports.get(dependency.getName()));
}
exports.addAll(getDependencyFeatureExports(features.get(dependency.getName(), dependency.getVersion())));
}
// add the export of the feature
for (String bundle : getBundleLocations(feature)) {
Manifest meta = manifests.get(bundles.get(bundle));
exports.addAll(getExports(meta));
}
return exports;
}
示例14: getBundleLocations
import org.apache.karaf.features.Feature; //导入依赖的package包/类
private Set<String> getBundleLocations(Application app) {
Set<String> locations = new HashSet<>();
for (String name : app.features()) {
try {
Feature feature = featuresService.getFeature(name);
locations.addAll(
feature.getBundles().stream().map(BundleInfo::getLocation).collect(Collectors.toList()));
} catch (Exception e) {
return locations;
}
}
return locations;
}
示例15: isFullyStarted
import org.apache.karaf.features.Feature; //导入依赖的package包/类
/**
* Scans the system to make sure that all bundles and their components
* are fully started.
*
* @return true if all bundles and their components are active
*/
private boolean isFullyStarted() {
for (Feature feature : featuresService.listInstalledFeatures()) {
if (!isFullyStarted(feature)) {
return false;
}
}
return true;
}