Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-13 13:22:09 -0400
committerChristopher Frost2011-05-13 13:22:09 -0400
commitcd71143b0b786e34479cc0ce64628217de98a258 (patch)
tree002fbb9cb759a308e5efac3f5b4436e65613fc8f
parentb0f8f42c7c899c1a3f55117b42d533105444ff6f (diff)
downloadorg.eclipse.virgo.kernel-cd71143b0b786e34479cc0ce64628217de98a258.tar.gz
org.eclipse.virgo.kernel-cd71143b0b786e34479cc0ce64628217de98a258.tar.xz
org.eclipse.virgo.kernel-cd71143b0b786e34479cc0ce64628217de98a258.zip
Improving the artifact repository code to remove bundles with out knowing the region
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java9
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java22
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java21
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubArtifactRepository.java4
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java2
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java8
6 files changed, 53 insertions, 13 deletions
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java
index 9e9f0881..e3613874 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java
@@ -40,6 +40,15 @@ public interface RuntimeArtifactRepository {
* Remove an {@link Artifact} from this repository. If the artifact is a bundle, it is only removed if the bundle is
* in the user region.
*
+ * @param artifact The {@link Artifact} to remove
+ * @return <code>true</code> if this repository contained the specified {@link Artifact}
+ */
+ boolean remove(Artifact artifact);
+
+ /**
+ * Remove an {@link Artifact} from this repository. If the artifact is a bundle, it is only removed if the bundle is
+ * in the user region.
+ *
* @param type The type of the {@link Artifact} to remove
* @param name The name of the {@link Artifact} to remove
* @param version The {@link Version} of the {@link Artifact} to remove
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java
index 1eac929b..a33d5bed 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java
@@ -19,6 +19,7 @@ import java.util.Set;
import org.eclipse.equinox.region.Region;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +52,7 @@ public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifact
/**
* {@inheritDoc}
*/
- public boolean add(Artifact artifact) {
+ public boolean add(@NonNull Artifact artifact) {
synchronized (this.monitor) {
boolean result = this.artifacts.add(artifact);
if (result) {
@@ -70,9 +71,8 @@ public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifact
/**
* {@inheritDoc}
*/
- public boolean remove(String type, String name, Version version, Region region) {
+ public boolean remove(@NonNull Artifact artifact) {
synchronized (this.monitor) {
- Artifact artifact = getArtifact(type, name, version, region);
boolean result = this.artifacts.remove(artifact);
if (result) {
for (ArtifactRepositoryListener listener : listeners) {
@@ -86,6 +86,20 @@ public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifact
return result;
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean remove(@NonNull String type, @NonNull String name, @NonNull Version version, @NonNull Region region) {
+ synchronized (this.monitor) {
+ Artifact artifact = getArtifact(type, name, version, region);
+ if(artifact != null){
+ return remove(artifact);
+ } else {
+ return false;
+ }
+ }
+ }
/**
* {@inheritDoc}
@@ -99,7 +113,7 @@ public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifact
/**
* {@inheritDoc}
*/
- public Artifact getArtifact(String type, String name, Version version, Region region) {
+ public Artifact getArtifact(@NonNull String type, @NonNull String name, @NonNull Version version, @NonNull Region region) {
synchronized (this.monitor) {
for (Artifact artifact : this.artifacts) {
if (artifact.getType().equals(type) &&
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
index cf8d311b..0be0e3b0 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
@@ -14,6 +14,7 @@ package org.eclipse.virgo.kernel.model.internal.bundle;
import org.eclipse.equinox.region.Region;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.virgo.kernel.model.Artifact;
+import org.eclipse.virgo.kernel.model.ArtifactState;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.serviceability.NonNull;
@@ -48,8 +49,7 @@ final class ModelBundleListener implements SynchronousBundleListener {
private final RegionDigraph regionDigraph;
- public ModelBundleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository,
- @NonNull PackageAdminUtil packageAdminUtil, @NonNull RegionDigraph regionDigraph) {
+ public ModelBundleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil, @NonNull RegionDigraph regionDigraph) {
this.bundleContext = bundleContext;
this.artifactRepository = artifactRepository;
this.packageAdminUtil = packageAdminUtil;
@@ -70,14 +70,25 @@ final class ModelBundleListener implements SynchronousBundleListener {
private void processInstalled(BundleEvent event) {
Bundle bundle = event.getBundle();
Region region = this.regionDigraph.getRegion(bundle);
- logger.info("Processing installed event for '{}:{}' in region '{}'", new Object[] {bundle.getSymbolicName(), bundle.getVersion().toString(), region.getName()});
+ logger.info("Processing installed event for bundle '{}:{}' in region '{}'", new Object[] {bundle.getSymbolicName(), bundle.getVersion().toString(), region.getName()});
this.artifactRepository.add(new BundleArtifact(bundleContext, packageAdminUtil, bundle, region));
}
private void processUninstalled(BundleEvent event) {
Bundle bundle = event.getBundle();
- logger.info("Processing uninstalled event for '{}:{}'", bundle.getSymbolicName(), bundle.getVersion().toString());
- this.artifactRepository.remove(BundleArtifact.TYPE, bundle.getSymbolicName(), bundle.getVersion(), this.regionDigraph.getRegion(bundle));
+ for (Artifact artifact : this.artifactRepository.getArtifacts()) {
+ if (artifact.getType().equals(BundleArtifact.TYPE) &&
+ artifact.getName().equals(bundle.getSymbolicName()) &&
+ artifact.getVersion().equals(bundle.getVersion()) ){
+ if(artifact instanceof BundleArtifact){
+ BundleArtifact bundleArtifact = (BundleArtifact) artifact;
+ if(ArtifactState.UNINSTALLED == bundleArtifact.getState()){
+ this.artifactRepository.remove(bundleArtifact);
+ logger.info("Processing uninstalled event for bundle '{}:{}' from region '{}'", new Object[] {bundleArtifact.getName(), bundleArtifact.getVersion().toString(), bundleArtifact.getRegion().getName()});
+ }
+ }
+ }
+ }
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubArtifactRepository.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubArtifactRepository.java
index eb9d97c9..832236fb 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubArtifactRepository.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubArtifactRepository.java
@@ -25,6 +25,10 @@ public class StubArtifactRepository implements RuntimeArtifactRepository {
return this.artifacts.add(artifact);
}
+ public boolean remove(Artifact artifact) {
+ return this.remove(artifact.getType(), artifact.getName(), artifact.getVersion(), artifact.getRegion());
+ }
+
public boolean remove(String type, String name, Version version, Region region) {
return this.artifacts.remove(getArtifact(type, name, version, region));
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java
index f481a97e..b1f5875a 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java
@@ -77,7 +77,7 @@ public class NotifyingArtifactRepositoryTests {
Artifact stubArtifact2 = new StubCompositeArtifact("foo2", "bar2", stubRegion2);
this.artifactRepository.add(stubArtifact);
this.artifactRepository.add(stubArtifact2);
- Artifact retrieved = this.artifactRepository.getArtifact("foo", "bar", new Version("0.1.0"), null);
+ Artifact retrieved = this.artifactRepository.getArtifact("foo", "bar", new Version("0.1.0"), stubRegion1);
assertNull(retrieved);
retrieved = this.artifactRepository.getArtifact("foo", "bar", Version.emptyVersion, stubRegion1);
assertEquals(stubArtifact, retrieved);
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
index b03ff247..9b3a1761 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
@@ -86,13 +86,15 @@ public class ModelBundleListenerTests {
@Test
public void uninstalled() {
replay(regionDigraph);
- BundleEvent event1 = new BundleEvent(BundleEvent.INSTALLED, new StubBundle().setBundleContext(this.bundleContext));
+ StubBundle myBundle = new StubBundle().setBundleContext(this.bundleContext);
+ BundleEvent event1 = new BundleEvent(BundleEvent.INSTALLED, myBundle);
this.listener.bundleChanged(event1);
assertEquals(1, this.artifactRepository.getArtifacts().size());
- BundleEvent event2 = new BundleEvent(BundleEvent.UNINSTALLED, new StubBundle().setBundleContext(this.bundleContext));
+ myBundle.setState(Bundle.UNINSTALLED);
+ BundleEvent event2 = new BundleEvent(BundleEvent.UNINSTALLED, myBundle);
this.listener.bundleChanged(event2);
assertEquals(0, this.artifactRepository.getArtifacts().size());
- BundleEvent event3 = new BundleEvent(BundleEvent.UNINSTALLED, new StubBundle().setBundleContext(this.bundleContext));
+ BundleEvent event3 = new BundleEvent(BundleEvent.UNINSTALLED, myBundle);
this.listener.bundleChanged(event3);
assertEquals(0, this.artifactRepository.getArtifacts().size());
}

Back to the top