All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.webpieces.http2engine.impl.shared.TempTimeoutSet Maven / Gradle / Ivy

There is a newer version: 2.1.109
Show newest version
package com.webpieces.http2engine.impl.shared;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TempTimeoutSet {

	private Set toDiscard = new HashSet();
	private List timeAndStream = new ArrayList<>(); 
	
	public void add(int streamId) {
		//we give it 10 seconds of follow on packets
		long expireTime = 10*1000 + System.currentTimeMillis();
		
		toDiscard.add(streamId);
		//add in reverse order so we can remove in reverse order..
		timeAndStream.add(0, new TimeStream(expireTime, streamId));
	}
	
	public boolean checkDiscard(int streamId) {
		boolean isDiscard = toDiscard.contains(streamId);
		
		long now = System.currentTimeMillis();
		for(int i = timeAndStream.size()-1; i >= 0; i--) {
			TimeStream timeStream = timeAndStream.get(i);
			if(now < timeStream.expireTime) {
				//if this one is not expired, none are
				return isDiscard;
			}
			
			timeAndStream.remove(i);
		}
		
		return isDiscard;
	}
	
	private class TimeStream {

		public long expireTime;
		public int streamId;

		
		public TimeStream(long expireTime, int streamId) {
			this.expireTime = expireTime;
			this.streamId = streamId;
		}

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy