/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.opensearch.search.asynchronous.context.permits; import org.opensearch.search.asynchronous.context.AsynchronousSearchContextId; import org.opensearch.search.asynchronous.context.active.AsynchronousSearchContextClosedException; import org.opensearch.action.ActionListener; import org.opensearch.common.lease.Releasable; import org.opensearch.common.unit.TimeValue; /** * NOOP context permit that responds with a NOOP {@linkplain Releasable} to release */ public class NoopAsynchronousSearchContextPermits extends AsynchronousSearchContextPermits { public NoopAsynchronousSearchContextPermits(AsynchronousSearchContextId asynchronousSearchContextId) { super(asynchronousSearchContextId, null, null); } @Override public void asyncAcquirePermit(final ActionListener onAcquired, final TimeValue timeout, String reason) { if (closed) { logger.debug("Trying to acquire permit for closed context [{}]", asynchronousSearchContextId); onAcquired.onFailure(new AsynchronousSearchContextClosedException(asynchronousSearchContextId)); } else { onAcquired.onResponse(() -> {}); } } @Override public void asyncAcquireAllPermits(ActionListener onAcquired, TimeValue timeout, String reason) { throw new IllegalStateException("Acquiring all permits is not allowed for asynchronous search id" + asynchronousSearchContextId); } }