io.deepsense.neptune.clientlibrary.services.channelvaluesender.TimedChannelValueSendingStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptune-client-library Show documentation
Show all versions of neptune-client-library Show documentation
Enables integration with Neptune in your Java code
/**
* Copyright (c) 2016, CodiLime Inc.
*/
package io.deepsense.neptune.clientlibrary.services.channelvaluesender;
public class TimedChannelValueSendingStrategy implements ChannelValueSendingStrategy {
private final int maxPackageCountInBuffer;
private final long minIntervalBetweenSends;
private long previousSendTimestamp;
public TimedChannelValueSendingStrategy(int maxPackageCountInBuffer, long minIntervalBetweenSends) {
this.maxPackageCountInBuffer = maxPackageCountInBuffer;
this.minIntervalBetweenSends = minIntervalBetweenSends;
}
@Override
public boolean shouldValuesBeSent(int packageCountInBuffer) {
return packageCountInBuffer > 0 && timeSinceLastSend() > minIntervalBetweenSends
|| packageCountInBuffer == maxPackageCountInBuffer;
}
@Override
public void onSend() {
previousSendTimestamp = System.currentTimeMillis();
}
private long timeSinceLastSend() {
return System.currentTimeMillis() - previousSendTimestamp;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy