diff options
24 files changed, 105 insertions, 135 deletions
diff --git a/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusClient.java b/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusClient.java index dee4e3dcfbb..d570747ad11 100644 --- a/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusClient.java +++ b/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusClient.java @@ -90,7 +90,7 @@ public final class MbusClient extends AbstractResource implements ClientProvider @Override public void handleReply(final Reply reply) { reply.getTrace().trace(6, "Reply received by MbusClient."); - final ResponseHandler handler = (ResponseHandler)reply.getContext(); + ResponseHandler handler = (ResponseHandler) reply.getContext(); reply.popHandler(); // restore user context try { handler.handleResponse(new MbusResponse(StatusCodes.fromMbusReply(reply), reply)) diff --git a/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusServer.java b/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusServer.java index 4c21489ded2..42fbec7711d 100644 --- a/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusServer.java +++ b/container-messagebus/src/main/java/com/yahoo/messagebus/jdisc/MbusServer.java @@ -67,6 +67,8 @@ public final class MbusServer extends AbstractResource implements ServerProvider @Override protected void destroy() { log.log(Level.INFO, "Destroying message bus server: " + session.name()); + if (runState.get() == State.RUNNING) + log.log(Level.WARNING, "Message bus server destroyed before being disconnected: " + session.name()); runState.set(State.STOPPED); sessionReference.close(); } @@ -79,6 +81,7 @@ public final class MbusServer extends AbstractResource implements ServerProvider return; } if (state == State.STOPPED) { + log.log(Level.WARNING, "Message bus server received message after being stopped: " + session.name()); dispatchErrorReply(msg, ErrorCode.NETWORK_SHUTDOWN, "MBusServer has been closed."); return; } diff --git a/container-messagebus/src/main/java/com/yahoo/messagebus/shared/SharedIntermediateSession.java b/container-messagebus/src/main/java/com/yahoo/messagebus/shared/SharedIntermediateSession.java index 1b3a9afff7b..2283f703463 100644 --- a/container-messagebus/src/main/java/com/yahoo/messagebus/shared/SharedIntermediateSession.java +++ b/container-messagebus/src/main/java/com/yahoo/messagebus/shared/SharedIntermediateSession.java @@ -109,4 +109,5 @@ public class SharedIntermediateSession extends AbstractResource session.destroy(); mbusReference.close(); } + } diff --git a/docproc/src/main/java/com/yahoo/docproc/impl/DocprocService.java b/docproc/src/main/java/com/yahoo/docproc/impl/DocprocService.java index b25743fbcde..01df2415ff4 100644 --- a/docproc/src/main/java/com/yahoo/docproc/impl/DocprocService.java +++ b/docproc/src/main/java/com/yahoo/docproc/impl/DocprocService.java @@ -398,7 +398,6 @@ public class DocprocService extends AbstractComponent { } } - private class NoCallStackException extends RuntimeException { - } + private static class NoCallStackException extends RuntimeException { } } diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java index 4c3292b557b..73d72aabcb9 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingHandler.java @@ -116,7 +116,11 @@ public class DocumentProcessingHandler extends AbstractRequestHandler { @Override protected void destroy() { laterExecutor.shutdown(); - docprocServiceRegistry.allComponents().forEach(docprocService -> docprocService.deconstruct()); + if ( ! laterExecutor.getQueue().isEmpty()) { + // This should not happen, as container should keep this alive until all requests are served. + log.log(Level.SEVERE, "Docproc laterExecutor queue not empty on shutdown, " + laterExecutor.getQueue().size() + " tasks discarded"); + } + docprocServiceRegistry.allComponents().forEach(DocprocService::deconstruct); } public ComponentRegistry<DocprocService> getDocprocServiceRegistry() { @@ -147,7 +151,7 @@ public class DocumentProcessingHandler extends AbstractRequestHandler { public ContentChannel handleRequest(Request request, ResponseHandler handler) { RequestContext requestContext; if (request instanceof MbusRequest) { - requestContext = new MbusRequestContext((MbusRequest) request, handler, docprocServiceRegistry, docFactoryRegistry, containerDocConfig); + requestContext = new MbusRequestContext((MbusRequest) request, handler, docFactoryRegistry, containerDocConfig); } else { //Other types can be added here in the future throw new IllegalArgumentException("Request type not supported: " + request); diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java index 8bcce9e892d..3c6e63bf5e4 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/DocumentProcessingTask.java @@ -26,7 +26,7 @@ import java.util.logging.Logger; */ public class DocumentProcessingTask implements Runnable { - private static Logger log = Logger.getLogger(DocumentProcessingTask.class.getName()); + private static final Logger log = Logger.getLogger(DocumentProcessingTask.class.getName()); private final List<Processing> processings = new ArrayList<>(); private final List<Processing> processingsDone = new ArrayList<>(); diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/RequestContext.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/RequestContext.java index ce92965e2df..6ec21c507cc 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/RequestContext.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/RequestContext.java @@ -28,7 +28,7 @@ public interface RequestContext { void processingFailed(Exception exception); /** Returns whether this request has timed out */ - default boolean hasExpired() { return false;} + default boolean hasExpired() { return false; } void skip(); 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 e1b9670dea8..bbdabd53084 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 @@ -5,7 +5,6 @@ import com.yahoo.component.provider.ComponentRegistry; import com.yahoo.concurrent.CopyOnWriteHashMap; import com.yahoo.container.core.document.ContainerDocumentConfig; import com.yahoo.docproc.AbstractConcreteDocumentFactory; -import com.yahoo.docproc.impl.DocprocService; import com.yahoo.docproc.impl.HandledProcessingException; import com.yahoo.docproc.Processing; import com.yahoo.docproc.impl.TransientFailureException; @@ -56,11 +55,10 @@ public class MbusRequestContext implements RequestContext, ResponseHandler { private final static String internalNoThrottledSourcePath = "/" + internalNoThrottledSource; public MbusRequestContext(MbusRequest request, ResponseHandler responseHandler, - ComponentRegistry<DocprocService> docprocServiceComponentRegistry, ComponentRegistry<AbstractConcreteDocumentFactory> docFactoryRegistry, ContainerDocumentConfig containerDocConfig) { this.request = request; - this.requestMsg = (DocumentMessage)request.getMessage(); + this.requestMsg = (DocumentMessage) request.getMessage(); this.responseHandler = responseHandler; this.processingFactory = new ProcessingFactory(docFactoryRegistry, containerDocConfig, getServiceName()); diff --git a/documentapi/src/main/java/com/yahoo/documentapi/Response.java b/documentapi/src/main/java/com/yahoo/documentapi/Response.java index eb759e2914a..63c9550474f 100644 --- a/documentapi/src/main/java/com/yahoo/documentapi/Response.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/Response.java @@ -105,10 +105,10 @@ public class Response { /** The operation was a success. */ SUCCESS, - /** The operation failed due to an unmet test-and-set condition. */ + /** The operation was not carried out due to an unmet test-and-set condition. */ CONDITION_FAILED, - /** The operation failed because its target document was not found. */ + /** The operation was not carried out because its target document was not found. */ NOT_FOUND, /** The operation failed because the cluster had insufficient storage to accept it. */ diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/MessageBusAsyncSession.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/MessageBusAsyncSession.java index 4776804a686..2d1792442a0 100644 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/MessageBusAsyncSession.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/MessageBusAsyncSession.java @@ -290,18 +290,17 @@ public class MessageBusAsyncSession implements MessageBusSession, AsyncSession { Message msg = reply.getMessage(); String err = getErrorMessage(reply); Response.Outcome outcome = toOutcome(reply); - switch (msg.getType()) { - case DocumentProtocol.MESSAGE_PUTDOCUMENT: - return new DocumentResponse(reqId, ((PutDocumentMessage)msg).getDocumentPut().getDocument(), err, outcome, reply.getTrace()); - case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: - return new DocumentUpdateResponse(reqId, ((UpdateDocumentMessage)msg).getDocumentUpdate(), err, outcome, reply.getTrace()); - case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: - return new DocumentIdResponse(reqId, ((RemoveDocumentMessage)msg).getDocumentId(), err, outcome, reply.getTrace()); - case DocumentProtocol.MESSAGE_GETDOCUMENT: - return new DocumentIdResponse(reqId, ((GetDocumentMessage)msg).getDocumentId(), err, outcome, reply.getTrace()); - default: - return new Response(reqId, err, outcome, reply.getTrace()); - } + return switch (msg.getType()) { + case DocumentProtocol.MESSAGE_PUTDOCUMENT -> + new DocumentResponse(reqId, ((PutDocumentMessage) msg).getDocumentPut().getDocument(), err, outcome, reply.getTrace()); + case DocumentProtocol.MESSAGE_UPDATEDOCUMENT -> + new DocumentUpdateResponse(reqId, ((UpdateDocumentMessage) msg).getDocumentUpdate(), err, outcome, reply.getTrace()); + case DocumentProtocol.MESSAGE_REMOVEDOCUMENT -> + new DocumentIdResponse(reqId, ((RemoveDocumentMessage) msg).getDocumentId(), err, outcome, reply.getTrace()); + case DocumentProtocol.MESSAGE_GETDOCUMENT -> + new DocumentIdResponse(reqId, ((GetDocumentMessage) msg).getDocumentId(), err, outcome, reply.getTrace()); + default -> new Response(reqId, err, outcome, reply.getTrace()); + }; } private static Response toSuccess(Reply reply, long reqId) { diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java index 03932d1b69e..5af78d97509 100644 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java @@ -595,13 +595,11 @@ public class ContentPolicy extends SlobrokPolicy { return !reply.hasErrors(); // For simplicity, count any reply with > 1 error. } var error = reply.getError(0); - switch (error.getCode()) { + return switch (error.getCode()) { // TODO this feels like a layering violation, but we use DocumentProtocol directly in other places in this policy anyway... - case DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED: - case DocumentProtocol.ERROR_BUSY: - return false; - default: return true; - } + case DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED, DocumentProtocol.ERROR_BUSY -> false; + default -> true; + }; } void handleErrorReply(Reply reply, Object untypedContext) { diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java index b53446e9d39..ec49a0c570f 100755 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentProtocol.java @@ -157,7 +157,7 @@ public class DocumentProtocol implements Protocol { /** We failed accessing the disk, which we think is a disk hardware problem. */ public static final int ERROR_DISK_FAILURE = ErrorCode.APP_TRANSIENT_ERROR + 1007; - /** We failed during an IO operation, we dont think is a specific disk hardware problem. */ + /** We failed during an IO operation, we don't think is a specific disk hardware problem. */ public static final int ERROR_IO_FAILURE = ErrorCode.APP_TRANSIENT_ERROR + 1008; /** diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/ProxyRequestHandler.java b/jdisc_core/src/main/java/com/yahoo/jdisc/ProxyRequestHandler.java index 19bb4a64a01..6edc4d105f0 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/ProxyRequestHandler.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/ProxyRequestHandler.java @@ -31,9 +31,9 @@ class ProxyRequestHandler implements DelegatedRequestHandler { @Override public ContentChannel handleRequest(Request request, ResponseHandler responseHandler) { - try (final ResourceReference requestReference = request.refer()) { + try (ResourceReference requestReference = request.refer()) { ContentChannel contentChannel; - final ResponseHandler proxyResponseHandler = new ProxyResponseHandler( + ResponseHandler proxyResponseHandler = new ProxyResponseHandler( request, new NullContentResponseHandler(responseHandler)); try { contentChannel = delegate.handleRequest(request, proxyResponseHandler); diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/References.java b/jdisc_core/src/main/java/com/yahoo/jdisc/References.java index 5b845754d3d..6cae0c48c56 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/References.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/References.java @@ -7,27 +7,22 @@ package com.yahoo.jdisc; * @author bakksjo */ public class References { - // Prevents instantiation. - private References() { - } + + private References() { } /** * A {@link ResourceReference} that does nothing. * Useful for e.g. testing of resource types when reference counting is not the focus. */ - public static final ResourceReference NOOP_REFERENCE = new ResourceReference() { - @Override - public void close() { - } - }; + public static final ResourceReference NOOP_REFERENCE = () -> { }; /** * <p>Returns a {@link ResourceReference} that invokes {@link SharedResource#release()} on * {@link ResourceReference#close() close}. Useful for treating the "main" reference of a {@link SharedResource} * just as any other reference obtained by calling {@link SharedResource#refer()}. Example:</p> * <pre> - * final Request request = new Request(...); - * try (final ResourceReference ref = References.fromResource(request)) { + * Request request = new Request(...); + * try (ResourceReference ref = References.fromResource(request)) { * .... * } * // The request will be released on exit from the try block. @@ -36,12 +31,8 @@ public class References { * @param resource The resource to create a ResourceReference for. * @return a ResourceReference whose close() method will call release() on the given resource. */ - public static ResourceReference fromResource(final SharedResource resource) { - return new ResourceReference() { - @Override - public void close() { - resource.release(); - } - }; + public static ResourceReference fromResource(SharedResource resource) { + return resource::release; } + } diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java b/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java index 61f7c04ec9a..91741fc7d4d 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java @@ -41,7 +41,7 @@ public class Request extends AbstractResource { private final HeaderFields headers = new HeaderFields(); private final Container container; private final Request parent; - private final ResourceReference parentReference; + private final ResourceReference resourceReference; private final long creationTime; private final boolean serverRequest; private final URI uri; @@ -83,15 +83,17 @@ public class Request extends AbstractResource { this(current, uri, true); } - public Request(CurrentContainer current, URI uri, boolean isServerRequest) { this(current, uri, isServerRequest, -1); } + public Request(CurrentContainer current, URI uri, boolean isServerRequest) { + this(current, uri, isServerRequest, -1); + } public Request(CurrentContainer current, URI uri, boolean isServerRequest, long creationTime) { - parent = null; - parentReference = null; - serverRequest = isServerRequest; + this.parent = null; + this.container = current.newReference(uri, this); + this.resourceReference = container::release; this.uri = uri.normalize(); - container = current.newReference(uri, this); this.creationTime = creationTime >= 0 ? creationTime : container.currentTimeMillis(); + this.serverRequest = isServerRequest; } @@ -121,11 +123,11 @@ public class Request extends AbstractResource { */ public Request(Request parent, URI uri) { this.parent = parent; - container = null; - creationTime = parent.container().currentTimeMillis(); - serverRequest = false; + this.container = null; + this.resourceReference = parent.refer(this); this.uri = uri.normalize(); - parentReference = this.parent.refer(this); + this.creationTime = parent.container().currentTimeMillis(); + this.serverRequest = false; } /** Returns the {@link Container} for which this Request was created */ @@ -140,7 +142,7 @@ public class Request extends AbstractResource { public URI getUri() { return uri; } /** - * Returns whether or not this Request was created by a {@link ServerProvider}. The value of this is used by + * Returns whether this Request was created by a {@link ServerProvider}. The value of this is used by * {@link Container#resolveHandler(Request)} to decide whether to match against server- or client-bindings. * * @return true, if this is a server request @@ -395,12 +397,7 @@ public class Request extends AbstractResource { @Override protected void destroy() { - if (parentReference != null) { - parentReference.close(); - } - if (container != null) { - container.release(); - } + resourceReference.close(); } } diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java b/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java index 6209c74374e..449c597bdc7 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java @@ -6,8 +6,8 @@ package com.yahoo.jdisc; * * <p>Implements {@link AutoCloseable} so that it can be used in try-with-resources statements. Example</p> * <pre> - * void doSomethingWithRequest(final Request request) { - * try (final ResourceReference ref = request.refer()) { + * void doSomethingWithRequest(Request request) { + * try (ResourceReference ref = request.refer()) { * // Do something with request * } * // ref.close() will be called automatically on exit from the try block, releasing the reference on 'request'. diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java index e172b5d1f64..6550d9b5386 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java @@ -13,6 +13,9 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + +import static java.util.stream.Collectors.toUnmodifiableMap; /** * <p>This is the inactive, mutable {@link Container}. Because it requires references to the application internals, it @@ -35,9 +38,7 @@ public class ContainerBuilder { public ContainerBuilder(Iterable<Module> guiceModules) { this.guiceModules.installAll(guiceModules); this.guiceModules.install(new AbstractModule() { - - @Override - public void configure() { + @Override public void configure() { bind(ContainerBuilder.class).toInstance(ContainerBuilder.this); } }); @@ -73,42 +74,26 @@ public class ContainerBuilder { return serverBindings.get(BindingSet.DEFAULT); } - public BindingRepository<RequestHandler> serverBindings(String setName) { - BindingRepository<RequestHandler> ret = serverBindings.get(setName); - if (ret == null) { - ret = new BindingRepository<>(); - serverBindings.put(setName, ret); - } - return ret; + public BindingRepository<RequestHandler> clientBindings() { + return clientBindings.get(BindingSet.DEFAULT); } - public Map<String, BindingSet<RequestHandler>> activateServerBindings() { - Map<String, BindingSet<RequestHandler>> ret = new HashMap<>(); - for (Map.Entry<String, BindingRepository<RequestHandler>> entry : serverBindings.entrySet()) { - ret.put(entry.getKey(), entry.getValue().activate()); - } - return ImmutableMap.copyOf(ret); + public BindingRepository<RequestHandler> serverBindings(String setName) { + return serverBindings.computeIfAbsent(setName, __ -> new BindingRepository<>()); } - public BindingRepository<RequestHandler> clientBindings() { - return clientBindings.get(BindingSet.DEFAULT); + public BindingRepository<RequestHandler> clientBindings(String setName) { + return clientBindings.computeIfAbsent(setName, __ -> new BindingRepository<>()); } - public BindingRepository<RequestHandler> clientBindings(String setName) { - BindingRepository<RequestHandler> ret = clientBindings.get(setName); - if (ret == null) { - ret = new BindingRepository<>(); - clientBindings.put(setName, ret); - } - return ret; + public Map<String, BindingSet<RequestHandler>> activateServerBindings() { + return serverBindings.entrySet().stream().collect(toUnmodifiableMap(entry -> entry.getKey(), + entry -> entry.getValue().activate())); } public Map<String, BindingSet<RequestHandler>> activateClientBindings() { - Map<String, BindingSet<RequestHandler>> ret = new HashMap<>(); - for (Map.Entry<String, BindingRepository<RequestHandler>> entry : clientBindings.entrySet()) { - ret.put(entry.getKey(), entry.getValue().activate()); - } - return ImmutableMap.copyOf(ret); + return clientBindings.entrySet().stream().collect(toUnmodifiableMap(entry -> entry.getKey(), + entry -> entry.getValue().activate())); } @SuppressWarnings({ "unchecked" }) diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java index 53fb81fb6db..e2d2da660c7 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java @@ -37,12 +37,12 @@ public class ActiveContainer extends AbstractResource implements CurrentContaine serverProviders = builder.serverProviders().activate(); serverProviders.forEach(resourceReferences::retain); serverBindings = builder.activateServerBindings(); - serverBindings.forEach( - (ignoredName, bindingSet) -> bindingSet.forEach( + serverBindings.values().forEach( + bindingSet -> bindingSet.forEach( binding -> resourceReferences.retain(binding.getValue()))); clientBindings = builder.activateClientBindings(); - clientBindings.forEach( - (ignoredName, bindingSet) -> bindingSet.forEach( + clientBindings.values().forEach( + bindingSet -> bindingSet.forEach( binding -> resourceReferences.retain(binding.getValue()))); bindingSetSelector = builder.getInstance(BindingSetSelector.class); timeoutMgr = builder.getInstance(TimeoutManagerImpl.class); diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/FutureResponse.java b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/FutureResponse.java index d5eda23a8d6..4730535640c 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/FutureResponse.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/FutureResponse.java @@ -30,18 +30,10 @@ public final class FutureResponse extends CompletableFuture<Response> implements * * @param content The content channel for the Response. */ - public FutureResponse(final ContentChannel content) { - this(new ResponseHandler() { - - @Override - public ContentChannel handleResponse(Response response) { - return content; - } - }); + public FutureResponse(ContentChannel content) { + this(response -> content); } - public void addListener(Runnable r, Executor e) { whenCompleteAsync((__, ___) -> r.run(), e); } - /** * <p>Constructs a new FutureResponse that calls the given {@link ResponseHandler} when {@link * #handleResponse(Response)} is invoked.</p> @@ -52,6 +44,8 @@ public final class FutureResponse extends CompletableFuture<Response> implements this.handler = handler; } + public void addListener(Runnable r, Executor e) { whenCompleteAsync((__, ___) -> r.run(), e); } + @Override public ContentChannel handleResponse(Response response) { complete(response); diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java index b60b62e3f86..ef420d69f16 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java @@ -27,7 +27,7 @@ import java.util.concurrent.TimeoutException; * * <p>The following is a simple example on how to use this class:</p> * <pre> - * public void handleRequest(final Request parent, final ResponseHandler handler) { + * public void handleRequest(Request parent, ResponseHandler handler) { * new RequestDispatch() { * @Override * protected Request newRequest() { @@ -80,8 +80,8 @@ public abstract class RequestDispatch implements Future<Response>, ResponseHandl * @return The ContentChannel to write the Request's content to. */ public final ContentChannel connect() { - final Request request = newRequest(); - try (final ResourceReference ref = References.fromResource(request)) { + Request request = newRequest(); + try (ResourceReference ref = References.fromResource(request)) { return request.connect(futureResponse); } } diff --git a/jrt/src/com/yahoo/jrt/TransportThread.java b/jrt/src/com/yahoo/jrt/TransportThread.java index 68b7c23b36b..870d1ce7adc 100644 --- a/jrt/src/com/yahoo/jrt/TransportThread.java +++ b/jrt/src/com/yahoo/jrt/TransportThread.java @@ -296,6 +296,9 @@ public class TransportThread { */ public TransportThread sync() { SyncCmd cmd = new SyncCmd(); + if (Thread.currentThread() == thread) { + log.log(Level.WARNING, "Attempting to sync " + thread + " with itself, which will deadlock"); + } if (postCommand(cmd)) { cmd.waitDone(); } else { diff --git a/messagebus/src/main/java/com/yahoo/messagebus/IntermediateSession.java b/messagebus/src/main/java/com/yahoo/messagebus/IntermediateSession.java index 7e8286d8793..805242665ca 100644 --- a/messagebus/src/main/java/com/yahoo/messagebus/IntermediateSession.java +++ b/messagebus/src/main/java/com/yahoo/messagebus/IntermediateSession.java @@ -63,13 +63,11 @@ public final class IntermediateSession implements MessageHandler, ReplyHandler, * @param routable the routable to forward. */ public void forward(Routable routable) { - if (routable instanceof Reply) { - Reply reply = (Reply)routable; - ReplyHandler handler = reply.popHandler(); - handler.handleReply(reply); + if (routable instanceof Reply reply) { + reply.popHandler().handleReply(reply); } else { routable.pushHandler(this); - mbus.handleMessage((Message)routable); + mbus.handleMessage((Message) routable); } } diff --git a/messagebus/src/main/java/com/yahoo/messagebus/MessageBus.java b/messagebus/src/main/java/com/yahoo/messagebus/MessageBus.java index eeea999cc14..4a443a9fde5 100644 --- a/messagebus/src/main/java/com/yahoo/messagebus/MessageBus.java +++ b/messagebus/src/main/java/com/yahoo/messagebus/MessageBus.java @@ -367,7 +367,7 @@ public class MessageBus implements ConfigHandler, NetworkOwner, MessageHandler, * sessions from receiving data from message bus.</p> * * @param name The name of the session to remove. - * @param broadcastName Whether or not session name was broadcast. + * @param broadcastName Whether session name was broadcast. */ public synchronized void unregisterSession(String name, boolean broadcastName) { net.unregisterSession(name, this, broadcastName); diff --git a/messagebus/src/main/java/com/yahoo/messagebus/Messenger.java b/messagebus/src/main/java/com/yahoo/messagebus/Messenger.java index 794ac152c9f..974eb54d779 100755 --- a/messagebus/src/main/java/com/yahoo/messagebus/Messenger.java +++ b/messagebus/src/main/java/com/yahoo/messagebus/Messenger.java @@ -42,7 +42,7 @@ public class Messenger implements Runnable { * * @param task The task to add. */ - void addRecurrentTask(final Task task) { + void addRecurrentTask(Task task) { children.add(task); } @@ -64,7 +64,7 @@ public class Messenger implements Runnable { * @param msg The message to send. * @param handler The handler to send to. */ - public void deliverMessage(final Message msg, final MessageHandler handler) { + public void deliverMessage(Message msg, MessageHandler handler) { if (destroyed.get()) { msg.discard(); } else { @@ -80,7 +80,7 @@ public class Messenger implements Runnable { * @param reply The reply to return. * @param handler The handler to return to. */ - public void deliverReply(final Reply reply, final ReplyHandler handler) { + public void deliverReply(Reply reply, ReplyHandler handler) { if (destroyed.get()) { reply.discard(); } else { @@ -95,7 +95,7 @@ public class Messenger implements Runnable { * * @param task The task to enqueue. */ - public void enqueue(final Task task) { + public void enqueue(Task task) { if (destroyed.get()) { task.destroy(); return; @@ -116,7 +116,7 @@ public class Messenger implements Runnable { if (Thread.currentThread() == thread) { return; // no need to wait for self } - final SyncTask task = new SyncTask(); + SyncTask task = new SyncTask(); enqueue(task); task.await(); } @@ -140,7 +140,7 @@ public class Messenger implements Runnable { } } thread.join(); - } catch (final InterruptedException e) { + } catch (InterruptedException e) { // ignore } done = true; @@ -161,7 +161,7 @@ public class Messenger implements Runnable { } else { wait(timeoutMS); } - } catch (final InterruptedException e) { + } catch (InterruptedException e) { continue; } } @@ -175,26 +175,26 @@ public class Messenger implements Runnable { if (task != null) { try { task.run(); - } catch (final Exception e) { + } catch (Exception e) { log.log(Level.SEVERE, "An exception was thrown while running " + task.getClass().getName(), e); } try { task.destroy(); - } catch (final Exception e) { + } catch (Exception e) { log.warning("An exception was thrown while destroying " + task.getClass().getName() + ": " + e); log.warning("Someone, somewhere might have to wait indefinitely for something."); } } - for (final Task child : children) { + for (Task child : children) { child.run(); } } - for (final Task child : children) { + for (Task child : children) { child.destroy(); } synchronized (this) { while (!queue.isEmpty()) { - final Task task = queue.poll(); + Task task = queue.poll(); task.destroy(); } notify(); @@ -236,7 +236,7 @@ public class Messenger implements Runnable { public void await() { try { latch.await(); - } catch (final InterruptedException e) { + } catch (InterruptedException e) { // ignore } } |