use of com.hazelcast.cp.internal.util.PartitionSpecificRunnableAdaptor in project hazelcast by hazelcast.
the class RaftSessionService method getInactiveSessions.
private Map<CPGroupId, Collection<Long>> getInactiveSessions() {
Map<CPGroupId, Collection<Long>> response = new ConcurrentHashMap<>();
Semaphore semaphore = new Semaphore(0);
OperationServiceImpl operationService = nodeEngine.getOperationService();
Collection<RaftSessionRegistry> registries = new ArrayList<>(this.registries.values());
for (RaftSessionRegistry registry : registries) {
CPGroupId groupId = registry.groupId();
operationService.execute(new PartitionSpecificRunnableAdaptor(() -> {
Set<Long> activeSessionIds = new HashSet<>();
for (SessionAwareService service : nodeEngine.getServices(SessionAwareService.class)) {
activeSessionIds.addAll(service.getAttachedSessions(groupId));
}
Set<Long> inactiveSessionIds = new HashSet<>();
for (CPSession session : registry.getSessions()) {
if (!activeSessionIds.contains(session.id()) && session.creationTime() + getSessionTTLMillis() < Clock.currentTimeMillis()) {
inactiveSessionIds.add(session.id());
}
}
if (inactiveSessionIds.size() > 0) {
response.put(groupId, inactiveSessionIds);
}
semaphore.release();
}, nodeEngine.getPartitionService().getPartitionId(groupId)));
}
try {
semaphore.tryAcquire(registries.size(), COLLECT_INACTIVE_SESSIONS_TASK_TIMEOUT_SECONDS, SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return response;
}
Aggregations