Annotation Type Priority
-
@Retention(RUNTIME) @Target(TYPE) public @interface Priority
Annotates types with a priority value. The priority is split into two components:
- A zero based numeric value where 0 is the highest priority ring,ring()
Integer.MAX_VALUE
is the lowest priority ring.
- A zero based numeric value wherevalue()
Integer.MAX_VALUE
is the highest priority value, 0 is the lowest priority value.
The
Priority
value of a type is used to choose which type to use when multiples types provide (via theProvides
annotation) the same service.Examples
Redundant
@Priority class Foo {...}
Redundant annotation, gives the type the default
ring()
andvalue()
values. A log message should be produced at theWARNING
level if a default Priority annotation is encountered as it likely indicates a coding error.Default Ring, different priority
@Priority(1) class Foo {...} @Priority(2) class Bar {...}
Type
Bar
will be chosen over typeFoo
because they belong to the same ring andBar
has a higher priority value thanFoo
.Different Ring, default priority
@Priority(ring=0) class Foo {...} @Priority(ring=1) class Bar {...}
Type
Foo
will be chosen over typeBar
becauseFoo
belongs to a higher priority ring thanBar
.Different Ring, different priority
@Priority(ring=3,value=9) class Foo {...} @Priority(ring=1,value=2) class Bar {...}
Type
Bar
will be chosen over typeFoo
becauseBar
belongs to a higher priority ring thanFoo
.- Author:
- cdivilly
-
-
Element Detail
-
ring
int ring
Identifies the 'ring' that this priority is classified into. Ring 0 is the highest priority ring.- Returns:
- A positive integer value representing the 'ring' that this
Priority
belongs to.
- Default:
- 2147483647
-
-