Annotation 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_VALUEis the lowest priority ring.- A zero based numeric value wherevalue()Integer.MAX_VALUEis 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 the Provides annotation) the same
service.
Examples
Redundant
@Priority
class Foo {...}
Redundant annotation, gives the type the default ring() and
value() values. A log message should be produced at the
WARNING 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 type Foo because they
belong to the same ring and Bar has a higher priority value than
Foo.
Different Ring, default priority
@Priority(ring=0)
class Foo {...}
@Priority(ring=1)
class Bar {...}
Type Foo will be chosen over type Bar because
Foo belongs to a higher priority ring than Bar.
Different Ring, different priority
@Priority(ring=3,value=9)
class Foo {...}
@Priority(ring=1,value=2)
class Bar {...}
Type Bar will be chosen over type Foo because
Bar belongs to a higher priority ring than Foo.
- Author:
- cdivilly
-
Optional Element Summary
Optional Elements
-
Element Details
-
ring
int ringIdentifies 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
Prioritybelongs to.
- Default:
- 2147483647
-
value
int valueOrders types within a singlering()classification. PriorityInteger.MAX_VALUEis the highest priority- Returns:
- A positive integer representing the position within this
ring()
- Default:
- 0
-