Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@
import org.apache.karaf.features.internal.repository.XmlRepository;
import org.apache.karaf.features.internal.resolver.Slf4jResolverLog;
import org.apache.karaf.features.internal.service.BootFeaturesInstaller;
import org.apache.karaf.features.internal.service.BootManaged;
import org.apache.karaf.features.internal.service.EventAdminListener;
import org.apache.karaf.features.internal.service.FeatureConfigInstaller;
import org.apache.karaf.features.internal.service.FeatureRepoFinder;
import org.apache.karaf.features.internal.service.FeaturesServiceConfig;
import org.apache.karaf.features.internal.service.FeaturesServiceImpl;
import org.apache.karaf.features.internal.service.SimpleFeaturesServiceImpl;
import org.apache.karaf.features.internal.service.BundleInstallSupport;
import org.apache.karaf.features.internal.service.BundleInstallSupportImpl;
import org.apache.karaf.features.internal.service.StateStorage;
Expand Down Expand Up @@ -101,6 +103,7 @@ public class Activator extends BaseActivator {

private ServiceTracker<FeaturesListener, FeaturesListener> featuresListenerTracker;
private FeaturesServiceImpl featuresService;
private SimpleFeaturesServiceImpl simpleFeaturesService;
private StandardManageableRegionDigraph digraphMBean;
private BundleInstallSupport installSupport;
private ExecutorService executorService;
Expand Down Expand Up @@ -182,36 +185,64 @@ protected void doStart() throws Exception {
Repository globalRepository = getGlobalRepository();
FeaturesServiceConfig cfg = getConfig();
StateStorage stateStorage = createStateStorage();
featuresService = new FeaturesServiceImpl(
stateStorage,
featureFinder,
configurationAdmin,
resolver,
installSupport,
globalRepository,
cfg);
try {
EventAdminListener eventAdminListener = new EventAdminListener(bundleContext);
featuresService.registerListener(eventAdminListener);
} catch (Throwable t) {
// No EventAdmin support in this case

boolean useSimpleResolver = getBoolean("resolverSimple", false);
FeaturesService registeredService;

if (useSimpleResolver) {
simpleFeaturesService = new SimpleFeaturesServiceImpl(
stateStorage,
featureFinder,
configurationAdmin,
installSupport,
cfg);
try {
EventAdminListener eventAdminListener = new EventAdminListener(bundleContext);
simpleFeaturesService.registerListener(eventAdminListener);
} catch (Throwable t) {
// No EventAdmin support in this case
}
registeredService = simpleFeaturesService;
} else {
featuresService = new FeaturesServiceImpl(
stateStorage,
featureFinder,
configurationAdmin,
resolver,
installSupport,
globalRepository,
cfg);
try {
EventAdminListener eventAdminListener = new EventAdminListener(bundleContext);
featuresService.registerListener(eventAdminListener);
} catch (Throwable t) {
// No EventAdmin support in this case
}
registeredService = featuresService;
}
register(FeaturesService.class, featuresService);
register(FeaturesService.class, registeredService);

featuresListenerTracker = createFeatureListenerTracker();
featuresListenerTracker = createFeatureListenerTracker(registeredService);
featuresListenerTracker.open();

FeaturesServiceMBeanImpl featuresServiceMBean = new FeaturesServiceMBeanImpl();
featuresServiceMBean.setBundleContext(bundleContext);
featuresServiceMBean.setFeaturesService(featuresService);
featuresServiceMBean.setFeaturesService(registeredService);
registerMBean(featuresServiceMBean, "type=feature");

String[] featuresRepositories = getStringArray("featuresRepositories", "");
String featuresBoot = getString("featuresBoot", "");
boolean featuresBootAsynchronous = getBoolean("featuresBootAsynchronous", false);
BootFeaturesInstaller bootFeaturesInstaller = new BootFeaturesInstaller(
bundleContext, featuresService, new SystemExitManager(),
featuresRepositories, featuresBoot, featuresBootAsynchronous);
BootFeaturesInstaller bootFeaturesInstaller;
if (useSimpleResolver) {
bootFeaturesInstaller = new BootFeaturesInstaller(
bundleContext, simpleFeaturesService, (BootManaged) simpleFeaturesService,
new SystemExitManager(), featuresRepositories, featuresBoot, featuresBootAsynchronous);
} else {
bootFeaturesInstaller = new BootFeaturesInstaller(
bundleContext, featuresService, new SystemExitManager(),
featuresRepositories, featuresBoot, featuresBootAsynchronous);
}
bootFeaturesInstaller.start();
}

Expand Down Expand Up @@ -305,26 +336,26 @@ private void registerRegionDiGraph(StandardRegionDigraph dg) throws BundleExcept
DigraphHelper.verifyUnmanagedBundles(bundleContext, dg);
}

private ServiceTracker<FeaturesListener, FeaturesListener> createFeatureListenerTracker() {
private ServiceTracker<FeaturesListener, FeaturesListener> createFeatureListenerTracker(FeaturesService service) {
return new ServiceTracker<>(
bundleContext,
FeaturesListener.class,
new ServiceTrackerCustomizer<FeaturesListener, FeaturesListener>() {
@Override
public FeaturesListener addingService(ServiceReference<FeaturesListener> reference) {
FeaturesListener service = bundleContext.getService(reference);
featuresService.registerListener(service);
return service;
FeaturesListener listener = bundleContext.getService(reference);
service.registerListener(listener);
return listener;
}

@Override
public void modifiedService(ServiceReference<FeaturesListener> reference, FeaturesListener service) {
public void modifiedService(ServiceReference<FeaturesListener> reference, FeaturesListener listener) {
}

@Override
public void removedService(ServiceReference<FeaturesListener> reference, FeaturesListener service) {
if (featuresService != null && service != null) {
featuresService.unregisterListener(service);
public void removedService(ServiceReference<FeaturesListener> reference, FeaturesListener listener) {
if (service != null && listener != null) {
service.unregisterListener(listener);
}
if (bundleContext != null && reference != null) {
bundleContext.ungetService(reference);
Expand All @@ -348,6 +379,10 @@ protected void doStop() {
featuresService.stop();
featuresService = null;
}
if (simpleFeaturesService != null) {
simpleFeaturesService.stop();
simpleFeaturesService = null;
}
if (installSupport != null) {
installSupport.unregister();
installSupport.saveDigraph();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public class BootFeaturesInstaller {
private static final Logger LOGGER = LoggerFactory.getLogger(BootFeaturesInstaller.class);
private static final String REQUIRE_SUCCESSFUL_BOOT = "karaf.require.successful.features.boot";

private final FeaturesServiceImpl featuresService;
private final FeaturesService featuresService;
private final BootManaged bootManaged;
private final BundleContext bundleContext;
private final ExitManager exitManager;
private final String[] repositories;
private final String features;
private final boolean asynchronous;

/**
* The Unix separator character.
*/
Expand All @@ -53,7 +54,7 @@ public class BootFeaturesInstaller {
* The system separator character.
*/
private static final char SYSTEM_SEPARATOR = File.separatorChar;

public BootFeaturesInstaller(BundleContext bundleContext,
FeaturesServiceImpl featuresService,
ExitManager exitManager,
Expand All @@ -62,6 +63,23 @@ public BootFeaturesInstaller(BundleContext bundleContext,
boolean asynchronous) {
this.bundleContext = bundleContext;
this.featuresService = featuresService;
this.bootManaged = featuresService;
this.exitManager = exitManager;
this.repositories = repositories;
this.features = features;
this.asynchronous = asynchronous;
}

public BootFeaturesInstaller(BundleContext bundleContext,
FeaturesService featuresService,
BootManaged bootManaged,
ExitManager exitManager,
String[] repositories,
String features,
boolean asynchronous) {
this.bundleContext = bundleContext;
this.featuresService = featuresService;
this.bootManaged = bootManaged;
this.exitManager = exitManager;
this.repositories = repositories;
this.features = features;
Expand All @@ -72,7 +90,7 @@ public BootFeaturesInstaller(BundleContext bundleContext,
* Install boot features
*/
public void start() {
if (featuresService.isBootDone()) {
if (bootManaged.isBootDone()) {
publishBootFinished();
return;
}
Expand Down Expand Up @@ -104,7 +122,7 @@ protected void installBootFeatures(boolean quitIfUnsuccessful) {
}
featuresService.installFeatures(features, options);
}
featuresService.bootDone();
bootManaged.bootDone();
publishBootFinished();
} catch (Throwable e) {
// Special handling in case the bundle has been refreshed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.karaf.features.internal.service;

/**
* Interface for features service implementations that support boot lifecycle management.
*/
public interface BootManaged {

boolean isBootDone();

void bootDone();

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
/**
*
*/
public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCallback {
public class FeaturesServiceImpl implements FeaturesService, BootManaged, Deployer.DeployCallback {

private static final String RESOLVE_FILE = "resolve";
private static final Logger LOGGER = LoggerFactory.getLogger(FeaturesServiceImpl.class);
Expand Down Expand Up @@ -243,13 +243,15 @@ protected void saveState() {
}
}

boolean isBootDone() {
@Override
public boolean isBootDone() {
synchronized (lock) {
return state.bootDone.get();
}
}

void bootDone() {
@Override
public void bootDone() {
synchronized (lock) {
state.bootDone.set(true);
saveState();
Expand Down
Loading
Loading