class UserSessionLookup implements ResponseContextCodes {

  public UserSession expected(String userName) throws GameBootRuntimeException {
    Optional<Context> ctx = helper.startTimer(CACHED_SESSION_TIMER);

    try {
      String noSession = "No session for " + userName;

      check(NO_USERNAME, isEmpty(userName), "No username specified");

      check(NO_USER_SESSION, !activeSessions.hasSession(userName), noSession);

      List<UserSession> sessions = assist.activeSessions();

      Optional<UserSession> o = find(sessions, us -> us.getUser().getUserName().equals(userName));

      // may not yet be in the cached list
      return o.isPresent() ? o.get() : sessionCheck(repository.findOpenSession(userName));
    } finally {
      helper.stopTimer(ctx);
    }
  }

}