Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concurrency resources via @Inject and with qualifiers #348

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

/**
* <p>Defines a {@link ContextService}
* to be registered in JNDI by the container
* to be injected into
* {@link ContextService} injection points
* with the specified {@link #qualifiers()}
* and registered in JNDI by the container
* under the JNDI name that is specified in the
* {@link #name()} attribute.</p>
*
Expand All @@ -39,9 +42,19 @@
* unchanged = TRANSACTION,
* cleared = ALL_REMAINING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed the qualifiers = MyQualifier.class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed the qualifiers = MyQualifier.class

Thanks! I have fixed it in commit b377e7a

* public class MyServlet extends HttpServlet {
* {@literal @}Resource(lookup = "java:app/concurrent/MyContext",
* {@literal @}Inject
* {@literal @}MyQualifier
* ConetxtService appContextSvc1;
*
* {@literal @}Resource(lookup = "java:app/concurrent/MyContext",
* name = "java:app/concurrent/env/MyContextRef")
* ContextService appContextSvc;
* ContextService appContextSvc2;
* ...
*
* {@literal @}Qualifier
* {@literal @}Retention(RetentionPolicy.RUNTIME)
* {@literal @}Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
* public {@literal @}interface MyQualifier {}
* </pre>
*
* <p>Resource environment references in a deployment descriptor
Expand Down Expand Up @@ -112,6 +125,28 @@
*/
String name();

/**
* <p>List of {@link Qualifier qualifier annotations}.</p>
*
* <p>A {@link ContextService} injection point
* with these qualifier annotations injects a bean that is
* produced by this {@code ContextServiceDefinition}.</p>
*
* <p>The default value is an empty list, indicating that this
* {@code ContextServiceDefinition} does not automatically produce
* bean instances for any injection points.</p>
*
* <p>Applications can define their own {@link Producer Producers}
* for {@link ContextService} injection points as long as the
* qualifier annotations on the producer do not conflict with the
* non-empty {@link #qualifiers()} list of a
* {@code ContextServiceDefinition}.</p>
*
* @return list of qualifiers.
* @since 3.1
*/
Class<?>[] qualifiers() default {};

/**
* <p>Types of context to clear whenever a thread runs the
* contextual task or action. The thread's previous context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import jakarta.enterprise.inject.spi.Producer;
import jakarta.inject.Qualifier;

/**
* <p>Defines a {@link ManagedExecutorService}
* to be registered in JNDI by the container
* to be injected into
* {@link ManagedExecutorService} injection points
* with the specified {@link #qualifiers()}
* and registered in JNDI by the container
* under the JNDI name that is specified in the
* {@link #name()} attribute.</p>
*
Expand All @@ -36,16 +42,27 @@
* <pre>
* {@literal @}ManagedExecutorDefinition(
* name = "java:module/concurrent/MyExecutor",
* qualifiers = MyQualifier.class,
* context = "java:module/concurrent/MyExecutorContext",
* hungTaskThreshold = 120000,
* maxAsync = 5)
* {@literal @}ContextServiceDefinition(
* name = "java:module/concurrent/MyExecutorContext",
* propagated = { SECURITY, APPLICATION })
* public class MyServlet extends HttpServlet {
* {@literal @}Resource(lookup = "java:module/concurrent/MyExecutor",
* public class MyServlet extends HttpServlet {
* {@literal @}Inject
* {@literal @}MyQualifier
* ManagedExecutorService myExecutor1;
*
* {@literal @}Resource(lookup = "java:module/concurrent/MyExecutor",
* name = "java:module/concurrent/env/MyExecutorRef")
* ManagedExecutorService myExecutor;
* ManagedExecutorService myExecutor2;
* ...
*
* {@literal @}Qualifier
* {@literal @}Retention(RetentionPolicy.RUNTIME)
* {@literal @}Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
* public {@literal @}interface MyQualifier {}
* </pre>
*
* <p>Resource environment references in a deployment descriptor
Expand Down Expand Up @@ -99,6 +116,28 @@
*/
String name();

/**
* <p>List of {@link Qualifier qualifier annotations}.</p>
*
* <p>A {@link ManagedExecutorService} injection point
* with these qualifier annotations injects a bean that is
* produced by this {@code ManagedExecutorDefinition}.</p>
*
* <p>The default value is an empty list, indicating that this
* {@code ManagedExecutorDefinition} does not automatically produce
* bean instances for any injection points.</p>
*
* <p>Applications can define their own {@link Producer Producers}
* for {@link ManagedExecutorService} injection points as long as the
* qualifier annotations on the producer do not conflict with the
* non-empty {@link #qualifiers()} list of a
* {@code ManagedExecutorDefinition}.</p>
*
* @return list of qualifiers.
* @since 3.1
*/
Class<?>[] qualifiers() default {};

/**
* The name of a {@link ContextService} instance which
* determines how context is applied to tasks and actions that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

/**
* <p>Defines a {@link ManagedScheduledExecutorService}
* to be registered in JNDI by the container
* to be injected into
* {@link ManagedScheduledExecutorService} injection points
* with the specified {@link #qualifiers()}
* and registered in JNDI by the container
* under the JNDI name that is specified in the
* {@link #name()} attribute.</p>
*
Expand All @@ -42,10 +45,20 @@
* {@literal @}ContextServiceDefinition(
* name = "java:comp/concurrent/MyScheduledExecutorContext",
* propagated = APPLICATION)
* public class MyServlet extends HttpServlet {
* {@literal @}Resource(lookup = "java:comp/concurrent/MyScheduledExecutor",
* public class MyServlet extends HttpServlet {
* {@literal @}Inject
* {@literal @}MyQualifier
* ManagedScheduledExecutorService myScheduledExecutor1;
*
* {@literal @}Resource(lookup = "java:comp/concurrent/MyScheduledExecutor",
* name = "java:comp/concurrent/env/MyScheduledExecutorRef")
* ManagedScheduledExecutorService myScheduledExecutor;
* ManagedScheduledExecutorService myScheduledExecutor2;
* ...
*
* {@literal @}Qualifier
* {@literal @}Retention(RetentionPolicy.RUNTIME)
* {@literal @}Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
* public {@literal @}interface MyQualifier {}
* </pre>
*
* <p>Resource environment references in a deployment descriptor
Expand Down Expand Up @@ -99,6 +112,28 @@
*/
String name();

/**
* <p>List of {@link Qualifier qualifier annotations}.</p>
*
* <p>A {@link ManagedScheduledExecutorService} injection point
* with these qualifier annotations injects a bean that is
* produced by this {@code ManagedScheduledExecutorDefinition}.</p>
*
* <p>The default value is an empty list, indicating that this
* {@code ManagedScheduledExecutorDefinition} does not automatically produce
* bean instances for any injection points.</p>
*
* <p>Applications can define their own {@link Producer Producers}
* for {@link ManagedScheduledExecutorService} injection points as long as the
* qualifier annotations on the producer do not conflict with the
* non-empty {@link #qualifiers()} list of a
* {@code ManagedScheduledExecutorDefinition}.</p>
*
* @return list of qualifiers.
* @since 3.1
*/
Class<?>[] qualifiers() default {};

/**
* The name of a {@link ContextService} instance which
* determines how context is applied to tasks and actions that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import java.lang.annotation.Target;

/**
* <p>Defines a {@link ManagedThreadFactory}
* to be registered in JNDI by the container
* <p>Defines {@link ManagedThreadFactory} instances
* to be injected into
* {@link ManagedThreadFactory} injection points
* with the specified {@link #qualifiers()}
* and registered in JNDI by the container
* under the JNDI name that is specified in the
* {@link #name()} attribute.</p>
*
Expand All @@ -41,10 +44,20 @@
* {@literal @}ContextServiceDefinition(
* name = "java:global/concurrent/MyThreadFactoryContext",
* propagated = APPLICATION)
* public class MyServlet extends HttpServlet {
* {@literal @}Resource(lookup = "java:global/concurrent/MyThreadFactory",
* public class MyServlet extends HttpServlet {
* {@literal @}Inject
* {@literal @}MyQualifier
* ManagedThreadFactory myThreadFactory1;
*
* {@literal @}Resource(lookup = "java:global/concurrent/MyThreadFactory",
* name = "java:module/concurrent/env/MyThreadFactoryRef")
* ManagedThreadFactory myThreadFactory;
* ManagedThreadFactory myThreadFactory2;
* ...
*
* {@literal @}Qualifier
* {@literal @}Retention(RetentionPolicy.RUNTIME)
* {@literal @}Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
* public {@literal @}interface MyQualifier {}
* </pre>
*
* <p>Resource environment references in a deployment descriptor
Expand Down Expand Up @@ -97,6 +110,28 @@
*/
String name();

/**
* <p>List of {@link Qualifier qualifier annotations}.</p>
*
* <p>A {@link ManagedThreadFactory} injection point
* with these qualifier annotations injects a bean that is
* produced by this {@code ManagedThreadFactoryDefinition}.</p>
*
* <p>The default value is an empty list, indicating that this
* {@code ManagedThreadFactoryDefinition} does not automatically produce
* bean instances for any injection points.</p>
*
* <p>Applications can define their own {@link Producer Producers}
* for {@link ManagedThreadFactory} injection points as long as the
* qualifier annotations on the producer do not conflict with the
* non-empty {@link #qualifiers()} list of a
* {@code ManagedThreadFactoryDefinition}.</p>
*
* @return list of qualifiers.
* @since 3.1
*/
Class<?>[] qualifiers() default {};

/**
* Determines how context is applied to threads from this
* thread factory.
Expand Down
Loading