From 051ffeb85b798ae8bb75ee7d4c412f6c3f05a1c8 Mon Sep 17 00:00:00 2001 From: Alexandre Porcelli Date: Mon, 10 Feb 2014 18:47:32 -0200 Subject: [PATCH] BZ-1063469: use try/catch/finally on IOService batch processing --- .../config/ConfigurationServiceImpl.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/uberfire-backend/uberfire-backend-server/src/main/java/org/uberfire/backend/server/config/ConfigurationServiceImpl.java b/uberfire-backend/uberfire-backend-server/src/main/java/org/uberfire/backend/server/config/ConfigurationServiceImpl.java index 1711c0007b..6e6d12d4eb 100644 --- a/uberfire-backend/uberfire-backend-server/src/main/java/org/uberfire/backend/server/config/ConfigurationServiceImpl.java +++ b/uberfire-backend/uberfire-backend-server/src/main/java/org/uberfire/backend/server/config/ConfigurationServiceImpl.java @@ -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() ); @@ -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() ); @@ -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; }