public void sent(Frame frame) { if (ResumeUtil.isTracked(frame)) { frames.put(currentPosition, frame.copy()); bufferSize += strategy.cost(frame); currentPosition += ResumeUtil.offset(frame); if (frames.size() > maxBufferSize) { Frame f = frames.remove(first(frames)); bufferSize -= strategy.cost(f); } } }
@Test public void supportsZeroBuffer() { cache = new ResumeCache(ResumePositionCounter.frames(), 0); cache.sent(STREAM); cache.sent(STREAM); cache.sent(STREAM); assertEquals(0, cache.getRemotePosition()); assertEquals(42, cache.getCurrentPosition()); assertEquals(42, cache.getEarliestResendPosition()); assertEquals(0, cache.size()); }
@Test public void supportsFrameCountBuffers() { cache = new ResumeCache(ResumePositionCounter.size(), 100);
public void updateRemotePosition(int remotePosition) { if (remotePosition > currentPosition) { throw new IllegalStateException( "Remote ahead of " + lastRemotePosition + " , expected " + remotePosition); } if (remotePosition == lastRemotePosition) { return; } if (remotePosition < lastRemotePosition) { throw new IllegalStateException( "Remote position moved back from " + lastRemotePosition + " to " + remotePosition); } lastRemotePosition = remotePosition; Iterator<Map.Entry<Integer, Frame>> positions = frames.entrySet().iterator(); while (positions.hasNext()) { Map.Entry<Integer, Frame> cachePosition = positions.next(); if (cachePosition.getKey() <= remotePosition) { positions.remove(); bufferSize -= strategy.cost(cachePosition.getValue()); cachePosition.getValue().release(); } // TODO check for a bad position } }
public void updateRemotePosition(int remotePosition) { if (remotePosition > currentPosition) { throw new IllegalStateException( "Remote ahead of " + lastRemotePosition + " , expected " + remotePosition); } if (remotePosition == lastRemotePosition) { return; } if (remotePosition < lastRemotePosition) { throw new IllegalStateException( "Remote position moved back from " + lastRemotePosition + " to " + remotePosition); } lastRemotePosition = remotePosition; Iterator<Map.Entry<Integer, Frame>> positions = frames.entrySet().iterator(); while (positions.hasNext()) { Map.Entry<Integer, Frame> cachePosition = positions.next(); if (cachePosition.getKey() <= remotePosition) { positions.remove(); bufferSize -= strategy.cost(cachePosition.getValue()); cachePosition.getValue().release(); } // TODO check for a bad position } }
public void sent(Frame frame) { if (ResumeUtil.isTracked(frame)) { frames.put(currentPosition, frame.copy()); bufferSize += strategy.cost(frame); currentPosition += ResumeUtil.offset(frame); if (frames.size() > maxBufferSize) { Frame f = frames.remove(first(frames)); bufferSize -= strategy.cost(f); } } }