diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-16 14:26:07 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-16 14:26:07 +0100 |
commit | c50b98dd4d410849733bbc8f947c625c805d1442 (patch) | |
tree | d29a4ca5c89aff69a4c5d6eed301fdb83e473906 /vespaclient-container-plugin | |
parent | d01f32a695788b18c891aad8d462dc261cc5c260 (diff) |
Ooof....
- Must must concurrent resourcepool.
- No point in using a resource pool when you never hand anything back ....
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r-- | vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java | 22 |
1 files changed, 15 insertions, 7 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 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<SyncSession> syncSessions; + private final ConcurrentResourcePool<SyncSession> 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<String> 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); } } |