removeAndTerminate

fun removeAndTerminate(request: ProcessModel.Entity.Request, waitStats: Boolean = false, afterTermination: (entity: ProcessModel.Entity) -> Unit? = null)(source)

Removes the request from the queue and tells the associated entity to terminate its process. The process that was suspended because the entity's request was placed in the queue is immediately terminated.

Units a preemption's reservation had collected for the request go back to the resource before the process is terminated, so the termination's hooks see them there (a capacity decrease waiting for them has taken them). After the termination they are offered to whoever else is waiting for them, as when a waiting process is terminated. So are the free units of what it requested: when the queue has a request selection rule, removing the request the rule had chosen can let it choose another, which is served at once rather than at the next release. A request the library has served has left the queue, so this cannot reach it; terminating its entity releases its allocation instead.

A request is in the queue while its entity's process still runs, from when it is placed until the process suspends: the queue's listeners, and a mailbox observer or allocation listener run in that step (as while a wait for the first of several things registers), can see it. A running process cannot be terminated, so this throws, before anything is removed; check that the entity's currentProcess is not running first.

Parameters

request

the request to remove from the queue

waitStats

if true the waiting time statistics are collected on the usage of the queue. The default is false.

afterTermination

a function to invoke after the process is successfully terminated