Ooof....
Must must concurrent resourcepool.
No point in using a resource pool when you never hand anything back ....
@@ -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 {
- try {
SyncSession syncSession = syncSessions.alloc();
+ try {
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 {
- try {
SyncSession syncSession = syncSessions.alloc();
+ try {
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);
}
}
