From 8993b9df81bf0acbbe42db002a202f46f019e7e6 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 27 Apr 2023 14:30:27 +0200 Subject: Unify passing of all feed operations through the various feed apis. --- .../com/yahoo/vespa/feed/perf/SimpleFeeder.java | 39 ++++++++++------------ 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'vespaclient-java/src/main/java/com/yahoo') diff --git a/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java b/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java index 189ac69ea91..e29e32aee92 100644 --- a/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java +++ b/vespaclient-java/src/main/java/com/yahoo/vespa/feed/perf/SimpleFeeder.java @@ -6,6 +6,7 @@ import com.yahoo.config.subscription.ConfigSubscriber; import com.yahoo.document.Document; import com.yahoo.document.DocumentId; import com.yahoo.document.DocumentPut; +import com.yahoo.document.DocumentRemove; import com.yahoo.document.DocumentTypeManager; import com.yahoo.document.DocumentTypeManagerConfigurer; import com.yahoo.document.DocumentUpdate; @@ -196,7 +197,7 @@ public class SimpleFeeder implements ReplyHandler { } else { isFirst = false; } - writer.write(op.getDocument()); + writer.write(op.getDocumentPut().getDocument()); } numReplies.incrementAndGet(); } @@ -234,13 +235,13 @@ public class SimpleFeeder implements ReplyHandler { DocumentSerializer writer = DocumentSerializerFactory.createHead(buffer); int type = NONE; if (op.getType() == FeedOperation.Type.DOCUMENT) { - writer.write(op.getDocument()); + writer.write(op.getDocumentPut().getDocument()); type = DOCUMENT; } else if (op.getType() == FeedOperation.Type.UPDATE) { writer.write(op.getDocumentUpdate()); type = UPDATE; } else if (op.getType() == FeedOperation.Type.REMOVE) { - writer.write(op.getRemove()); + writer.write(op.getDocumentRemove().getId()); type = REMOVE; } int sz = buffer.position(); @@ -292,8 +293,10 @@ public class SimpleFeeder implements ReplyHandler { } @Override - public Document getDocument() { - return new Document(deserializer); + public DocumentPut getDocumentPut() { + DocumentPut put = new DocumentPut(new Document(deserializer)); + put.setCondition(getCondition()); + return put; } } static class LazyUpdateOperation extends ConditionalFeedOperation { @@ -305,7 +308,9 @@ public class SimpleFeeder implements ReplyHandler { @Override public DocumentUpdate getDocumentUpdate() { - return new DocumentUpdate(deserializer); + DocumentUpdate update = new DocumentUpdate(deserializer); + update.setCondition(getCondition()); + return update; } } @@ -339,7 +344,9 @@ public class SimpleFeeder implements ReplyHandler { } else if (type == UPDATE) { return new LazyUpdateOperation(deser, testAndSetCondition); } else if (type == REMOVE) { - return new RemoveFeedOperation(new DocumentId(deser), testAndSetCondition); + var remove = new DocumentRemove(new DocumentId(deser)); + remove.setCondition(testAndSetCondition); + return new RemoveFeedOperation(remove); } else { throw new IllegalArgumentException("Unknown operation " + type); } @@ -426,21 +433,9 @@ public class SimpleFeeder implements ReplyHandler { private static Message newMessage(FeedOperation op) { return switch (op.getType()) { - case DOCUMENT -> { - PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(op.getDocument())); - message.setCondition(op.getCondition()); - yield message; - } - case REMOVE -> { - RemoveDocumentMessage message = new RemoveDocumentMessage(op.getRemove()); - message.setCondition(op.getCondition()); - yield message; - } - case UPDATE -> { - UpdateDocumentMessage message = new UpdateDocumentMessage(op.getDocumentUpdate()); - message.setCondition(op.getCondition()); - yield message; - } + case DOCUMENT -> new PutDocumentMessage(op.getDocumentPut()); + case REMOVE -> new RemoveDocumentMessage(op.getDocumentRemove()); + case UPDATE -> new UpdateDocumentMessage(op.getDocumentUpdate()); default -> null; }; } -- cgit v1.2.3