Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2012-07-25 10:55:05 -0400
committerGlyn Normington2012-07-25 10:55:05 -0400
commit5c6cf8acf25c992ba118c09e40bd530fc1c40203 (patch)
tree42d6374e050fd447e70b082b0bab5da83a610883
parent540ab7da158178d976a33821fcd7e8bbc3ea1f47 (diff)
downloadorg.eclipse.virgo.kernel-5c6cf8acf25c992ba118c09e40bd530fc1c40203.tar.gz
org.eclipse.virgo.kernel-5c6cf8acf25c992ba118c09e40bd530fc1c40203.tar.xz
org.eclipse.virgo.kernel-5c6cf8acf25c992ba118c09e40bd530fc1c40203.zip
385743: encapsulate storage management
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java22
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java18
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java4
3 files changed, 28 insertions, 16 deletions
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java
index 2ba78490..46405ee7 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java
@@ -24,9 +24,13 @@ final class PathGenerator {
}
this.baseDirectory = basePathReference.getParent();
this.baseName = basePathReference.getName();
+
+ PathReference currentPathReference = getGenerationPath(this.generation, this.baseDirectory, this.baseName);
+ currentPathReference.getParent().createDirectory();
+ currentPathReference.delete(true);
}
- PathReference getCurrentPath() {
+ public PathReference getCurrentPath() {
synchronized (this.monitor) {
return getGenerationPath(this.generation);
}
@@ -35,20 +39,24 @@ final class PathGenerator {
/**
* Note that the history is only one level deep.
*/
- void next() {
+ public void next() {
synchronized (this.monitor) {
if (this.generation != 0) {
getPreviousPath().delete(true);
}
this.generation++;
this.hasPrevious = true;
+
+ PathReference currentPathReference = getCurrentPath();
+ currentPathReference.getParent().createDirectory();
+ currentPathReference.delete(true);
}
}
/**
* This may only be called if the current generation has not been used.
*/
- void previous() {
+ public void previous() {
synchronized (this.monitor) {
if (!this.hasPrevious) {
throw new IllegalStateException("No stash available");
@@ -63,8 +71,12 @@ final class PathGenerator {
return getGenerationPath(this.generation - 1);
}
- private PathReference getGenerationPath(long instance) {
- return this.baseDirectory.newChild(Long.toString(instance)).newChild(this.baseName);
+ private PathReference getGenerationPath(long generation) {
+ return getGenerationPath(generation, this.baseDirectory, this.baseName);
+ }
+
+ private static PathReference getGenerationPath(long generation, PathReference baseDirectory, String baseName) {
+ return baseDirectory.newChild(Long.toString(generation)).newChild(baseName);
}
}
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java
index d8c8d7ac..44976808 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java
@@ -55,12 +55,13 @@ final class StandardArtifactStorage implements ArtifactStorage {
this.pathGenerator = new PathGenerator(baseStagingPathReference);
- synchronize(this.sourcePathReference, false);
+ synchronize(this.sourcePathReference);
}
@Override
public void synchronize() {
- synchronize(this.sourcePathReference, true);
+ this.pathGenerator.next();
+ synchronize(this.sourcePathReference);
}
@Override
@@ -70,7 +71,8 @@ final class StandardArtifactStorage implements ArtifactStorage {
@Override
public void synchronize(URI sourceUri) {
- synchronize(new PathReference(sourceUri), true);
+ this.pathGenerator.next();
+ synchronize(new PathReference(sourceUri));
}
@Override
@@ -84,14 +86,8 @@ final class StandardArtifactStorage implements ArtifactStorage {
currentPathReference.delete(true);
}
- private void synchronize(PathReference normalizedSourcePathReference, boolean stash) {
- PathReference currentPathReference;
- if (stash) {
- this.pathGenerator.next();
- }
- currentPathReference = this.pathGenerator.getCurrentPath();
- currentPathReference.getParent().createDirectory();
- currentPathReference.delete(true);
+ private void synchronize(PathReference normalizedSourcePathReference) {
+ PathReference currentPathReference = this.pathGenerator.getCurrentPath();
if (normalizedSourcePathReference != null && !normalizedSourcePathReference.isDirectory()
&& needsUnpacking(normalizedSourcePathReference.getName())) {
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java
index 0f28d88a..a7174c09 100644
--- a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java
@@ -147,6 +147,10 @@ public class PathGeneratorTests {
File file = c.toFile();
assertTrue(file.toURI().toString().indexOf(TEST_PATH) != -1);
assertEquals(TEST_FILENAME, c.getName());
+ assertFalse(c.exists());
+ PathReference parent = c.getParent();
+ assertTrue(parent.isDirectory());
+ assertTrue(parent.exists());
}
}

Back to the top