Skip to content

Latest commit

 

History

History
95 lines (75 loc) · 3.18 KB

use_of_the_priority_annotation_in_ordering_interceptors.adoc

File metadata and controls

95 lines (75 loc) · 3.18 KB

Use of the Priority Annotation in Ordering Interceptors

The Priority annotation can be used to enable and order interceptors associated with components that use interceptor bindings. The required value element of the Priority annotation determines the ordering. Interceptors with smaller priority values are called first. If more than one interceptor has the same priority, the relative order of those interceptors is undefined.

@Monitored
@Interceptor
@Priority(100)
public class MonitoringInterceptor {
    @AroundInvoke
    public Object monitorInvocation(InvocationContext ctx)
        throws Exception {
        ...
    }
}

The Priority annotation is ignored when computing the invocation order of interceptors bound to a component using the Interceptors annotation.

The following priority values are defined for interceptor ordering when used with the Priority annotation. Interceptors with lower priority values are invoked earlier in the interceptor chain.

  • Interceptor.Priority.PLATFORM_BEFORE = 0

  • Interceptor.Priority.LIBRARY_BEFORE = 1000

  • Interceptor.Priority.APPLICATION = 2000

  • Interceptor.Priority.LIBRARY_AFTER = 3000

  • Interceptor.Priority.PLATFORM_AFTER = 4000

These values define the following interceptor ranges to order interceptors for a specific interposed method or event in the interceptor chain:

Interceptors defined by the Jakarta EE Platform specifications that are to be executed at the beginning of the interceptor chain should have priority values in the range PLATFORM_BEFORE up until LIBRARY_BEFORE.

Interceptors defined by extension libraries that are intended to be executed earlier in the interceptor chain, but after interceptors in the range up until LIBRARY_BEFORE should have priority values in the range LIBRARY_BEFORE up until APPLICATION.

Interceptors defined by applications should be in the range APPLICATION up until LIBRARY_AFTER.

Interceptors defined by extension libraries that are intended to be executed later in the interceptor chain should have priority values in the range LIBRARY_AFTER up until PLATFORM_AFTER.

Interceptors defined by the Jakarta EE Platform specifications that are to be executed at the end of the interceptor chain should have priority values at PLATFORM_AFTER or higher.

An interceptor that must be invoked before or after another defined interceptor can choose any appropriate value.

Negative priority values are reserved for future use by this specification and should not be used.

The following example defines an extension library interceptor that is to be executed before any application interceptor, but after any early platform interceptor:

@Priority(Interceptor.Priority.LIBRARY_BEFORE+10)
@Validated
@Interceptor
public class ValidationInterceptor { ... }