use of io.atomix.utils.concurrent.Scheduled in project atomix by atomix.
the class RaftProxyManager method close.
/**
* Closes the session manager.
*
* @return A completable future to be completed once the session manager is closed.
*/
public CompletableFuture<Void> close() {
if (open.compareAndSet(true, false)) {
CompletableFuture<Void> future = new CompletableFuture<>();
threadContext.execute(() -> {
synchronized (this) {
for (Scheduled keepAliveFuture : keepAliveTimers.values()) {
keepAliveFuture.cancel();
}
protocol.unregisterHeartbeatHandler();
}
future.complete(null);
});
return future;
}
return CompletableFuture.completedFuture(null);
}
use of io.atomix.utils.concurrent.Scheduled in project atomix by atomix.
the class RaftProxyManager method scheduleKeepAlive.
/**
* Schedules a keep-alive request.
*/
private synchronized void scheduleKeepAlive(long lastKeepAliveTime, long timeout, long delta) {
Scheduled keepAliveFuture = keepAliveTimers.remove(timeout);
if (keepAliveFuture != null) {
keepAliveFuture.cancel();
}
// Schedule the keep alive for 3/4 the timeout minus the delta from the last keep-alive request.
keepAliveTimers.put(timeout, threadContext.schedule(Duration.ofMillis(Math.max(Math.max((long) (timeout * TIMEOUT_FACTOR) - delta, timeout - MIN_TIMEOUT_DELTA - delta), 0)), () -> {
if (open.get()) {
keepAliveSessions(lastKeepAliveTime, timeout);
}
}));
}
use of io.atomix.utils.concurrent.Scheduled in project atomix by atomix.
the class DistributedLockService method releaseSession.
private void releaseSession(Session session) {
if (lock != null && lock.session == session.sessionId().id()) {
lock = queue.poll();
while (lock != null) {
if (lock.session == session.sessionId().id()) {
lock = queue.poll();
} else {
Scheduled timer = timers.remove(lock.index);
if (timer != null) {
timer.cancel();
}
Session lockSession = getSessions().getSession(lock.session);
if (lockSession == null || lockSession.getState() == Session.State.EXPIRED || lockSession.getState() == Session.State.CLOSED) {
lock = queue.poll();
} else {
lockSession.publish(DistributedLockEvents.LOCK, SERIALIZER::encode, new LockEvent(lock.id, lock.index));
break;
}
}
}
}
}
use of io.atomix.utils.concurrent.Scheduled in project atomix by atomix.
the class DistributedLockService method unlock.
/**
* Applies an unlock commit.
*/
protected void unlock(Commit<Unlock> commit) {
if (lock != null) {
if (lock.session != commit.session().sessionId().id()) {
return;
}
lock = queue.poll();
while (lock != null) {
Scheduled timer = timers.remove(lock.index);
if (timer != null) {
timer.cancel();
}
Session session = getSessions().getSession(lock.session);
if (session == null || session.getState() == Session.State.EXPIRED || session.getState() == Session.State.CLOSED) {
lock = queue.poll();
} else {
session.publish(DistributedLockEvents.LOCK, SERIALIZER::encode, new LockEvent(lock.id, commit.index()));
break;
}
}
}
}
use of io.atomix.utils.concurrent.Scheduled in project atomix by atomix.
the class RaftFuzzTest method reset.
/**
* Shuts down clients and servers.
*/
private void reset() throws Exception {
for (Scheduled shutdownTimer : shutdownTimers.values()) {
shutdownTimer.cancel();
}
shutdownTimers.clear();
for (Scheduled restartTimer : restartTimers.values()) {
restartTimer.cancel();
}
restartTimers.clear();
clients.forEach(c -> {
try {
c.close().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
}
});
servers.forEach(s -> {
try {
if (s.isRunning()) {
s.shutdown().get(10, TimeUnit.SECONDS);
}
} catch (Exception e) {
}
});
Path directory = Paths.get("target/fuzz-logs/");
if (Files.exists(directory)) {
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
}
members = new ArrayList<>();
port = 5000;
clients = new ArrayList<>();
servers = new ArrayList<>();
protocolFactory = new LocalRaftProtocolFactory(protocolSerializer);
}
Aggregations