001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2024–2025 microBean™.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
006 * the License. You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
011 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
012 * specific language governing permissions and limitations under the License.
013 */
014package org.microbean.reference;
015
016import java.util.function.Supplier;
017
018import org.microbean.bean.Request;
019
020/**
021 * A factory for {@link Supplier}s of contextual instances.
022 *
023 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
024 *
025 * @see #supplier(Request)
026 */
027public interface Instances extends AutoCloseable, InstanceRemover {
028
029  @Override // AutoCloseable
030  public default void close() {
031
032  }
033
034  /**
035   * Returns {@code true} if and only if the supplied {@link Request} should result in a contextual reference that is a
036   * <dfn>client proxy</dfn>.
037   *
038   * @param request a {@link Request}; may be {@code null}
039   *
040   * @return {@code true} if and only if the supplied {@link Request} should result in a contextual reference that is a
041   * <dfn>client proxy</dfn>
042   */
043  public boolean proxiable(final Request<?> request);
044
045  /**
046   * Returns a {@link Supplier} of contextual instances appropriate for the given {@link Request}.
047   *
048   * @param <I> the type of the contextual instance being requested
049   *
050   * @param request a {@link Request}; may be {@code null}
051   *
052   * @return a non-{@code null} {@link Supplier} of contextual instances of the appropriate type
053   */
054  public <I> Supplier<? extends I> supplier(final Request<I> request);
055
056}