You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/04/01 13:43:44 UTC
[11/11] git commit: [KARAF-2859] Reverse the link between
regions/persistence,
as it causes the features service to be refreshed which isn't supported
[KARAF-2859] Reverse the link between regions/persistence, as it causes the features service to be refreshed which isn't supported
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/17095271
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/17095271
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/17095271
Branch: refs/heads/master
Commit: 17095271c803af711fc353f39f02cb152abb2c76
Parents: 8a3e43e
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Apr 1 13:41:46 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Apr 1 13:41:46 2014 +0200
----------------------------------------------------------------------
features/core/pom.xml | 12 ----
.../karaf/features/RegionsPersistence.java | 26 +++++++++
.../karaf/features/internal/BundleManager.java | 21 ++++++-
.../internal/PersistentBundleManager.java | 59 --------------------
.../karaf/features/internal/osgi/Activator.java | 44 +++++++++------
region/core/pom.xml | 8 ++-
.../region/persist/RegionsPersistence.java | 26 ---------
.../region/persist/internal/Activator.java | 8 ++-
.../persist/internal/RegionsBundleTracker.java | 12 ++--
.../internal/RegionsPersistenceImpl.java | 3 +-
10 files changed, 90 insertions(+), 129 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/features/core/pom.xml
----------------------------------------------------------------------
diff --git a/features/core/pom.xml b/features/core/pom.xml
index e2e3989..8459b3d 100644
--- a/features/core/pom.xml
+++ b/features/core/pom.xml
@@ -44,11 +44,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.karaf.region</groupId>
- <artifactId>org.apache.karaf.region.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<scope>provided</scope>
@@ -112,13 +107,6 @@
org.apache.karaf.features.management.codec;
-noimport:=true
</Export-Package>
- <Import-Package>
- org.apache.karaf.region.persist;resolution:=optional,
- *
- </Import-Package>
- <DynamicImport-Package>
- org.apache.karaf.region.persist
- </DynamicImport-Package>
<Private-Package>
org.apache.karaf.features.internal,
org.apache.karaf.features.internal.model,
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/features/core/src/main/java/org/apache/karaf/features/RegionsPersistence.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/RegionsPersistence.java b/features/core/src/main/java/org/apache/karaf/features/RegionsPersistence.java
new file mode 100644
index 0000000..96ca7da
--- /dev/null
+++ b/features/core/src/main/java/org/apache/karaf/features/RegionsPersistence.java
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+public interface RegionsPersistence {
+ void install(Bundle b, String regionName) throws BundleException;
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/features/core/src/main/java/org/apache/karaf/features/internal/BundleManager.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/BundleManager.java b/features/core/src/main/java/org/apache/karaf/features/internal/BundleManager.java
index 647fbb9..be4fca7 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/BundleManager.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/BundleManager.java
@@ -42,8 +42,8 @@ import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
import org.apache.felix.utils.version.VersionRange;
import org.apache.karaf.features.FeaturesService.Option;
+import org.apache.karaf.features.RegionsPersistence;
import org.apache.karaf.features.Resolver;
-import org.apache.karaf.region.persist.RegionsPersistence;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -66,6 +66,7 @@ public class BundleManager {
private static final Logger LOGGER = LoggerFactory.getLogger(BundleManager.class);
private final BundleContext bundleContext;
private final long refreshTimeout;
+ private RegionsPersistence regionsPersistence;
public BundleManager(BundleContext bundleContext) {
this(bundleContext, 5000);
@@ -76,7 +77,25 @@ public class BundleManager {
this.refreshTimeout = refreshTimeout;
}
+ public void setRegionsPersistence(RegionsPersistence regionsPersistence) {
+ this.regionsPersistence = regionsPersistence;
+ }
+
public BundleInstallerResult installBundleIfNeeded(String bundleLocation, int startLevel, String regionName) throws IOException, BundleException {
+ BundleInstallerResult result = doInstallBundleIfNeeded(bundleLocation, startLevel, regionName);
+ installToRegion(regionName, result.bundle, result.isNew);
+ return result;
+ }
+
+ private void installToRegion(String region, Bundle bundle, boolean isNew) throws BundleException {
+ if (region != null && isNew) {
+ if (regionsPersistence != null) {
+ regionsPersistence.install(bundle, region);
+ }
+ }
+ }
+
+ private BundleInstallerResult doInstallBundleIfNeeded(String bundleLocation, int startLevel, String regionName) throws IOException, BundleException {
InputStream is = getInputStreamForBundle(bundleLocation);
try {
is.mark(256 * 1024);
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/features/core/src/main/java/org/apache/karaf/features/internal/PersistentBundleManager.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/PersistentBundleManager.java b/features/core/src/main/java/org/apache/karaf/features/internal/PersistentBundleManager.java
deleted file mode 100644
index 30ff446..0000000
--- a/features/core/src/main/java/org/apache/karaf/features/internal/PersistentBundleManager.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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;
-
-import java.io.IOException;
-
-import org.apache.karaf.region.persist.RegionsPersistence;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-
-public class PersistentBundleManager extends BundleManager {
-
- private final RegionsPersistence regionsPersistence;
-
- public PersistentBundleManager(BundleContext bundleContext, RegionsPersistence regionsPersistence) {
- super(bundleContext);
- this.regionsPersistence = regionsPersistence;
- }
-
- public PersistentBundleManager(BundleContext bundleContext, long refreshTimeout, RegionsPersistence regionsPersistence) {
- super(bundleContext, refreshTimeout);
- this.regionsPersistence = regionsPersistence;
- }
-
- @Override
- public BundleInstallerResult installBundleIfNeeded(String bundleLocation, int startLevel, String regionName) throws IOException, BundleException {
- BundleInstallerResult result = super.installBundleIfNeeded(bundleLocation, startLevel, regionName);
- installToRegion(regionName, result.bundle, result.isNew);
- return result;
- }
-
- private void installToRegion(String region, Bundle bundle, boolean isNew) throws BundleException {
- if (region != null && isNew) {
- if (regionsPersistence != null) {
- regionsPersistence.install(bundle, region);
- } else {
- throw new RuntimeException("Unable to find RegionsPersistence service, while installing " + region);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
index 6c59387..138366e 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
@@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Properties;
-import java.util.concurrent.Callable;
import javax.management.NotCompliantMBeanException;
@@ -33,10 +32,10 @@ import org.apache.karaf.features.internal.BundleManager;
import org.apache.karaf.features.internal.FeatureConfigInstaller;
import org.apache.karaf.features.internal.FeatureFinder;
import org.apache.karaf.features.internal.FeaturesServiceImpl;
-import org.apache.karaf.features.internal.PersistentBundleManager;
import org.apache.karaf.features.management.internal.FeaturesServiceMBeanImpl;
-import org.apache.karaf.region.persist.RegionsPersistence;
+import org.apache.karaf.features.RegionsPersistence;
import org.apache.karaf.util.tracker.BaseActivator;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -49,10 +48,10 @@ public class Activator extends BaseActivator {
private ServiceTracker<FeaturesListener, FeaturesListener> featuresListenerTracker;
private FeaturesServiceImpl featuresService;
+ private SingleServiceTracker<RegionsPersistence> regionsTracker;
@Override
protected void doOpen() throws Exception {
- trackService("org.apache.karaf.region.persist.RegionsPersistence");
trackService(URLStreamHandlerService.class, "(url.handler.protocol=mvn)");
trackService(ConfigurationAdmin.class);
@@ -70,7 +69,6 @@ public class Activator extends BaseActivator {
protected void doStart() throws NotCompliantMBeanException {
ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
- Object regionsPersistence = getTrackedService("org.apache.karaf.region.persist.RegionsPersistence");
URLStreamHandlerService mvnUrlHandler = getTrackedService(URLStreamHandlerService.class);
if (configurationAdmin == null || mvnUrlHandler == null) {
@@ -82,19 +80,25 @@ public class Activator extends BaseActivator {
props.put(Constants.SERVICE_PID, "org.apache.karaf.features.repos");
register(ManagedService.class, featureFinder, props);
- BundleManager bundleManager;
- if (regionsPersistence != null) {
- final Object rg = regionsPersistence;
- // Use an inner class to isolate from the region persistence package
- bundleManager = new Callable<BundleManager>() {
- @Override
- public BundleManager call() {
- return new PersistentBundleManager(bundleContext, (RegionsPersistence) rg);
- }
- }.call();
- } else {
- bundleManager = new BundleManager(bundleContext);
- }
+ final BundleManager bundleManager = new BundleManager(bundleContext);
+ regionsTracker = new SingleServiceTracker<RegionsPersistence>(bundleContext, RegionsPersistence.class,
+ new SingleServiceTracker.SingleServiceListener() {
+ @Override
+ public void serviceFound() {
+ bundleManager.setRegionsPersistence(regionsTracker.getService());
+ }
+ @Override
+ public void serviceLost() {
+ serviceFound();
+ }
+ @Override
+ public void serviceReplaced() {
+ serviceFound();
+ }
+ });
+ regionsTracker.open();
+
+
FeatureConfigInstaller configInstaller = new FeatureConfigInstaller(configurationAdmin);
String featuresRepositories = getString("featuresRepositories", "");
boolean respectStartLvlDuringFeatureStartup = getBoolean("respectStartLvlDuringFeatureStartup", true);
@@ -143,6 +147,10 @@ public class Activator extends BaseActivator {
}
protected void doStop() {
+ if (regionsTracker != null) {
+ regionsTracker.close();
+ regionsTracker = null;
+ }
if (featuresListenerTracker != null) {
featuresListenerTracker.close();
featuresListenerTracker = null;
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/region/core/pom.xml
----------------------------------------------------------------------
diff --git a/region/core/pom.xml b/region/core/pom.xml
index 8e9fe95..f1a792a 100644
--- a/region/core/pom.xml
+++ b/region/core/pom.xml
@@ -62,6 +62,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>org.apache.karaf.features.core</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.eclipse.equinox</groupId>
<artifactId>region</artifactId>
<version>1.0.0.v20110506</version>
@@ -104,9 +109,6 @@
<Bundle-Activator>
org.apache.karaf.region.persist.internal.Activator
</Bundle-Activator>
- <Export-Package>
- org.apache.karaf.region.persist;version="${project.version}"
- </Export-Package>
<Private-Package>
org.apache.karaf.region.persist.internal.*,
org.apache.karaf.util.tracker
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/region/core/src/main/java/org/apache/karaf/region/persist/RegionsPersistence.java
----------------------------------------------------------------------
diff --git a/region/core/src/main/java/org/apache/karaf/region/persist/RegionsPersistence.java b/region/core/src/main/java/org/apache/karaf/region/persist/RegionsPersistence.java
deleted file mode 100644
index 1c66b4c..0000000
--- a/region/core/src/main/java/org/apache/karaf/region/persist/RegionsPersistence.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.region.persist;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
-
-public interface RegionsPersistence {
- void install(Bundle b, String regionName) throws BundleException;
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/region/core/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
----------------------------------------------------------------------
diff --git a/region/core/src/main/java/org/apache/karaf/region/persist/internal/Activator.java b/region/core/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
index 4705818..aa7215f 100644
--- a/region/core/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
+++ b/region/core/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
@@ -22,7 +22,7 @@ package org.apache.karaf.region.persist.internal;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.karaf.region.persist.RegionsPersistence;
+import org.apache.karaf.features.RegionsPersistence;
import org.apache.karaf.util.tracker.SingleServiceTracker;
import org.eclipse.equinox.region.RegionDigraph;
import org.osgi.framework.Bundle;
@@ -82,8 +82,10 @@ public class Activator implements BundleActivator {
public void stop(BundleContext bundleContext) throws Exception {
tracker.close();
persistence.set(null);
- bundleTracker.set(null);
+ RegionsBundleTracker tracker = bundleTracker.getAndSet(null);
+ if (tracker != null) {
+ tracker.stop();
+ }
}
-
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java
----------------------------------------------------------------------
diff --git a/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java b/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java
index 890fb58..7035303 100644
--- a/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java
+++ b/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java
@@ -20,7 +20,7 @@
package org.apache.karaf.region.persist.internal;
-import org.apache.karaf.region.persist.RegionsPersistence;
+import org.apache.karaf.features.RegionsPersistence;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -39,24 +39,24 @@ public class RegionsBundleTracker {
void start(BundleContext bundleContext, RegionsPersistence regionsPersistence) {
this.regionsPersistence = regionsPersistence;
int stateMask = Bundle.INSTALLED;
- bundleTracker = new BundleTracker(bundleContext, stateMask, new BundleTrackerCustomizer() {
+ bundleTracker = new BundleTracker<Bundle>(bundleContext, stateMask, new BundleTrackerCustomizer<Bundle>() {
@Override
- public Object addingBundle(Bundle bundle, BundleEvent bundleEvent) {
+ public Bundle addingBundle(Bundle bundle, BundleEvent bundleEvent) {
return RegionsBundleTracker.this.addingBundle(bundle);
}
@Override
- public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) {
+ public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Bundle o) {
}
@Override
- public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) {
+ public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Bundle o) {
}
});
bundleTracker.open();
}
- private Object addingBundle(Bundle bundle) {
+ private Bundle addingBundle(Bundle bundle) {
String region = bundle.getHeaders().get("Region");
if (region != null) {
try {
http://git-wip-us.apache.org/repos/asf/karaf/blob/17095271/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java
----------------------------------------------------------------------
diff --git a/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java b/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java
index 9cfda9f..dcf5d26 100644
--- a/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java
+++ b/region/core/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java
@@ -31,7 +31,8 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
-import org.apache.karaf.region.persist.RegionsPersistence;
+
+import org.apache.karaf.features.RegionsPersistence;
import org.apache.karaf.region.persist.internal.model.FilterAttributeType;
import org.apache.karaf.region.persist.internal.model.FilterBundleType;
import org.apache.karaf.region.persist.internal.model.FilterNamespaceType;