This feature enables developers to respond appropriately to any events that interrupt the running of a service instance during execution of a task.
This feature allows interrupt handling to move from a polling model to an event-driven model. The polling model is still available for backward compatibility.
When a service implements the Service Interrupt handler, the service is informed as soon as the interrupt occurs. Service developers no longer need to have a separate monitoring thread for interrupts to determine when an interrupt has occurred.
Only task-level events are propagated to a running service instance. An interrupt is not delivered to a running service instance if no task is running (onInvoke is not called).
Once the onServiceInterrupt() handler is triggered, it is passed the current service context object. To get more details about the actual interrupt (for example, to retrieve the event and grace period in the interrupt handler), the service can call the getLastInterruptEvent method on the service context object.
Interrupts do not have any error handling associated with them. Any exception thrown while handling this method is ignored by the middleware. The middleware reports the exception to the service instance so that the service instance can take the necessary actions to handle the exception.