@Override public Optional<Reservation> lookup(final NodeUrn nodeUrn, final DateTime timestamp) { log.trace("ReservationCacheImpl.lookup({}, {})", nodeUrn, timestamp); checkRunning(); synchronized (reservationsByNodeUrn) { final List<CacheItem<Reservation>> entry = reservationsByNodeUrn.get(nodeUrn); if (entry == null) { log.trace("ReservationManagerImpl.lookup() CACHE MISS"); return Optional.absent(); } for (CacheItem<Reservation> item : entry) { final Interval effectiveInterval; final Reservation reservation = item.get(); final DateTime reservationStart = reservation.getInterval().getStart(); final DateTime reservationCancellation = reservation.getCancelled(); if (reservationCancellation != null) { if (reservationCancellation.isBefore(reservationStart)) { continue; } else { effectiveInterval = new Interval(reservationStart, reservationCancellation); } } else { effectiveInterval = reservation.getInterval(); } if (effectiveInterval.contains(timestamp)) { if (!item.isOutdated()) { item.touch(); log.trace("ReservationManagerImpl.lookup() CACHE HIT"); return Optional.of(reservation); } } } } return Optional.absent(); }