summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin
diff options
context:
space:
mode:
authorHaakon Dybdahl <dybis@users.noreply.github.com>2017-01-10 13:09:33 +0100
committerGitHub <noreply@github.com>2017-01-10 13:09:33 +0100
commitb28aadbeac85c8f40fece841fd387da946e058d7 (patch)
treef098b2b45e8efe34c36610fff39906dcfeb8a194 /vespaclient-container-plugin
parent8e67ba0904d753efdfa58d28ba60af895b04d4fa (diff)
parent2eddddc726ee821b9dd778697a96256abe489ba7 (diff)
Merge pull request #1467 from yahoo/dybdahl/destroy-sessions
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.java31
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(); }
}
}