Skip to content

Commit

Permalink
0001178: Performance Improvement: Many calls are being made to the fi…
Browse files Browse the repository at this point in the history
…le system to check if file exists while extracting big batches
  • Loading branch information
chenson42 committed Apr 15, 2013
1 parent ad8af85 commit 7f6b2fe
Showing 1 changed file with 16 additions and 7 deletions.
Expand Up @@ -23,7 +23,9 @@
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jumpmind.exception.IoException;
import org.jumpmind.symmetric.io.data.Batch;
Expand All @@ -34,9 +36,11 @@

public class StagingDataWriter extends AbstractProtocolDataWriter {

protected IStagingManager stagingManager;
private IStagingManager stagingManager;

protected String category;
private String category;

private Map<Batch, IStagedResource> stagedResources = new HashMap<Batch, IStagedResource>();

public StagingDataWriter(String sourceNodeId, String category, IStagingManager stagingManager,
IProtocolDataWriterListener... listeners) {
Expand All @@ -62,14 +66,19 @@ public static List<IProtocolDataWriterListener> toList(IProtocolDataWriterListen
@Override
protected void notifyEndBatch(Batch batch, IProtocolDataWriterListener listener) {
listener.end(context, batch, getStagedResource(batch));
stagedResources.remove(batch);
}

protected IStagedResource getStagedResource(Batch batch) {
String location = batch.getStagedLocation();
IStagedResource resource = stagingManager.find(category, location, batch.getBatchId());
if (resource == null || resource.getState() == State.DONE) {
log.debug("Creating staged resource for batch {}", batch.getSourceNodeBatchId());
resource = stagingManager.create(category, location, batch.getBatchId());
IStagedResource resource = stagedResources.get(batch);
if (resource == null) {
String location = batch.getStagedLocation();
resource = stagingManager.find(category, location, batch.getBatchId());
if (resource == null || resource.getState() == State.DONE) {
log.debug("Creating staged resource for batch {}", batch.getSourceNodeBatchId());
resource = stagingManager.create(category, location, batch.getBatchId());
}
stagedResources.put(batch, resource);
}
return resource;
}
Expand Down

0 comments on commit 7f6b2fe

Please sign in to comment.