summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2020-12-30 15:03:27 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-06-30 20:50:15 +0200
commiteaed7fa806a307ca712d6f099d089288b8caaf7a (patch)
tree5978ee251f5938f5be60cebe2bfa1c679c3f4d97 /container-core
parent1991465dbd06bee5377df35dba9dd87bac787e4a (diff)
Use an injected VespaDocumentAccess for streaming search
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/documentapi/VespaDocumentAccess.java34
1 files changed, 19 insertions, 15 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/documentapi/VespaDocumentAccess.java b/container-core/src/main/java/com/yahoo/container/core/documentapi/VespaDocumentAccess.java
index d55df15b2fd..bb78ee3022f 100644
--- a/container-core/src/main/java/com/yahoo/container/core/documentapi/VespaDocumentAccess.java
+++ b/container-core/src/main/java/com/yahoo/container/core/documentapi/VespaDocumentAccess.java
@@ -24,6 +24,8 @@ import com.yahoo.documentapi.messagebus.protocol.DocumentProtocolPoliciesConfig;
import com.yahoo.vespa.config.content.DistributionConfig;
import com.yahoo.vespa.config.content.LoadTypeConfig;
+import java.util.concurrent.atomic.AtomicReference;
+
/**
* Wraps a lazily initialised MessageBusDocumentAccess. Lazy to allow it to always be set up.
* Inject this class directly (instead of DocumentAccess) for use in internal code.
@@ -33,9 +35,8 @@ import com.yahoo.vespa.config.content.LoadTypeConfig;
public class VespaDocumentAccess extends DocumentAccess {
private final MessageBusParams parameters;
- private final Object monitor = new Object();
- private DocumentAccess delegate = null;
+ private final AtomicReference<MessageBusDocumentAccess> delegate = new AtomicReference<>();
private boolean shutDown = false;
VespaDocumentAccess(DocumentmanagerConfig documentmanagerConfig,
@@ -52,26 +53,29 @@ public class VespaDocumentAccess extends DocumentAccess {
this.parameters.getMessageBusParams().setMessageBusConfig(messagebusConfig);
}
- private DocumentAccess delegate() {
- synchronized (monitor) {
- if (delegate == null) {
- if (shutDown)
- throw new IllegalStateException("This document access has been shut down");
+ public MessageBusDocumentAccess delegate() {
+ MessageBusDocumentAccess access = delegate.getAcquire();
+ return access != null ? access : delegate.updateAndGet(value -> {
+ if (value != null)
+ return value;
+
+ if (shutDown)
+ throw new IllegalStateException("This document access has been shut down");
- delegate = new MessageBusDocumentAccess(parameters);
- }
- return delegate;
- }
+ return new MessageBusDocumentAccess(parameters);
+ });
}
@Override
public void shutdown() {
- synchronized (monitor) {
+ delegate.updateAndGet(access -> {
super.shutdown();
shutDown = true;
- if (delegate != null)
- delegate.shutdown();
- }
+ if (access != null)
+ access.shutdown();
+
+ return null;
+ });
}
@Override