
com.xqbase.tuna.util.TimeoutQueue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tuna-core Show documentation
Show all versions of tuna-core Show documentation
a Lightweight and High Performance Java Network Framework - Core Part
The newest version!
package com.xqbase.tuna.util;
import java.util.function.Consumer;
public class TimeoutQueue>
extends LinkedEntry implements Runnable {
private Consumer action;
private int timeout;
public TimeoutQueue(Consumer action, int timeout) {
super(null);
this.action = action;
this.timeout = timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public void offer(T t) {
t.setExpire(System.currentTimeMillis() + timeout);
t.setTimeoutEntry(addNext(t));
}
@Override
public void run() {
long now = System.currentTimeMillis();
iteratePrev(expirable -> expirable.getExpire() < now, action::accept);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy