Skip to content

Commit

Permalink
Issue #38 interaction with deployment descriptor elements for resourc…
Browse files Browse the repository at this point in the history
…e definitions

Signed-off-by: Nathan Rauh <nathan.rauh@us.ibm.com>
  • Loading branch information
njr-11 committed Oct 18, 2021
1 parent 8a40391 commit dc70b62
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,28 @@
* If {@link #ALL_REMAINING} is not present in any of the lists, it is
* implicitly appended to the {@link #cleared()} context types.</p>
*
* You can also define a {@code ContextService} with the
* {@code <context-service>} deployment descriptor element.
* For example,
*
* <pre>
* &lt;context-service&gt;
* &lt;name&gt;java:app/concurrent/MyContext&lt;/name&gt;
* &lt;cleared&gt;Security&lt;/cleared&gt;
* &lt;cleared&gt;Transaction&lt;/cleared&gt;
* &lt;propagated&gt;Application&lt;/propagated&gt;
* &lt;unchanged&gt;Remaining&lt;/unchanged&gt;
* &lt;/context-service&gt;
* </pre>
*
* If a {@code context-service} and {@code ContextServiceDefinition}
* have the same name, their attributes are merged to define a single
* {@code ContextService} definition, with each attribute that is specified
* in the {@code context-service} deployment descriptor entry taking
* precedence over the corresponding attribute of the annotation.
*
* @since 3.0
*/
// TODO could mention relation with <context-service> definition in deployment descriptor once that is added
@Repeatable(ContextServiceDefinition.List.class)
@Retention(RUNTIME)
@Target(TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
* {@link jakarta.annotation.Resource#lookup() lookup} attribute of a
* {@link jakarta.annotation.Resource} annotation,</p>
*
* <pre>{@literal @}ManagedExecutorDefinition(
* <pre>
* {@literal @}ManagedExecutorDefinition(
* name = "java:module/concurrent/MyExecutor",
* context = "java:module/concurrent/MyExecutorContext",
* hungTaskThreshold = 120000,
* maxAsync = 5,
* context ={@literal @}ContextServiceDefinition(
* name = "java:module/concurrent/MyExecutorContext",
* propagated = { SECURITY, APPLICATION }))
* public class MyServlet extends HttpServlet {
* maxAsync = 5)
* {@literal @}ContextServiceDefinition(
* name = "java:module/concurrent/MyExecutorContext",
* propagated = { SECURITY, APPLICATION })
* public class MyServlet extends HttpServlet {
* {@literal @}Resource(lookup = "java:module/concurrent/MyExecutor",
* name = "java:module/concurrent/env/MyExecutorRef")
* ManagedExecutorService myExecutor;
Expand All @@ -57,9 +59,27 @@
* &lt;/resource-env-ref&gt;
* </pre>
*
* You can also define a {@code ManagedExecutorService} with the
* {@code <managed-executor>} deployment descriptor element.
* For example,
*
* <pre>
* &lt;managed-executor&gt;
* &lt;name&gt;java:module/concurrent/MyExecutor&lt;/name&gt;
* &lt;context-service-ref&gt;java:module/concurrent/MyExecutorContext&lt;/context-service-ref&gt;
* &lt;hung-task-threshold&gt;120000&lt;/hung-task-threshold&gt;
* &lt;max-async&gt;5&lt;/max-async&gt;
* &lt;/managed-executor&gt;
* </pre>
*
* If a {@code managed-executor} and {@code ManagedExecutorDefinition}
* have the same name, their attributes are merged to define a single
* {@code ManagedExecutorService} definition, with each attribute that is specified
* in the {@code managed-executor} deployment descriptor entry taking
* precedence over the corresponding attribute of the annotation.
*
* @since 3.0
*/
//TODO could mention relation with <managed-executor> definition in deployment descriptor once that is added
@Repeatable(ManagedExecutorDefinition.List.class)
@Retention(RUNTIME)
@Target(TYPE)
Expand All @@ -80,17 +100,22 @@
String name();

/**
* <p>Determines how context is applied to tasks and actions that
* run on this executor.</p>
*
* <p>The default value indicates to use the default instance of
* {@link ContextService} by specifying a
* {@link ContextServiceDefinition} with the name
* <code>java:comp/DefaultContextService</code>.</p>
* The name of a {@link ContextService} instance which
* determines how context is applied to tasks and actions that
* run on this executor.
* <p>
* The name can be the name of a {@link ContextServiceDefinition} or
* the name of a {@code context-service} deployment descriptor element
* or the JNDI name of the Jakarta EE default {@code ContextService}
* instance, {@code java:comp/DefaultContextService}.
* <p>
* The default value, {@code java:comp/DefaultContextService}, is the
* JNDI name of the Jakarta EE default {@code ContextService}.
*
* @return instructions for capturing and propagating or clearing context.
* @return name of the {@code ContextService} for
* capturing and propagating or clearing context.
*/
ContextServiceDefinition context() default @ContextServiceDefinition(name = "java:comp/DefaultContextService");
String context() default "java:comp/DefaultContextService";

/**
* <p>The amount of time in milliseconds that a task or action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
* {@link jakarta.annotation.Resource#lookup() lookup} attribute of a
* {@link jakarta.annotation.Resource} annotation,</p>
*
* <pre>{@literal @}ManagedScheduledExecutorDefinition(
* <pre>
* {@literal @}ManagedScheduledExecutorDefinition(
* name = "java:comp/concurrent/MyScheduledExecutor",
* context = "java:comp/concurrent/MyScheduledExecutorContext",
* hungTaskThreshold = 30000,
* maxAsync = 3,
* context ={@literal @}ContextServiceDefinition(
* name = "java:comp/concurrent/MyScheduledExecutorContext",
* propagated = APPLICATION))
* public class MyServlet extends HttpServlet {
* maxAsync = 3)
* {@literal @}ContextServiceDefinition(
* name = "java:comp/concurrent/MyScheduledExecutorContext",
* propagated = APPLICATION)
* public class MyServlet extends HttpServlet {
* {@literal @}Resource(lookup = "java:comp/concurrent/MyScheduledExecutor",
* name = "java:comp/concurrent/env/MyScheduledExecutorRef")
* ManagedScheduledExecutorService myScheduledExecutor;
Expand All @@ -57,9 +59,27 @@
* &lt;/resource-env-ref&gt;
* </pre>
*
* You can also define a {@code ManagedScheduledExecutorService} with the
* {@code <managed-scheduled-executor>} deployment descriptor element.
* For example,
*
* <pre>
* &lt;managed-scheduled-executor&gt;
* &lt;name&gt;java:module/concurrent/MyExecutor&lt;/name&gt;
* &lt;context-service-ref&gt;java:module/concurrent/MyExecutorContext&lt;/context-service-ref&gt;
* &lt;hung-task-threshold&gt;120000&lt;/hung-task-threshold&gt;
* &lt;max-async&gt;5&lt;/max-async&gt;
* &lt;/managed-scheduled-executor&gt;
* </pre>
*
* If a {@code managed-scheduled-executor} and {@code ManagedScheduledExecutorDefinition}
* have the same name, their attributes are merged to define a single
* {@code ManagedScheduledExecutorService} definition, with each attribute that is specified
* in the {@code managed-scheduled-executor} deployment descriptor entry taking
* precedence over the corresponding attribute of the annotation.
*
* @since 3.0
*/
//TODO could mention relation with <managed-scheduled-executor> definition in deployment descriptor once that is added
@Repeatable(ManagedScheduledExecutorDefinition.List.class)
@Retention(RUNTIME)
@Target(TYPE)
Expand All @@ -80,17 +100,22 @@
String name();

/**
* <p>Determines how context is applied to tasks and actions that
* run on this executor.</p>
*
* <p>The default value indicates to use the default instance of
* {@link ContextService} by specifying a
* {@link ContextServiceDefinition} with the name
* <code>java:comp/DefaultContextService</code>.</p>
* The name of a {@link ContextService} instance which
* determines how context is applied to tasks and actions that
* run on this executor.
* <p>
* The name can be the name of a {@link ContextServiceDefinition} or
* the name of a {@code context-service} deployment descriptor element
* or the JNDI name of the Jakarta EE default {@code ContextService}
* instance, {@code java:comp/DefaultContextService}.
* <p>
* The default value, {@code java:comp/DefaultContextService}, is the
* JNDI name of the Jakarta EE default {@code ContextService}.
*
* @return instructions for capturing and propagating or clearing context.
* @return name of the {@code ContextService} for
* capturing and propagating or clearing context.
*/
ContextServiceDefinition context() default @ContextServiceDefinition(name = "java:comp/DefaultContextService");
String context() default "java:comp/DefaultContextService";

/**
* <p>The amount of time in milliseconds that a task or action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
* {@link jakarta.annotation.Resource#lookup() lookup} attribute of a
* {@link jakarta.annotation.Resource} annotation,</p>
*
* <pre>{@literal @}ManagedThreadFactoryDefinition(
* <pre>
* {@literal @}ManagedThreadFactoryDefinition(
* name = "java:global/concurrent/MyThreadFactory",
* priority = "4",
* context ={@literal @}ContextServiceDefinition(
* name = "java:global/concurrent/MyThreadFactoryContext",
* propagated = APPLICATION))
* public class MyServlet extends HttpServlet {
* context = "java:global/concurrent/MyThreadFactoryContext",
* priority = 4)
* {@literal @}ContextServiceDefinition(
* name = "java:global/concurrent/MyThreadFactoryContext",
* propagated = APPLICATION)
* public class MyServlet extends HttpServlet {
* {@literal @}Resource(lookup = "java:global/concurrent/MyThreadFactory",
* name = "java:module/concurrent/env/MyThreadFactoryRef")
* ManagedThreadFactory myThreadFactory;
Expand All @@ -56,9 +58,26 @@
* &lt;/resource-env-ref&gt;
* </pre>
*
* You can also define a {@code ManagedThreadFactory} with the
* {@code <managed-thread-factory>} deployment descriptor element.
* For example,
*
* <pre>
* &lt;managed-thread-factory&gt;
* &lt;name&gt;java:global/concurrent/MyThreadFactory&lt;/name&gt;
* &lt;context-service-ref&gt;java:global/concurrent/MyThreadFactoryContext&lt;/context-service-ref&gt;
* &lt;priority&gt;4&lt;/priority&gt;
* &lt;/managed-thread-factory&gt;
* </pre>
*
* If a {@code managed-thread-factory} and {@code ManagedThreadFactoryDefinition}
* have the same name, their attributes are merged to define a single
* {@code ManagedThreadFactory} definition, with each attribute that is specified
* in the {@code managed-thread-factory} deployment descriptor entry taking
* precedence over the corresponding attribute of the annotation.
*
* @since 3.0
*/
//TODO could mention relation with <managed-thread-factory> definition in deployment descriptor once that is added
@Repeatable(ManagedThreadFactoryDefinition.List.class)
@Retention(RUNTIME)
@Target(TYPE)
Expand Down Expand Up @@ -89,7 +108,7 @@
*
* @return instructions for capturing and propagating or clearing context.
*/
ContextServiceDefinition context() default @ContextServiceDefinition(name = "java:comp/DefaultContextService");
String context() default "java:comp/DefaultContextService";

/**
* <p>Priority for threads created by this thread factory.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@ public interface ThreadContextProvider {
* <p>
* For example:
* <pre>
* {@code @ManagedExecutorDefinition(}
* name = "java:module/concurrent/MyCustomContextExecutor",
* maxAsync = 3,
* context = {@code @ContextServiceDefinition(}
* name = "java:module/concurrent/MyCustomContext",
* propagated = MyCustomContextProvider.CONTEXT_NAME,
* cleared = { ContextServiceDefinition.SECURITY, ContextServiceDefinition.TRANSACTION },
* unchanged = ContextServiceDefinition.ALL_REMAINING))
* {@code @ContextServiceDefinition(}
* name = "java:module/concurrent/MyCustomContext",
* propagated = MyCustomContextProvider.CONTEXT_NAME,
* cleared = { ContextServiceDefinition.SECURITY, ContextServiceDefinition.TRANSACTION },
* unchanged = ContextServiceDefinition.ALL_REMAINING)
* </pre>
* <p>
* It is an error for multiple thread context providers of an identical type to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

@ManagedExecutorDefinition( // from ManagedExecutorDefinition JavaDoc
name = "java:module/concurrent/MyExecutor",
context = "java:module/concurrent/MyExecutorContext",
hungTaskThreshold = 120000,
maxAsync = 5,
context = @ContextServiceDefinition(
name = "java:module/concurrent/MyExecutorContext",
propagated = { SECURITY, APPLICATION }))
maxAsync = 5)
@ContextServiceDefinition( // from ManagedExecutorDefinition JavaDoc, used by above
name = "java:module/concurrent/MyExecutorContext",
propagated = { SECURITY, APPLICATION })
@ManagedExecutorDefinition(
name = "java:app/concurrent/ManagedExecutorDefinitionDefaults")
public class ManagedExecutorDefinitionTest {
Expand All @@ -53,11 +54,7 @@ public void testManagedExecutorDefinitionDefaultValues() throws Exception {
assertNotNull(def);
assertEquals(-1, def.hungTaskThreshold());
assertEquals(-1, def.maxAsync());
ContextServiceDefinition csd = def.context();
assertEquals("java:comp/DefaultContextService", csd.name());
assertArrayEquals(new String[] { TRANSACTION }, csd.cleared());
assertArrayEquals(new String[] {}, csd.unchanged());
assertArrayEquals(new String[] { ALL_REMAINING }, csd.propagated());
assertEquals("java:comp/DefaultContextService", def.context());
}

/**
Expand All @@ -72,10 +69,6 @@ public void testManagedExecutorDefinitionJavaDocExample() throws Exception {
assertNotNull(def);
assertEquals(120000, def.hungTaskThreshold());
assertEquals(5, def.maxAsync());
ContextServiceDefinition csd = def.context();
assertEquals("java:module/concurrent/MyExecutorContext", csd.name());
assertArrayEquals(new String[] { SECURITY, APPLICATION }, csd.propagated());
assertArrayEquals(new String[] { TRANSACTION }, csd.cleared());
assertArrayEquals(new String[] {}, csd.unchanged());
assertEquals("java:module/concurrent/MyExecutorContext", def.context());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

@ManagedScheduledExecutorDefinition( // from ManagedScheduledExecutorDefinition JavaDoc
name = "java:comp/concurrent/MyScheduledExecutor",
context = "java:comp/concurrent/MyScheduledExecutorContext",
hungTaskThreshold = 30000,
maxAsync = 3,
context = @ContextServiceDefinition(
name = "java:comp/concurrent/MyScheduledExecutorContext",
propagated = APPLICATION))
maxAsync = 3)
@ContextServiceDefinition( // from ManagedScheduledExecutorDefinition JavaDoc, used by above
name = "java:comp/concurrent/MyScheduledExecutorContext",
propagated = APPLICATION)
@ManagedScheduledExecutorDefinition(
name = "java:global/concurrent/ManagedScheduledExecutorDefinitionDefaults")
public class ManagedScheduledExecutorDefinitionTest {
Expand All @@ -54,11 +55,7 @@ public void testManagedScheduledExecutorDefinitionDefaultValues() throws Excepti
assertNotNull(def);
assertEquals(-1, def.hungTaskThreshold());
assertEquals(-1, def.maxAsync());
ContextServiceDefinition csd = def.context();
assertEquals("java:comp/DefaultContextService", csd.name());
assertArrayEquals(new String[] { TRANSACTION }, csd.cleared());
assertArrayEquals(new String[] {}, csd.unchanged());
assertArrayEquals(new String[] { ALL_REMAINING }, csd.propagated());
assertEquals("java:comp/DefaultContextService", def.context());
}

/**
Expand All @@ -74,10 +71,6 @@ public void testManagedScheduledExecutorDefinitionJavaDocExample() throws Except
assertNotNull(def);
assertEquals(30000, def.hungTaskThreshold());
assertEquals(3, def.maxAsync());
ContextServiceDefinition csd = def.context();
assertEquals("java:comp/concurrent/MyScheduledExecutorContext", csd.name());
assertArrayEquals(new String[] { APPLICATION }, csd.propagated());
assertArrayEquals(new String[] { TRANSACTION }, csd.cleared());
assertArrayEquals(new String[] {}, csd.unchanged());
assertEquals("java:comp/concurrent/MyScheduledExecutorContext", def.context());
}
}

0 comments on commit dc70b62

Please sign in to comment.