From c50b98dd4d410849733bbc8f947c625c805d1442 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 16 Jan 2017 14:26:07 +0100 Subject: Ooof.... - Must must concurrent resourcepool. - No point in using a resource pool when you never hand anything back .... --- .../document/restapi/OperationHandlerImpl.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java') 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 540e22090ea..5ad7524ca2f 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 @@ -21,8 +21,8 @@ import com.yahoo.vdslib.VisitorOrdering; import com.yahoo.vespaclient.ClusterDef; import com.yahoo.vespaclient.ClusterList; import com.yahoo.vespaxmlparser.VespaXMLFeedReader; +import com.yahoo.yolean.concurrent.ConcurrentResourcePool; import com.yahoo.yolean.concurrent.ResourceFactory; -import com.yahoo.yolean.concurrent.ResourcePool; import org.apache.commons.lang3.exception.ExceptionUtils; import java.io.ByteArrayOutputStream; @@ -52,11 +52,11 @@ public class OperationHandlerImpl implements OperationHandler { } } - private final ResourcePool syncSessions; + private final ConcurrentResourcePool syncSessions; public OperationHandlerImpl(DocumentAccess documentAccess) { this.documentAccess = documentAccess; - syncSessions = new ResourcePool<>(new SyncSessionFactory(documentAccess)); + syncSessions = new ConcurrentResourcePool<>(new SyncSessionFactory(documentAccess)); } @Override @@ -142,8 +142,8 @@ public class OperationHandlerImpl implements OperationHandler { @Override public void put(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + SyncSession syncSession = syncSessions.alloc(); try { - SyncSession syncSession = syncSessions.alloc(); DocumentPut put = new DocumentPut(data.getDocument()); put.setCondition(data.getCondition()); syncSession.put(put); @@ -151,26 +151,30 @@ 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 { + syncSessions.free(syncSession); } } @Override public void update(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + SyncSession syncSession = syncSessions.alloc(); try { - SyncSession syncSession = syncSessions.alloc(); 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 { + syncSessions.free(syncSession); } } @Override public void delete(RestUri restUri, String condition) throws RestApiException { + SyncSession syncSession = syncSessions.alloc(); try { DocumentId id = new DocumentId(restUri.generateFullId()); - SyncSession syncSession = syncSessions.alloc(); DocumentRemove documentRemove = new DocumentRemove(id); if (condition != null && ! condition.isEmpty()) { documentRemove.setCondition(new TestAndSetCondition(condition)); @@ -180,14 +184,16 @@ 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 { + syncSessions.free(syncSession); } } @Override public Optional get(RestUri restUri) throws RestApiException { + SyncSession syncSession = syncSessions.alloc(); try { DocumentId id = new DocumentId(restUri.generateFullId()); - SyncSession syncSession = syncSessions.alloc(); final Document document = syncSession.get(id); if (document == null) { return Optional.empty(); @@ -199,6 +205,8 @@ public class OperationHandlerImpl implements OperationHandler { } catch (Exception e) { throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + } finally { + syncSessions.free(syncSession); } } -- cgit v1.2.3