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

Custom Rank Indicator Annotations #511

Open
buko opened this issue May 19, 2020 · 0 comments
Open

Custom Rank Indicator Annotations #511

buko opened this issue May 19, 2020 · 0 comments

Comments

@buko
Copy link

buko commented May 19, 2020

A very common requirement is to be able to group services of the same contract into "buckets" that will determine how they are used. To facilitate this hk2 provides the @Rank annotation that allows an explicit integer-based ordering of services. The use of integers allows for arbitrary ordering but it can also be error-prone and isn't really type-safe. It would be nice-to-have the ability to specify custom annotations that could indicate a numerical rank.

This might work like the following:

@RankIndicator
@Rank(30_000)
@Documented
@Retention(RUNTIME)
public @interface HighPriority {}

@RankIndicator
@Rank(20_000)
@Documented
@Retention(RUNTIME)
public @interface NormalPriority {}


@RankIndicator
@Rank(10_000)
@Documented
@Retention(RUNTIME)
public @interface LowPriority {}

This would define certain annotations as being Rank indicators. Services annotated with these Rank indicators would be given the Rank specified on the Rank indicator annotation eg:

@HighPriority
final class ConsoleNotifier implements Notifier { ... }

The service ConsoleLogger would have the rank of 30_000 and would only be used for sending high-priority notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant