diff options
author | Haakon Dybdahl <dybdahl@yahoo-inc.com> | 2017-01-10 12:26:59 +0100 |
---|---|---|
committer | Haakon Dybdahl <dybdahl@yahoo-inc.com> | 2017-01-10 12:26:59 +0100 |
commit | 2eddddc726ee821b9dd778697a96256abe489ba7 (patch) | |
tree | 4d3f51ef2a43e0a81667dcb4bd7cac199c2614de /vespaclient-container-plugin | |
parent | 980d6da5a076c2d2a46d9bfbda2730309bc6c252 (diff) |
Call destroy on sessions after use.
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r-- | vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java index 24f9873da53..7963b26858c 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java @@ -88,6 +88,17 @@ public class OperationHandlerImpl implements OperationHandler { restUri)); } try { + return doVisit(visitorControlHandler, localDataVisitorHandler, restUri); + } finally { + visitorSession.destroy(); + } + } + + private VisitResult doVisit( + VisitorControlHandler visitorControlHandler, + LocalDataVisitorHandler localDataVisitorHandler, + RestUri restUri) throws RestApiException { + try { if (! visitorControlHandler.waitUntilDone(VISIT_TIMEOUT_MS)) { throw new RestApiException(Response.createErrorResponse(500, "Timed out", restUri)); } @@ -112,8 +123,9 @@ public class OperationHandlerImpl implements OperationHandler { @Override public void put(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + SyncSession syncSession = null; try { - SyncSession syncSession = documentAccess.createSyncSession(new SyncParameters()); + syncSession = documentAccess.createSyncSession(new SyncParameters()); DocumentPut put = new DocumentPut(data.getDocument()); put.setCondition(data.getCondition()); syncSession.put(put); @@ -121,26 +133,32 @@ public class OperationHandlerImpl implements OperationHandler { throw new RestApiException(createErrorResponse(documentException, restUri)); } catch (Exception e) { throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + } finally { + if (syncSession != null) { syncSession.destroy(); } } } @Override public void update(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + SyncSession syncSession = null; try { - SyncSession syncSession = documentAccess.createSyncSession(new SyncParameters()); + syncSession = documentAccess.createSyncSession(new SyncParameters()); syncSession.update(data.getDocumentUpdate()); } catch (DocumentAccessException documentException) { throw new RestApiException(createErrorResponse(documentException, restUri)); } catch (Exception e) { throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + } finally { + if (syncSession != null) { syncSession.destroy(); } } } @Override public void delete(RestUri restUri, String condition) throws RestApiException { + SyncSession syncSession = null; try { DocumentId id = new DocumentId(restUri.generateFullId()); - SyncSession syncSession = documentAccess.createSyncSession(new SyncParameters()); + syncSession = documentAccess.createSyncSession(new SyncParameters()); DocumentRemove documentRemove = new DocumentRemove(id); if (condition != null && ! condition.isEmpty()) { documentRemove.setCondition(new TestAndSetCondition(condition)); @@ -150,14 +168,17 @@ public class OperationHandlerImpl implements OperationHandler { throw new RestApiException(Response.createErrorResponse(400, documentException.getMessage(), restUri)); } catch (Exception e) { throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + } finally { + if (syncSession != null) { syncSession.destroy(); } } } @Override public Optional<String> get(RestUri restUri) throws RestApiException { + SyncSession syncSession = null; try { DocumentId id = new DocumentId(restUri.generateFullId()); - SyncSession syncSession = documentAccess.createSyncSession(new SyncParameters()); + syncSession = documentAccess.createSyncSession(new SyncParameters()); final Document document = syncSession.get(id); if (document == null) { return Optional.empty(); @@ -169,6 +190,8 @@ public class OperationHandlerImpl implements OperationHandler { } catch (Exception e) { throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + } finally { + if (syncSession != null) { syncSession.destroy(); } } } |