We study the sojourn time in a queueing system with a single exponential server, serving a Poisson stream of customers in order of arrival. Service is provided at a low or high rate, which can be adapted at exponential inspection times. When the number of customers in the system is above a given threshold, the service rate is upgraded to the high rate, otherwise, it is downgraded to the low rate. The state dependent changes in the service rate make the analysis of the sojourn time a challenging problem, since the sojourn time now also depends on future arrivals. We determine the Laplace transform of the stationary sojourn time and describe a procedure to compute all moments as well. First we analyze the special case of continuous inspection, where the service rate immediately changes once the threshold is crossed. Then we extend the analysis to random inspection times. This extension requires the development of a new methodological tool, that is, matrix generating functions. The power of this tool is that it can also be used to analyze generalizations to phase-type services and inspection times.