io.serialized.client.feed.InMemorySequenceNumberTracker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of serialized-client Show documentation
Show all versions of serialized-client Show documentation
Java Client for Serialized APIs
The newest version!
package io.serialized.client.feed;
import org.apache.commons.lang3.Validate;
import java.util.concurrent.atomic.AtomicLong;
/**
* Default, in-memory, implementation of the sequence number tracker.
* Will keep the state of which feed entries have been consumed.
*/
public class InMemorySequenceNumberTracker implements SequenceNumberTracker {
private final AtomicLong sequenceNumber;
public InMemorySequenceNumberTracker() {
this.sequenceNumber = new AtomicLong(0);
}
public InMemorySequenceNumberTracker(long initialValue) {
this.sequenceNumber = new AtomicLong(initialValue);
}
@Override
public long lastConsumedSequenceNumber() {
return sequenceNumber.longValue();
}
@Override
public void updateLastConsumedSequenceNumber(long sequenceNumber) {
Validate.isTrue(sequenceNumber >= 0,
"Illegal sequenceNumber [%d] - last consumed sequence number cannot be negative", sequenceNumber);
Validate.isTrue(sequenceNumber > this.sequenceNumber.get(),
"Illegal sequenceNumber [%d] - last consumed sequence number must be greater than current", sequenceNumber);
this.sequenceNumber.set(sequenceNumber);
}
@Override
public void reset() {
sequenceNumber.set(0);
}
}