| 1 |
/* |
| 2 |
* JBoss, Home of Professional Open Source |
| 3 |
* Copyright 2016, Red Hat, Inc., and individual contributors |
| 4 |
* by the @authors tag. See the copyright.txt in the distribution for a |
| 5 |
* full listing of individual contributors. |
| 6 |
* |
| 7 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
* you may not use this file except in compliance with the License. |
| 9 |
* You may obtain a copy of the License at |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
package jakarta.enterprise.inject.spi.configurator; |
| 18 |
|
| 19 |
import java.util.function.Consumer; |
| 20 |
import java.util.function.Function; |
| 21 |
|
| 22 |
import jakarta.enterprise.context.spi.CreationalContext; |
| 23 |
import jakarta.enterprise.inject.spi.ProcessProducer; |
| 24 |
import jakarta.enterprise.inject.spi.Producer; |
| 25 |
|
| 26 |
/** |
| 27 |
* <p> |
| 28 |
* A {@link ProducerConfigurator} can configure a {@link Producer}. The container must provide an implementation of this |
| 29 |
* interface. |
| 30 |
* </p> |
| 31 |
* |
| 32 |
* <p> |
| 33 |
* This configurator is not thread safe and shall not be used concurrently. |
| 34 |
* </p> |
| 35 |
* |
| 36 |
* <p>CDI Lite implementations are not required to provide support for Portable Extensions.</p> |
| 37 |
* |
| 38 |
* @param <T> The return type of the producer method or the type of the producer field |
| 39 |
* @author Martin Kouba |
| 40 |
* @see ProcessProducer#configureProducer() |
| 41 |
* @since 2.0 |
| 42 |
*/ |
| 43 |
public interface ProducerConfigurator<T> { |
| 44 |
|
| 45 |
/** |
| 46 |
* Set a callback to produce a new instance. |
| 47 |
* |
| 48 |
* @param <U> instance type |
| 49 |
* @param callback a {@link Function} defining the callback to set |
| 50 |
* @return self |
| 51 |
* @see Producer#produce(CreationalContext) |
| 52 |
*/ |
| 53 |
<U extends T> ProducerConfigurator<T> produceWith(Function<CreationalContext<U>, U> callback); |
| 54 |
|
| 55 |
/** |
| 56 |
* Set a callback to destroy the produced instance. |
| 57 |
* |
| 58 |
* @param callback a {@link Consumer} defining the callback to set |
| 59 |
* @return self |
| 60 |
* @see Producer#dispose(Object) |
| 61 |
*/ |
| 62 |
ProducerConfigurator<T> disposeWith(Consumer<T> callback); |
| 63 |
|
| 64 |
|
| 65 |
} |