Server: no delay op sending

This commit is contained in:
2025-03-31 16:05:00 +02:00
parent edebb6d8f0
commit 5c50d572d0
3 changed files with 32 additions and 1 deletions

View File

@@ -65,7 +65,7 @@ public class OpPusher {
if (tree.hasPendingOpsForHost(entry.peer())) {
doAgain.set(true);
invalidationQueueService.pushInvalidationToOne(entry.peer(), pd.key());
invalidationQueueService.pushInvalidationToOneNoDelay(entry.peer(), pd.key());
}
return ops;
}

View File

@@ -44,6 +44,24 @@ public class HashSetDelayedBlockingQueue<T> {
}
}
// Adds the object to the queue, if it exists re-adds it
// With no delay
// Returns the old object, or null
public T addNoDelay(T el) {
synchronized (this) {
if (_closed) throw new IllegalStateException("Adding to a queue that is closed!");
SetElement<T> old = _set.putFirst(el, new SetElement<>(el, 0));
this.notify();
if (old != null)
return old.el();
else
return null;
}
}
// Adds the object to the queue, if it exists re-adds it with a new delay
// Returns the old object, or null
public T readd(T el) {

View File

@@ -24,6 +24,19 @@ public class HashSetDelayedBlockingQueueTest {
Assertions.assertTrue((gotTime - curTime) >= 1000);
}
@Test
void addNoDelay() throws InterruptedException {
var queue = new HashSetDelayedBlockingQueue<>(1000);
var curTime = System.currentTimeMillis();
queue.addNoDelay("hello!");
var thing = queue.get();
var gotTime = System.currentTimeMillis();
Assertions.assertEquals("hello!", thing);
Assertions.assertTrue((gotTime - curTime) < 500);
}
@Test
void GetImmediate() throws InterruptedException {
var queue = new HashSetDelayedBlockingQueue<>(0);