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

io.deepsense.neptune.clientlibrary.services.channelvaluesender.TimedChannelValueSendingStrategy Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
/**
 * 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