RunBefore class final
A reflective annotation that declares that the annotated interceptor, filter, or handler should execute before one or more specified targets within the JetLeaf request processing pipeline.
Overview
The RunBefore annotation is part of JetLeaf’s interceptor ordering system, allowing developers to define explicit execution precedence between different interceptors or filters.
When JetLeaf builds the interceptor chain for a given request, it uses these annotations to sort components deterministically—ensuring that certain interceptors (e.g. logging, metrics, security) execute in a specific order.
Usage Example
@RunBefore([AuthInterceptor, 'metrics_interceptor'])
class LoggingInterceptor implements HandlerInterceptor {
@override
Future<bool> preHandle(req, res, handler) async {
print('Incoming request: ${req.getUri()}');
return true;
}
}
In this example:
- The
LoggingInterceptorwill always run before bothAuthInterceptorand the interceptor registered under the pod name'metrics_interceptor'.
Supported Target Types
- Type references (e.g.
AuthInterceptor)
→ JetLeaf resolves these based on class types. - String pod names (e.g.
'security_interceptor')
→ Used when the interceptor is registered dynamically or under a dependency injection pod.
Framework Integration
During interceptor registration, JetLeaf reads all RunBefore and RunAfter annotations and computes an execution graph.
It then uses topological sorting to produce a stable and deterministic interceptor order.
Example of Combined Usage
@RunBefore([AuthInterceptor])
class MetricsInterceptor {}
@RunAfter([MetricsInterceptor])
class AuthInterceptor {}
The framework will always ensure:
MetricsInterceptor → AuthInterceptor
Design Notes
- Used only at class-level, enforced via
@Target({TargetKind.classType}). - Extends
ReflectableAnnotationfor runtime resolution through JetLeaf’s reflection system. - The ordering is advisory, meaning if a referenced interceptor isn’t registered, the system skips it gracefully.
Related Annotations
- RunAfter — declares execution ordering after another target.
Summary
The RunBefore annotation provides fine-grained control over interceptor execution order, improving modularity and predictability in complex request pipelines.
- Annotations
-
- @Target.new({TargetKind.classType})
Constructors
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
- hashCode → int
-
Returns a hash code consistent with equality definition.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
targets
→ List<
Object> -
The list of targets (either Types or String pod names)
that this interceptor should execute before.
final
Methods
-
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
Returns a string representation of this annotation.
inherited
Operators
-
operator ==(
Object other) → bool -
Checks if this annotation is equal to another object.
inherited