Enum RestResourceProducer.Scope
- All Implemented Interfaces:
Serializable, Comparable<RestResourceProducer.Scope>
- Enclosing interface:
RestResourceProducer
RestResourceProducer.
The scope determines when AutoCloseable resources are automatically closed after injection.
This allows producers to balance performance (class-scoped reuse) with isolation (method-scoped cleanup).
- Since:
- 1.0
- Author:
- James R. Perkins
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic RestResourceProducer.ScopeReturns the enum constant of this type with the specified name.static RestResourceProducer.Scope[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
DEFAULT
Use the natural scope of the injection point.- Static fields: Cleaned up when the test class completes
- Instance fields: Cleaned up when the test class completes
- Method parameters: Cleaned up when the test method completes
This is the default scope and is appropriate for most custom producers where method-level isolation is desired for parameters (e.g., temporary files, test-specific resources).
- See Also:
-
CLASS
Always use class scope for all injection points.Resources are cleaned up when the test class completes, regardless of whether injected into a field or method parameter. This scope is appropriate for expensive-to-create resources that are safe to share across test methods.
Example use cases:
- REST clients (thread-safe, expensive to create)
- Database connection pools (designed for reuse)
- Immutable configuration objects
Built-in producers (
Client,URI,Configuration) useCLASSscope for performance.- See Also:
-
NEW
Create a new instance for every injection point.The producer's
RestResourceProducer.produce(ExtensionContext, Class, Annotation...)method is invoked every time the resource is injected, completely bypassing any caching. This means:- Multiple field injections create separate instances
- Each method parameter injection creates a fresh instance
- No instance is ever shared or reused
This scope is appropriate for mutable or stateful resources that must be isolated between injection points to prevent cross-contamination or unexpected behavior.
Example use cases:
- Mutable API clients that maintain request state (e.g.,
WebTarget) - Builder instances that accumulate state across method calls
- Resources with per-injection configuration requirements
Performance consideration: Since
produce()is called for every injection, this scope should only be used when instance isolation is required. UseCLASSfor expensive, thread-safe resources.Built-in producers that use
NEWscope:WebTarget- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-