@Override
    public ApplicationLock lockApplication(OrchestratorContext context, ApplicationInstanceReference reference) throws UncheckedTimeoutException {
        ReentrantLock lock = locks.computeIfAbsent(reference, (ignored) -> new ReentrantLock());

        try {
            if (!lock.tryLock(context.getTimeLeft().toMillis(), TimeUnit.MILLISECONDS)) {
                throw new UncheckedTimeoutException("Timed out trying to acquire the lock on " + reference);
            }
        } catch (InterruptedException e) {
            throw new UncheckedTimeoutException("Interrupted", e);
        }

        return new ApplicationLock() {
            @Override
            public ApplicationInstanceReference getApplicationInstanceReference() {
                return reference;
            }

            @Override
            public HostInfos getHostInfos() {
                return getHostInfosByApplicationResolver().apply(reference);
            }

            @Override
            public void setHostState(HostName hostName, HostStatus status) {
                if (status == HostStatus.NO_REMARKS) {
                    applicationHostInfo(reference).remove(hostName);
                } else {
                    applicationHostInfo(reference).put(hostName, HostInfo.createSuspended(status, Instant.EPOCH));
                }
            }

            @Override
            public ApplicationInstanceStatus getApplicationInstanceStatus() {
                return ApplicationInstanceStatus.NO_REMARKS;
            }

            @Override
            public void setApplicationInstanceStatus(ApplicationInstanceStatus applicationInstanceStatus) {
                throw new UnsupportedOperationException();
            }

            @Override
            public void close() {
                lock.unlock();
            }
        };
    }
In-memory implementation of StatusService.

@author hakon
orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/InMemoryStatusService.java