diff --git a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/stage/StagingManager.java b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/stage/StagingManager.java index ad4a4cdcdf..4ad0639857 100644 --- a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/stage/StagingManager.java +++ b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/stage/StagingManager.java @@ -41,18 +41,19 @@ public class StagingManager implements IStagingManager { - private static final String LOCK_EXTENSION = ".lock"; + protected static final String LOCK_EXTENSION = ".lock"; protected static final Logger log = LoggerFactory.getLogger(StagingManager.class); protected File directory; - private Map resourcePathsCache = new ConcurrentHashMap(); + protected Set resourcePathsCache; + protected Map inUse = new ConcurrentHashMap(); - boolean clusterEnabled; + protected boolean clusterEnabled; - long lowFreeSpaceThresholdMegabytes; + protected long lowFreeSpaceThresholdMegabytes; public StagingManager(String directory, boolean clusterEnabled, long lowFreeSpaceThresholdMegabytes) { log.info("The staging directory was initialized at the following location: " + directory); @@ -60,6 +61,7 @@ public StagingManager(String directory, boolean clusterEnabled, long lowFreeSpac this.directory.mkdirs(); this.clusterEnabled = clusterEnabled; this.lowFreeSpaceThresholdMegabytes = lowFreeSpaceThresholdMegabytes; + this.resourcePathsCache = ConcurrentHashMap.newKeySet(); } public StagingManager(String directory, boolean clusterEnabled) { @@ -68,7 +70,7 @@ public StagingManager(String directory, boolean clusterEnabled) { @Override public Set getResourceReferences() { - return new TreeSet(resourcePathsCache.keySet()); + return new TreeSet(resourcePathsCache); } @Override @@ -143,13 +145,13 @@ protected void clean(Path path, long ttlInMs, StagingPurgeContext context) throw } cleanPath(resource, ttlInMs, context); // this comes after stat collection because - // once the file is gone we loose visibility to size + // once the file is gone we lose visibility to size } else { - resourcePathsCache.put(stagingPath,stagingPath); + resourcePathsCache.add(stagingPath); } } } catch (IllegalStateException ex) { - log.warn("Failure during refreshResourceList ", ex); + log.warn("Failure during clean ", ex); } } } @@ -196,7 +198,7 @@ public IStagedResource create(Object... path) { } this.inUse.put(filePath, resource); - this.resourcePathsCache.put(filePath, filePath); + this.resourcePathsCache.add(filePath); return resource; } @@ -222,16 +224,9 @@ protected String buildFilePath(Object... path) { public IStagedResource find(String path) { IStagedResource resource = inUse.get(path); if (resource == null) { - boolean foundResourcePath = resourcePathsCache.containsKey(path); - if (!foundResourcePath) { - resource = createStagedResource(path); - if (resource.getState() == State.DONE) { - resourcePathsCache.put(path, path); - foundResourcePath = true; - } - } else if (foundResourcePath) { - resource = createStagedResource(path); - } + resource = createStagedResource(path); + inUse.put(path, resource); + resourcePathsCache.add(path); } return resource; } @@ -306,5 +301,4 @@ public boolean accept(Path entry) { } }; - }