001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- 002 * 003 * Copyright © 2022 microBean™. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 014 * implied. See the License for the specific language governing 015 * permissions and limitations under the License. 016 */ 017package org.microbean.loader.spi; 018 019import java.util.ServiceLoader; 020 021/** 022 * An instantiator of {@link ServiceLoader.Provider} instances. 023 * 024 * @author <a href="https://about.me/lairdnelson" 025 * target="_parent">Laird Nelson</a> 026 */ 027public interface ServiceProviderInstantiator { 028 029 /** 030 * Instantiates the supplied {@link ServiceLoader.Provider} and 031 * returns the resulting service provider. 032 * 033 * @param <T> the type of service provider to instantiate 034 * 035 * @param serviceLoaderProvider a {@link ServiceLoader.Provider}; 036 * must not be {@code null} 037 * 038 * @return a service provider; never {@code null} 039 * 040 * @exception NullPointerException if {@code 041 * serviceLoaderProvider} is {@code null} 042 * 043 * @nullability This method does not, and its overrides must not, 044 * return {@code null}. 045 * 046 * @idempotency The idempotency and determinism of any 047 * implementation of this method is left undefined. 048 * 049 * @threadsafety This method and any override is not guaranteed to 050 * be safe for concurrent use by multiple threads. 051 */ 052 public default <T> T instantiate(final ServiceLoader.Provider<? extends T> serviceLoaderProvider) { 053 return serviceLoaderProvider.get(); 054 } 055 056}