Order

annotation class Order(val value: Int = ORDER_DEFAULT, val before: Array<KClass<*>> = [], val after: Array<KClass<*>> = [])

Specifies the execution order for annotated elements.

This annotation controls the sequence in which handlers, processors, or components are executed when multiple candidates exist for the same operation. Lower values indicate higher priority (executed first).

Ordering is essential for:

  • Ensuring correct sequence of event processing

  • Controlling initialization order of components

  • Managing dependencies between processors

  • Implementing complex business workflows

Example usage:

@EventProcessor
class OrderProcessor {

@OnEvent
@Order(1) // Execute first
fun validateOrder(event: OrderCreated) {
// Validation logic
}

@OnEvent
@Order(2) // Execute after validation
fun processPayment(event: OrderCreated) {
// Payment processing
}

@OnEvent
@Order(after = [PaymentProcessor::class]) // Execute after PaymentProcessor
fun sendConfirmation(event: OrderCreated) {
// Send confirmation
}
}

Parameters

value

The priority value. Lower numbers execute first. Common values: ORDER_FIRST (-2^31), ORDER_DEFAULT (0), ORDER_LAST (2^31-1)

before

Array of classes that this element should execute before. Useful for relative ordering without hard-coded values.

after

Array of classes that this element should execute after. Useful for relative ordering without hard-coded values.

See also

for the highest priority

for normal priority

for the lowest priority

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val after: Array<KClass<*>>
Link copied to clipboard
Link copied to clipboard
val value: Int