/** * Schedules a deadline at given {@code triggerDateTime} with given {@code deadlineName}. The payload of this * deadline will be {@code null}, as none is provided. The returned {@code scheduleId} and provided * {@code deadlineName} combination can be used to cancel the scheduled deadline. The scope within which this call * is made will be retrieved by the DeadlineManager itself. * * @param triggerDateTime A {@link java.time.Instant} denoting the moment to trigger the deadline handling * @param deadlineName A {@link String} representing the name of the deadline to schedule * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Instant triggerDateTime, String deadlineName) { return schedule(triggerDateTime, deadlineName, null); }
@CommandHandler public MyAggregate(CreateMyAggregateCommand command, DeadlineManager deadlineManager) { apply(new MyAggregateCreatedEvent(command.id)); String deadlineName = "deadlineName"; String deadlineId = deadlineManager.schedule( Duration.ofMillis(DEADLINE_TIMEOUT), deadlineName, new DeadlinePayload(command.id) ); if (command.cancelBeforeDeadline) { deadlineManager.cancelSchedule(deadlineName, deadlineId); } }
/** * Schedules a deadline after the given {@code triggerDuration} with provided context. The returned * {@code scheduleId} and provided {@code deadlineName} combination can be used to cancel the scheduled deadline. * <p> * The given {@code messageOrPayload} may be any object, as well as a DeadlineMessage. In the latter case, the * instance provided is the donor for the payload and {@link org.axonframework.messaging.MetaData} of the actual * deadline being used. In the former case, the given {@code messageOrPayload} will be wrapped as the payload of a * {@link DeadlineMessage}. * </p> * * @param triggerDuration A {@link Duration} describing the waiting period before handling the deadline * @param deadlineName A {@link String} representing the name of the deadline to schedule * @param messageOrPayload A {@link org.axonframework.messaging.Message} or payload for a message as an * {@link Object} * @param deadlineScope A {@link ScopeDescriptor} describing the scope within which the deadline was scheduled * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Duration triggerDuration, String deadlineName, Object messageOrPayload, ScopeDescriptor deadlineScope) { String scheduleId = generateScheduleId(); schedule(triggerDuration, deadlineName, messageOrPayload, deadlineScope, scheduleId); return scheduleId; }
@Test public void testHandlerInterceptorOnAggregate() { configuration.deadlineManager().registerHandlerInterceptor((uow, chain) -> { uow.transformMessage(deadlineMessage -> GenericDeadlineMessage .asDeadlineMessage(deadlineMessage.getDeadlineName(), new DeadlinePayload("fakeId"))); return chain.proceed(); }); configuration.commandGateway().sendAndWait(new CreateMyAggregateCommand(IDENTIFIER)); assertPublishedEvents(new MyAggregateCreatedEvent(IDENTIFIER), new DeadlineOccurredEvent(new DeadlinePayload("fakeId"))); }
@Test public void testDispatchInterceptorOnAggregate() { configuration.deadlineManager().registerDispatchInterceptor(messages -> (i, m) -> GenericDeadlineMessage.asDeadlineMessage(m.getDeadlineName(), new DeadlinePayload("fakeId"))); configuration.commandGateway().sendAndWait(new CreateMyAggregateCommand(IDENTIFIER)); assertPublishedEvents(new MyAggregateCreatedEvent(IDENTIFIER), new DeadlineOccurredEvent(new DeadlinePayload("fakeId"))); }
@StartSaga @SagaEventHandler(associationProperty = "id") public void on(SagaStartingEvent sagaStartingEvent, DeadlineManager deadlineManager) { String deadlineName = "deadlineName"; String deadlineId = deadlineManager.schedule( Duration.ofMillis(DEADLINE_TIMEOUT), deadlineName, new DeadlinePayload(sagaStartingEvent.id) ); if (sagaStartingEvent.isCancelBeforeDeadline()) { deadlineManager.cancelSchedule(deadlineName, deadlineId); } }
/** * Schedules a deadline at given {@code triggerDateTime} with provided context. The returned {@code scheduleId} and * provided {@code deadlineName} combination can be used to cancel the scheduled deadline. * <p> * The given {@code messageOrPayload} may be any object, as well as a DeadlineMessage. In the latter case, the * instance provided is the donor for the payload and {@link org.axonframework.messaging.MetaData} of the actual * deadline being used. In the former case, the given {@code messageOrPayload} will be wrapped as the payload of a * {@link DeadlineMessage}. * </p> * * @param triggerDateTime A {@link Instant} denoting the moment to trigger the deadline handling * @param deadlineName A {@link String} representing the name of the deadline to schedule * @param messageOrPayload A {@link org.axonframework.messaging.Message} or payload for a message as an * {@link Object} * @param deadlineScope A {@link ScopeDescriptor} describing the scope within which the deadline was scheduled * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Instant triggerDateTime, String deadlineName, Object messageOrPayload, ScopeDescriptor deadlineScope) { String scheduleId = generateScheduleId(); schedule(triggerDateTime, deadlineName, messageOrPayload, deadlineScope, scheduleId); return scheduleId; }
@Test public void testHandlerInterceptorOnSaga() { EventMessage<Object> testEventMessage = asEventMessage(new SagaStartingEvent(IDENTIFIER, DO_NOT_CANCEL_BEFORE_DEADLINE)); configuration.deadlineManager().registerHandlerInterceptor((uow, chain) -> { uow.transformMessage(deadlineMessage -> GenericDeadlineMessage .asDeadlineMessage(deadlineMessage.getDeadlineName(), new DeadlinePayload("fakeId"))); return chain.proceed(); }); configuration.eventStore().publish(testEventMessage); assertPublishedEvents(new SagaStartingEvent(IDENTIFIER, DO_NOT_CANCEL_BEFORE_DEADLINE), new DeadlineOccurredEvent(new DeadlinePayload("fakeId"))); }
@Test public void testDispatchInterceptorOnSaga() { EventMessage<Object> testEventMessage = asEventMessage(new SagaStartingEvent(IDENTIFIER, DO_NOT_CANCEL_BEFORE_DEADLINE)); configuration.deadlineManager().registerDispatchInterceptor(messages -> (i, m) -> GenericDeadlineMessage.asDeadlineMessage(m.getDeadlineName(), new DeadlinePayload("fakeId"))); configuration.eventStore().publish(testEventMessage); assertPublishedEvents(new SagaStartingEvent(IDENTIFIER, DO_NOT_CANCEL_BEFORE_DEADLINE), new DeadlineOccurredEvent(new DeadlinePayload("fakeId"))); }
/** * Schedules a deadline after the given {@code triggerDuration} with given {@code deadlineName}. The payload of this * deadline will be {@code null}, as none is provided. The returned {@code scheduleId} and provided * {@code deadlineName} combination can be used to cancel the scheduled deadline. * The scope within which this call is made will be retrieved by the DeadlineManager itself. * * @param triggerDuration A {@link java.time.Duration} describing the waiting period before handling the deadline * @param deadlineName A {@link String} representing the name of the deadline to schedule * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Duration triggerDuration, String deadlineName) { return schedule(triggerDuration, deadlineName, null); }
/** * Schedules a deadline at given {@code triggerDateTime} with provided context. The returned {@code scheduleId} and * provided {@code deadlineName} combination can be used to cancel the scheduled deadline. * <p> * The given {@code messageOrPayload} may be any object, as well as a DeadlineMessage. In the latter case, the * instance provided is the donor for the payload and {@link org.axonframework.messaging.MetaData} of the actual * deadline being used. In the former case, the given {@code messageOrPayload} will be wrapped as the payload of a * {@link DeadlineMessage}. * </p> * * @param triggerDateTime A {@link Instant} denoting the moment to trigger the deadline handling * @param deadlineName A {@link String} representing the name of the deadline to schedule * @param messageOrPayload A {@link org.axonframework.messaging.Message} or payload for a message as an * {@link Object} * @param deadlineScope A {@link ScopeDescriptor} describing the scope within which the deadline was scheduled * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Instant triggerDateTime, String deadlineName, Object messageOrPayload, ScopeDescriptor deadlineScope) { return schedule(triggerDateTime, deadlineName, messageOrPayload, deadlineScope); }
/** * Schedules a deadline at given {@code triggerDateTime} with given {@code deadlineName}. The returned * {@code scheduleId} and provided {@code deadlineName} combination can be used to cancel the scheduled deadline. * The scope within which this call is made will be retrieved by the DeadlineManager itself. * <p> * The given {@code messageOrPayload} may be any object, as well as a DeadlineMessage. In the latter case, the * instance provided is the donor for the payload and {@link org.axonframework.messaging.MetaData} of the actual * deadline being used. In the former case, the given {@code messageOrPayload} will be wrapped as the payload of a * {@link DeadlineMessage}. * </p> * * @param triggerDateTime A {@link java.time.Instant} denoting the moment to trigger the deadline handling * @param deadlineName A {@link String} representing the name of the deadline to schedule * @param messageOrPayload A {@link org.axonframework.messaging.Message} or payload for a message as an * {@link Object} * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Instant triggerDateTime, String deadlineName, Object messageOrPayload) { return schedule(triggerDateTime, deadlineName, messageOrPayload, Scope.describeCurrentScope()); }
/** * Schedules a deadline after the given {@code triggerDuration}. The returned {@code scheduleId} and provided * {@code deadlineName} combination can be used to cancel the scheduled deadline. * The scope within which this call is made will be retrieved by the DeadlineManager * itself. * <p> * The given {@code messageOrPayload} may be any object, as well as a DeadlineMessage. In the latter case, the * instance provided is the donor for the payload and {@link org.axonframework.messaging.MetaData} of the actual * deadline being used. In the former case, the given {@code messageOrPayload} will be wrapped as the payload of a * {@link DeadlineMessage}. * </p> * * @param triggerDuration A {@link java.time.Duration} describing the waiting period before handling the deadline * @param deadlineName A {@link String} representing the name of the deadline to schedule * @param messageOrPayload A {@link org.axonframework.messaging.Message} or payload for a message as an * {@link Object} * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Duration triggerDuration, String deadlineName, Object messageOrPayload) { return schedule(triggerDuration, deadlineName, messageOrPayload, Scope.describeCurrentScope()); }
@SagaEventHandler(associationProperty = "id") public void on(ScheduleSpecificDeadline message, DeadlineManager deadlineManager) { Object deadlinePayload = message.payload; if (deadlinePayload != null) { deadlineManager.schedule(Duration.ofMillis(DEADLINE_TIMEOUT), "specificDeadlineName", deadlinePayload); } else { deadlineManager.schedule(Duration.ofMillis(DEADLINE_TIMEOUT), "payloadlessDeadline"); } }
@CommandHandler public void on(ScheduleSpecificDeadline message, DeadlineManager deadlineManager) { Object deadlinePayload = message.payload; if (deadlinePayload != null) { deadlineManager.schedule(Duration.ofMillis(DEADLINE_TIMEOUT), "specificDeadlineName", deadlinePayload); } else { deadlineManager.schedule(Duration.ofMillis(DEADLINE_TIMEOUT), "payloadlessDeadline"); } }
@CommandHandler public void handle(TriggerDeadlineInChildEntityCommand command, DeadlineManager deadlineManager) { deadlineManager.schedule( Duration.ofMillis(CHILD_ENTITY_DEADLINE_TIMEOUT), "deadlineName", new EntityDeadlinePayload("entity" + command.id) ); } }
/** * Schedules a deadline after the given {@code triggerDuration} with given {@code deadlineName}. The payload of this * deadline will be {@code null}, as none is provided. The returned {@code scheduleId} and provided * {@code deadlineName} combination can be used to cancel the scheduled deadline. * The scope within which this call is made will be retrieved by the DeadlineManager itself. * * @param triggerDuration A {@link java.time.Duration} describing the waiting period before handling the deadline * @param deadlineName A {@link String} representing the name of the deadline to schedule * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Duration triggerDuration, String deadlineName) { return schedule(triggerDuration, deadlineName, null); }
/** * Schedules a deadline at given {@code triggerDateTime} with given {@code deadlineName}. The payload of this * deadline will be {@code null}, as none is provided. The returned {@code scheduleId} and provided * {@code deadlineName} combination can be used to cancel the scheduled deadline. The scope within which this call * is made will be retrieved by the DeadlineManager itself. * * @param triggerDateTime A {@link java.time.Instant} denoting the moment to trigger the deadline handling * @param deadlineName A {@link String} representing the name of the deadline to schedule * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Instant triggerDateTime, String deadlineName) { return schedule(triggerDateTime, deadlineName, null); }
/** * Schedules a deadline after the given {@code triggerDuration} with given {@code deadlineName}. The payload of this * deadline will be {@code null}, as none is provided. The returned {@code scheduleId} and provided * {@code deadlineName} combination can be used to cancel the scheduled deadline. * The scope within which this call is made will be retrieved by the DeadlineManager itself. * * @param triggerDuration A {@link java.time.Duration} describing the waiting period before handling the deadline * @param deadlineName A {@link String} representing the name of the deadline to schedule * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Duration triggerDuration, String deadlineName) { return schedule(triggerDuration, deadlineName, null); }
/** * Schedules a deadline at given {@code triggerDateTime} with given {@code deadlineName}. The payload of this * deadline will be {@code null}, as none is provided. The returned {@code scheduleId} and provided * {@code deadlineName} combination can be used to cancel the scheduled deadline. The scope within which this call * is made will be retrieved by the DeadlineManager itself. * * @param triggerDateTime A {@link java.time.Instant} denoting the moment to trigger the deadline handling * @param deadlineName A {@link String} representing the name of the deadline to schedule * @return the {@code scheduleId} as a {@link String} to use when cancelling the schedule */ default String schedule(Instant triggerDateTime, String deadlineName) { return schedule(triggerDateTime, deadlineName, null); }