diff options
Diffstat (limited to 'docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus')
5 files changed, 30 insertions, 36 deletions
diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java index caaff318cdd..e1b9670dea8 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.docproc.jdisc.messagebus; import com.yahoo.component.provider.ComponentRegistry; @@ -32,6 +32,8 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; +import static java.util.logging.Level.WARNING; + /** * @author Einar M R Rosenvinge */ @@ -68,7 +70,7 @@ public class MbusRequestContext implements RequestContext, ResponseHandler { @Override public List<Processing> getProcessings() { if (deserialized.getAndSet(true)) { - return Collections.emptyList(); + return List.of(); } return processingFactory.fromMessage(requestMsg); } @@ -143,19 +145,17 @@ public class MbusRequestContext implements RequestContext, ResponseHandler { @Override public String getServiceName() { String path = getUri().getPath(); - return path.substring(7, path.length()); + return path.substring(7); } @Override public boolean isProcessable() { - Message msg = requestMsg; - switch (msg.getType()) { - case DocumentProtocol.MESSAGE_PUTDOCUMENT: - case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: - case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: - return true; - } - return false; + return switch (requestMsg.getType()) { + case DocumentProtocol.MESSAGE_PUTDOCUMENT, + DocumentProtocol.MESSAGE_UPDATEDOCUMENT, + DocumentProtocol.MESSAGE_REMOVEDOCUMENT -> true; + default -> false; + }; } @Override @@ -180,14 +180,12 @@ public class MbusRequestContext implements RequestContext, ResponseHandler { private void dispatchRequest(Message msg, String uriPath, ResponseHandler handler) { try { new RequestDispatch() { - @Override protected Request newRequest() { return new MbusRequest(request, uriCache.computeIfAbsent(uriPath, __ -> URI.create("mbus://remotehost" + uriPath)), msg); } - @Override public ContentChannel handleResponse(Response response) { return handler.handleResponse(response); @@ -195,7 +193,7 @@ public class MbusRequestContext implements RequestContext, ResponseHandler { }.dispatch(); } catch (Exception e) { dispatchResponse(Response.Status.INTERNAL_SERVER_ERROR); - e.printStackTrace(); + log.log(WARNING, "Failed to dispatch request", e); } } diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MessageFactory.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MessageFactory.java index 013f75c317c..b81e6b9ded7 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MessageFactory.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MessageFactory.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.docproc.jdisc.messagebus; import com.yahoo.docproc.Processing; diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java index bf6c75584be..030f95e380b 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ProcessingFactory.java @@ -1,10 +1,6 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.docproc.jdisc.messagebus; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; import com.yahoo.component.ComponentId; import com.yahoo.component.provider.ComponentRegistry; import com.yahoo.concurrent.SystemTimer; @@ -22,6 +18,10 @@ import com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage; import com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage; import com.yahoo.messagebus.Message; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + /** * @author Simon Thoresen Hult */ @@ -41,32 +41,28 @@ class ProcessingFactory { } public List<Processing> fromMessage(Message message) { - List<Processing> processings = new ArrayList<>(); - switch (message.getType()) { - case DocumentProtocol.MESSAGE_PUTDOCUMENT: { + return switch (message.getType()) { + case DocumentProtocol.MESSAGE_PUTDOCUMENT -> { PutDocumentMessage putMessage = (PutDocumentMessage) message; DocumentPut putOperation = new DocumentPut(createPutDocument(putMessage)); putOperation.setCondition(putMessage.getCondition()); putOperation.setCreateIfNonExistent(putMessage.getCreateIfNonExistent()); - processings.add(createProcessing(putOperation, message)); - break; + yield List.of(createProcessing(putOperation, message)); } - case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: { + case DocumentProtocol.MESSAGE_UPDATEDOCUMENT -> { UpdateDocumentMessage updateMessage = (UpdateDocumentMessage) message; DocumentUpdate updateOperation = updateMessage.getDocumentUpdate(); updateOperation.setCondition(updateMessage.getCondition()); - processings.add(createProcessing(updateOperation, message)); - break; + yield List.of(createProcessing(updateOperation, message)); } - case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: { + case DocumentProtocol.MESSAGE_REMOVEDOCUMENT -> { RemoveDocumentMessage removeMessage = (RemoveDocumentMessage) message; DocumentRemove removeOperation = new DocumentRemove(removeMessage.getDocumentId()); removeOperation.setCondition(removeMessage.getCondition()); - processings.add(createProcessing(removeOperation, message)); - break; + yield List.of(createProcessing(removeOperation, message)); } - } - return processings; + default -> List.of(); + }; } private Document createPutDocument(PutDocumentMessage msg) { @@ -82,7 +78,7 @@ class ProcessingFactory { String componentId = typeConfig.factorycomponent(); // Class name of the factory AbstractConcreteDocumentFactory cdf = docFactoryRegistry.getComponent(new ComponentId(componentId)); if (cdf == null) { - log.fine("Unable to get document factory component '" + componentId + "' from document factory registry."); + log.fine(() -> "Unable to get document factory component '" + componentId + "' from document factory registry."); return document; } return cdf.getDocumentCopy(document.getDataType().getName(), document, document.getId()); diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ResponseMerger.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ResponseMerger.java index fad1e651eec..4cb8fa1e92f 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ResponseMerger.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/ResponseMerger.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.docproc.jdisc.messagebus; import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/package-info.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/package-info.java index 7c4369a07ad..2454aaa6fed 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/package-info.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/package-info.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. @ExportPackage package com.yahoo.docproc.jdisc.messagebus; |