latest activity timestamp
This commit is contained in:
parent
22a55ce7e6
commit
39a243cdab
|
@ -52,8 +52,13 @@ public interface IoStream extends WriteStream, Closeable, StreamStatistics {
|
|||
write(packet.getPacket());
|
||||
writeInt(packet.getCrc());
|
||||
flush();
|
||||
onActivity();
|
||||
}
|
||||
|
||||
long latestActivityTime();
|
||||
|
||||
void onActivity();
|
||||
|
||||
default void sendPacket(byte[] plainPacket) throws IOException {
|
||||
if (plainPacket.length == 0)
|
||||
throw new IllegalArgumentException("Empty packets are not valid.");
|
||||
|
|
|
@ -10,6 +10,7 @@ public abstract class AbstractIoStream implements IoStream {
|
|||
|
||||
protected StreamStats streamStats = new StreamStats();
|
||||
private final AtomicInteger bytesOut = new AtomicInteger();
|
||||
private long latestActivity;
|
||||
|
||||
@Override
|
||||
public StreamStats getStreamStats() {
|
||||
|
@ -30,6 +31,15 @@ public abstract class AbstractIoStream implements IoStream {
|
|||
public void flush() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivity() {
|
||||
latestActivity = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long latestActivityTime() {
|
||||
return latestActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return isClosed;
|
||||
|
@ -57,6 +67,7 @@ public abstract class AbstractIoStream implements IoStream {
|
|||
maxPacketGap = (int) Math.max(maxPacketGap, now - previousPacketArrivalTime);
|
||||
}
|
||||
previousPacketArrivalTime = now;
|
||||
AbstractIoStream.this.onActivity();
|
||||
}
|
||||
|
||||
public void onArrived(int length) {
|
||||
|
|
Loading…
Reference in New Issue