001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2023–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.bean;
015
016/**
017 * An interface whose implementation perform pre-destruction logic for contextual instances.
018 *
019 * <p>{@link PreDestructor}s are typically used during the execution of a {@link Factory}'s {@link
020 * Factory#destroy(Object, Request)} method.</p>
021 *
022 * @param <I> the type of contextual instance
023 *
024 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
025 *
026 * @see Factory#destroy(Object, Request)
027 */
028// Subordinate to Factory<I>.
029// Calls preDestroy() methods.
030@FunctionalInterface
031public interface PreDestructor<I> {
032
033  /**
034   * Performs pre-destruction logic for the supplied contextual instance.
035   *
036   * @param i a contextual instance; must not be {@code null}
037   *
038   * @param r a {@link Request}; msut not be {@code null}
039   *
040   * @return {@code i} as supplied
041   *
042   * @exception NullPointerException if either argument is {@code null}
043   */
044  public I preDestroy(final I i, final Request<I> r);
045
046}