diff options
Diffstat (limited to 'container-core')
2 files changed, 23 insertions, 16 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java b/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java index d98a865e1fb..087be0f17c5 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java @@ -13,7 +13,9 @@ import com.yahoo.container.core.config.HandlersConfigurerDi; import com.yahoo.container.di.CloudSubscriberFactory; import com.yahoo.container.di.ComponentDeconstructor; import com.yahoo.container.handler.threadpool.ContainerThreadPool; +import com.yahoo.jdisc.Metric; import com.yahoo.jdisc.handler.RequestHandler; +import com.yahoo.jdisc.test.MockMetric; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; @@ -139,6 +141,7 @@ public class HandlersConfigurerTestWrapper { // Needed by e.g. SearchHandler bind(Linguistics.class).to(SimpleLinguistics.class).in(Scopes.SINGLETON); bind(ContainerThreadPool.class).to(SimpleContainerThreadpool.class); + bind(Metric.class).to(MockMetric.class); } }); } 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..d01cd994fa5 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,8 +24,10 @@ 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. + * Wraps a lazily initialised {@link DocumentAccess}. Lazy to allow it to always be set up. * Inject this class directly (instead of DocumentAccess) for use in internal code. * * @author jonmv @@ -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<DocumentAccess> 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 DocumentAccess delegate() { + DocumentAccess 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 |