forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC: add the @Active qualifier for List<> injection points
This is similar to the `@All` qualifier, both in spirit and implementation, it just filters out inactive beans. This commit also adds the `ArcContainer.listActive()` methods, again similar to the `listAll()` methods, just with additional filtering.
- Loading branch information
Showing
17 changed files
with
668 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/Active.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.quarkus.arc; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
|
||
import jakarta.enterprise.inject.Any; | ||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.enterprise.util.AnnotationLiteral; | ||
import jakarta.inject.Qualifier; | ||
|
||
/** | ||
* The container provides a synthetic bean for an injection point with the required type {@link List} and the required qualifier | ||
* {@link Active}. The injected instance is an immutable list of the contextual references of the disambiguated beans, | ||
* without beans that are currently {@linkplain InjectableBean#checkActive() inactive}. | ||
* | ||
* <pre> | ||
* @ApplicationScoped | ||
* public class Processor { | ||
* | ||
* @Inject | ||
* @Active | ||
* List<Service> services; | ||
* } | ||
* </pre> | ||
* | ||
* If the injection point declares no other qualifier then {@link Any} is used, i.e. the behavior is equivalent to | ||
* {@code @Inject @Any Instance<Service> services} and subsequent filtering on the active status. The semantics is the same | ||
* as for the {@link Instance#iterator()}, i.e. the container attempts to resolve ambiguities. In general, if multiple beans | ||
* are eligible then the container eliminates all beans that are: | ||
* <ul> | ||
* <li>not alternatives, except for producer methods and fields of beans that are alternatives,</li> | ||
* <li>default beans.</li> | ||
* </ul> | ||
* | ||
* You can also inject a list of bean instances wrapped in {@link InstanceHandle}. This can be useful if you need to inspect the | ||
* bean metadata. | ||
* | ||
* <pre> | ||
* @ApplicationScoped | ||
* public class Processor { | ||
* | ||
* @Inject | ||
* @Active | ||
* List<InstanceHandle<Service>> services; | ||
* | ||
* void doSomething() { | ||
* for (InstanceHandle<Service> handle : services) { | ||
* if (handle.getBean().getScope().equals(Dependent.class)) { | ||
* handle.get().process(); | ||
* break; | ||
* } | ||
* } | ||
* } | ||
* } | ||
* </pre> | ||
* | ||
* The list is sorted by {@link InjectableBean#getPriority()}. Higher priority goes first. | ||
* | ||
* @see jakarta.annotation.Priority | ||
*/ | ||
@Qualifier | ||
@Retention(RUNTIME) | ||
@Target({ TYPE, FIELD, METHOD, PARAMETER }) | ||
public @interface Active { | ||
/** | ||
* Supports inline instantiation of this qualifier. | ||
*/ | ||
final class Literal extends AnnotationLiteral<Active> implements Active { | ||
public static final Literal INSTANCE = new Literal(); | ||
|
||
private static final long serialVersionUID = 1L; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.