Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
BZ-1063469: use try/catch/finally on IOService batch processing
Browse files Browse the repository at this point in the history
  • Loading branch information
porcelli committed Feb 10, 2014
1 parent 597618e commit 051ffeb
Showing 1 changed file with 23 additions and 13 deletions.
Expand Up @@ -153,11 +153,14 @@ public boolean addConfiguration( final ConfigGroup configGroup ) {

final CommentedOption commentedOption = new CommentedOption( getIdentityName(),
"Created config " + filePath.getFileName() );
ioService.startBatch();
ioService.write( filePath, marshaller.marshall( configGroup ), commentedOption );
try {
ioService.startBatch();
ioService.write( filePath, marshaller.marshall( configGroup ), commentedOption );

updateLastModified();
ioService.endBatch();
updateLastModified();
} finally {
ioService.endBatch();
}
//Invalidate cache if a new item has been created; otherwise cached value is stale
configuration.remove( configGroup.getType() );

Expand All @@ -172,11 +175,14 @@ public boolean updateConfiguration( ConfigGroup configGroup ) {

final CommentedOption commentedOption = new CommentedOption( getIdentityName(),
"Updated config " + filePath.getFileName() );
ioService.startBatch();
ioService.write( filePath, marshaller.marshall( configGroup ), commentedOption );
try {
ioService.startBatch();
ioService.write( filePath, marshaller.marshall( configGroup ), commentedOption );

updateLastModified();
ioService.endBatch();
updateLastModified();
} finally {
ioService.endBatch();
}
//Invalidate cache if a new item has been created; otherwise cached value is stale
configuration.remove( configGroup.getType() );

Expand All @@ -195,12 +201,16 @@ public boolean removeConfiguration( final ConfigGroup configGroup ) {
if ( !ioService.exists( filePath ) ) {
return true;
}
ioService.startBatch();
boolean result = ioService.deleteIfExists( filePath );
if ( result ) {
updateLastModified();
boolean result;
try {
ioService.startBatch();
result = ioService.deleteIfExists( filePath );
if ( result ) {
updateLastModified();
}
} finally {
ioService.endBatch();
}
ioService.endBatch();

return result;
}
Expand Down

0 comments on commit 051ffeb

Please sign in to comment.