Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-03-11 09:01:34 -0500
committerGlyn Normington2011-03-11 09:01:34 -0500
commit40b067213f1753b5c899d0eaf7e5b82349843379 (patch)
treeae149e94e1c9de915d037a546701f66a94b3627c
parentac3c5ba2941238b13de087db6842089625b8af2d (diff)
downloadorg.eclipse.virgo.kernel-40b067213f1753b5c899d0eaf7e5b82349843379.tar.gz
org.eclipse.virgo.kernel-40b067213f1753b5c899d0eaf7e5b82349843379.tar.xz
org.eclipse.virgo.kernel-40b067213f1753b5c899d0eaf7e5b82349843379.zip
bug 336941: tidy up the visitor interface
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraphVisitor.java26
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java36
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceEventHook.java1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/SubgraphTraverser.java15
5 files changed, 58 insertions, 21 deletions
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraphVisitor.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraphVisitor.java
index a94dd3ca..ae486d96 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraphVisitor.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraphVisitor.java
@@ -13,8 +13,6 @@
package org.eclipse.virgo.kernel.osgi.region;
-import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
-
/**
* {@link RegionDigraphVisitor} is used to traverse a subgraph of a {@link RegionDigraph}.
* <p />
@@ -25,10 +23,28 @@ import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
*/
public interface RegionDigraphVisitor {
- void visit(Region r);
+ /**
+ * Visits the given region and determines whether or not to continue traversing.
+ *
+ * @param region the region to visit
+ * @return <code>true</code> if the traversal is to continue and <code>false</code> otherwise
+ */
+ boolean visit(Region region);
- void preEdgeTraverse(FilteredRegion fr);
+ /**
+ * Prepares to traverse an edge with the given {@link RegionFilter} and determines whether or not to traverse the
+ * edge.
+ *
+ * @param regionFilter the {@link RegionFilter} of the edge to be traversed
+ * @return <code>true</code> if the edge is to be traversed and <code>false</code> otherwise
+ */
+ boolean preEdgeTraverse(RegionFilter regionFilter);
- void postEdgeTraverse(FilteredRegion fr);
+ /**
+ * This is called after traversing an edge with the given {@link RegionFilter}.
+ *
+ * @param regionFilter the {@link RegionFilter} of the edge that has just been traversed
+ */
+ void postEdgeTraverse(RegionFilter regionFilter);
} \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
index 25ac96ba..52257f42 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
@@ -113,6 +113,7 @@ final class RegionManager {
this.tracker.track(this.bundleContext.registerService(org.osgi.framework.hooks.service.FindHook.class, serviceFindHook, null));
}
+ @SuppressWarnings("deprecation")
private void registerServiceEventHook(org.osgi.framework.hooks.service.EventHook serviceEventHook) {
this.tracker.track(this.bundleContext.registerService(org.osgi.framework.hooks.service.EventHook.class, serviceEventHook, null));
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
index 104fe5e7..906d9322 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
@@ -20,7 +20,6 @@ import java.util.Stack;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraphVisitor;
-import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -83,17 +82,34 @@ public final class RegionBundleFindHook implements FindHook {
}
}
- public void preEdgeTraverse(FilteredRegion fr) {
+ private void pushAllowed() {
synchronized (this.monitor) {
this.allowedStack.push(this.allowed);
this.allowed = new HashSet<Bundle>();
}
}
- public void postEdgeTraverse(FilteredRegion fr) {
+ private void popAllowed() {
+ synchronized (this.monitor) {
+ this.allowed = this.allowedStack.pop();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean preEdgeTraverse(RegionFilter regionFilter) {
+ pushAllowed();
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void postEdgeTraverse(RegionFilter regionFilter) {
Set<Bundle> a = getAllowed();
popAllowed();
- filter(a, fr.getFilter());
+ filter(a, regionFilter);
getAllowed().addAll(a);
}
@@ -107,18 +123,16 @@ public final class RegionBundleFindHook implements FindHook {
}
}
- private void popAllowed() {
- synchronized (this.monitor) {
- this.allowed = this.allowedStack.pop();
- }
- }
-
- public void visit(Region r) {
+ /**
+ * {@inheritDoc}
+ */
+ public boolean visit(Region r) {
for (Bundle b : this.bundles) {
if (r.contains(b)) {
getAllowed().add(b);
}
}
+ return true;
}
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceEventHook.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceEventHook.java
index 0c1e9279..56610acb 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceEventHook.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceEventHook.java
@@ -37,6 +37,7 @@ import org.osgi.framework.hooks.service.FindHook;
* <strong>Concurrent Semantics</strong><br />
* Thread safe.
*/
+@SuppressWarnings("deprecation")
public final class RegionServiceEventHook implements EventHook {
private final FindHook serviceFindHook;
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/SubgraphTraverser.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/SubgraphTraverser.java
index 20d7ffae..21f8c6f8 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/SubgraphTraverser.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/SubgraphTraverser.java
@@ -36,16 +36,21 @@ final class SubgraphTraverser {
private void visitRemainingSubgraph(Region r, RegionDigraphVisitor visitor, Set<Region> path) {
if (!path.contains(r)) {
- visitor.visit(r);
- traverseEdges(r, visitor, path);
+ if (visitor.visit(r)) {
+ traverseEdges(r, visitor, path);
+ }
}
}
private void traverseEdges(Region r, RegionDigraphVisitor visitor, Set<Region> path) {
for (FilteredRegion fr : r.getEdges()) {
- visitor.preEdgeTraverse(fr);
- visitRemainingSubgraph(fr.getRegion(), visitor, extendPath(r, path));
- visitor.postEdgeTraverse(fr);
+ if (visitor.preEdgeTraverse(fr.getFilter())) {
+ try {
+ visitRemainingSubgraph(fr.getRegion(), visitor, extendPath(r, path));
+ } finally {
+ visitor.postEdgeTraverse(fr.getFilter());
+ }
+ }
}
}

Back to the top