aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-04-25 19:57:57 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2019-04-25 19:57:57 +0200
commit907158959c159904c3f4d20274c565806746ac15 (patch)
treef4db3e3d2fc81cf061cb1811b5bc3af4ca91695f /vespaclient-container-plugin
parent249fe76c9437d0f1a033294df98d8d8101baef2c (diff)
Refactor to allow for lazy decode.
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java3
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java25
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/StreamReaderV3.java9
-rw-r--r--vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java6
4 files changed, 15 insertions, 28 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java
index ac2c9515d71..947fcb637fb 100644
--- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java
@@ -17,6 +17,7 @@ import com.yahoo.net.HostName;
import com.yahoo.vespa.http.client.core.ErrorCode;
import com.yahoo.vespa.http.client.core.Headers;
import com.yahoo.vespa.http.client.core.OperationStatus;
+import com.yahoo.vespaxmlparser.FeedOperation;
import com.yahoo.vespaxmlparser.VespaXMLFeedReader;
import com.yahoo.yolean.Exceptions;
@@ -274,7 +275,7 @@ class ClientFeederV3 {
/** Returns the next message in the stream, or null if none */
protected DocumentOperationMessageV3 getNextMessage(
String operationId, InputStream requestInputStream, FeederSettings settings) throws Exception {
- VespaXMLFeedReader.Operation operation = streamReaderV3.getNextOperation(requestInputStream, settings);
+ FeedOperation operation = streamReaderV3.getNextOperation(requestInputStream, settings);
// This is a bit hard to set up while testing, so we accept that things are not perfect.
if (sourceSession.getResource().session() != null) {
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java
index ca2fdd6b329..6df6bba5a59 100644
--- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/DocumentOperationMessageV3.java
@@ -9,11 +9,7 @@ import com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage;
import com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage;
import com.yahoo.jdisc.Metric;
import com.yahoo.messagebus.Message;
-import com.yahoo.messagebus.routing.ErrorDirective;
-import com.yahoo.messagebus.routing.Hop;
-import com.yahoo.messagebus.routing.Route;
-import com.yahoo.vespaxmlparser.VespaXMLFeedReader;
-import com.yahoo.yolean.Exceptions;
+import com.yahoo.vespaxmlparser.FeedOperation;
/**
* Keeps an operation with its message.
@@ -40,18 +36,7 @@ class DocumentOperationMessageV3 {
return operationId;
}
- static DocumentOperationMessageV3 newErrorMessage(String operationId, Exception exception) {
- Message feedErrorMessageV3 = new FeedErrorMessage(operationId);
- DocumentOperationMessageV3 msg = new DocumentOperationMessageV3(operationId, feedErrorMessageV3);
- Hop hop = new Hop();
- hop.addDirective(new ErrorDirective(Exceptions.toMessageString(exception)));
- Route route = new Route();
- route.addHop(hop);
- feedErrorMessageV3.setRoute(route);
- return msg;
- }
-
- static DocumentOperationMessageV3 newUpdateMessage(VespaXMLFeedReader.Operation op, String operationId) {
+ private static DocumentOperationMessageV3 newUpdateMessage(FeedOperation op, String operationId) {
DocumentUpdate update = op.getDocumentUpdate();
update.setCondition(op.getCondition());
Message msg = new UpdateDocumentMessage(update);
@@ -60,7 +45,7 @@ class DocumentOperationMessageV3 {
return new DocumentOperationMessageV3(id, msg);
}
- static DocumentOperationMessageV3 newRemoveMessage(VespaXMLFeedReader.Operation op, String operationId) {
+ static DocumentOperationMessageV3 newRemoveMessage(FeedOperation op, String operationId) {
DocumentRemove remove = new DocumentRemove(op.getRemove());
remove.setCondition(op.getCondition());
Message msg = new RemoveDocumentMessage(remove);
@@ -69,7 +54,7 @@ class DocumentOperationMessageV3 {
return new DocumentOperationMessageV3(id, msg);
}
- static DocumentOperationMessageV3 newPutMessage(VespaXMLFeedReader.Operation op, String operationId) {
+ private static DocumentOperationMessageV3 newPutMessage(FeedOperation op, String operationId) {
DocumentPut put = new DocumentPut(op.getDocument());
put.setCondition(op.getCondition());
Message msg = new PutDocumentMessage(put);
@@ -78,7 +63,7 @@ class DocumentOperationMessageV3 {
return new DocumentOperationMessageV3(id, msg);
}
- static DocumentOperationMessageV3 create(VespaXMLFeedReader.Operation operation, String operationId, Metric metric) {
+ static DocumentOperationMessageV3 create(FeedOperation operation, String operationId, Metric metric) {
switch (operation.getType()) {
case DOCUMENT:
metric.add(MetricNames.NUM_PUTS, 1, null /*metricContext*/);
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/StreamReaderV3.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/StreamReaderV3.java
index 00290c4fb09..69f810ad4c7 100644
--- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/StreamReaderV3.java
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/StreamReaderV3.java
@@ -5,8 +5,8 @@ import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.vespa.http.client.core.Encoder;
import com.yahoo.vespa.http.server.util.ByteLimitedInputStream;
+import com.yahoo.vespaxmlparser.FeedOperation;
import com.yahoo.vespaxmlparser.FeedReader;
-import com.yahoo.vespaxmlparser.VespaXMLFeedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -30,15 +30,14 @@ public class StreamReaderV3 {
this.docTypeManager = docTypeManager;
}
- public VespaXMLFeedReader.Operation getNextOperation(
- InputStream requestInputStream, FeederSettings settings) throws Exception {
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
+ public FeedOperation getNextOperation(InputStream requestInputStream, FeederSettings settings) throws Exception {
+ FeedOperation op = null;
int length = readByteLength(requestInputStream);
try (InputStream limitedInputStream = new ByteLimitedInputStream(requestInputStream, length)){
FeedReader reader = feedReaderFactory.createReader(limitedInputStream, docTypeManager, settings.dataFormat);
- reader.read(op);
+ op = reader.read();
}
return op;
}
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java
index b399b1197da..606d21c0059 100644
--- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java
+++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespaxmlparser/MockReader.java
@@ -45,9 +45,10 @@ public class MockReader implements FeedReader {
}
@Override
- public void read(Operation operation) throws Exception {
+ public FeedOperation read() throws Exception {
+ Operation operation = new Operation();
if (finished) {
- return;
+ return operation;
}
byte whatToDo = stream.getNextOperation();
@@ -70,6 +71,7 @@ public class MockReader implements FeedReader {
case 4:
throw new RuntimeException("boom");
}
+ return operation;
}
}