/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <K, V> V waitForAttribute(K key, long timeout) throws InterruptedException { A.notNull(key, "key"); if (timeout == 0) timeout = Long.MAX_VALUE; long now = System.currentTimeMillis(); // Prevent overflow. long end = now + timeout < 0 ? Long.MAX_VALUE : now + timeout; // Don't wait longer than session timeout. if (end > endTime) end = endTime; synchronized (mux) { while (!closed && !attrs.containsKey(key) && now < end) { mux.wait(end - now); now = System.currentTimeMillis(); } if (closed) throw new InterruptedException("Session was closed: " + this); return (V) attrs.get(key); } }
/** * @param key Key. * @param val Value. * @return {@code true} if key/value pair was set. */ private boolean isAttributeSet(Object key, Object val) { if (attrs.containsKey(key)) { Object stored = attrs.get(key); if (val == null && stored == null) return true; if (val != null && stored != null) return val.equals(stored); } return false; }