Skip to content

Commit

Permalink
Fixed problem with non-closed repositories in case of application red…
Browse files Browse the repository at this point in the history
…eploy
  • Loading branch information
skodapetr committed Jan 6, 2015
1 parent 4d57eee commit ab6f76b
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;

import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -174,6 +175,37 @@ public synchronized ManageableWritableRDFDataUnit getRDFDataUnit(ExecutionInfo e
return (ManageableWritableRDFDataUnit) dataUnit;
}

/**
* Release and close all opened repositories. Should be called when application is closing.
*/
@PreDestroy
private void closeAll() {
LOG.info("Releasing all opened repositories...");
synchronized (dataUnits) {
// Release dataUnits.
for (String directoryStr : dataUnits.keySet()) {
final DataUnitHolder holder = dataUnits.get(directoryStr);
try {
holder.getDataUnit().release();
} catch (DataUnitException ex) {
LOG.warn("Can't release DataUnit.", ex);
}
}
// Release all repositories.
for (Long executionId : openedForExecution.keySet()) {
try {
repositoryManager.release(executionId);
} catch (RDFException ex) {
LOG.warn("Can't release repository for execution: {}", executionId, ex);
}
}
// Empty lists.
dataUnits.clear();
openedForExecution.clear();
}
LOG.info("Releasing all opened repositories...done");
}

private void incRepoCounter(DataUnitHolder holder) {
int value = 0;
if (openedForExecution.containsKey(holder.getExecutionId())) {
Expand Down

0 comments on commit ab6f76b

Please sign in to comment.