Search in sources :

Example 1 with SessionMetadata

use of io.atomix.primitive.session.SessionMetadata in project atomix by atomix.

the class RaftServiceManager method applyMetadata.

/**
 * Applies a metadata entry to the state machine.
 */
private MetadataResult applyMetadata(Indexed<MetadataEntry> entry) {
    // If the session ID is non-zero, read the metadata for the associated state machine.
    if (entry.entry().session() > 0) {
        RaftSession session = raft.getSessions().getSession(entry.entry().session());
        // If the session is null, return an UnknownSessionException.
        if (session == null) {
            logger.warn("Unknown session: " + entry.entry().session());
            throw new RaftException.UnknownSession("Unknown session: " + entry.entry().session());
        }
        Set<SessionMetadata> sessions = new HashSet<>();
        for (RaftSession s : raft.getSessions().getSessions()) {
            if (s.serviceName().equals(session.serviceName())) {
                sessions.add(new SessionMetadata(s.sessionId().id(), s.serviceName(), s.serviceType().id()));
            }
        }
        return new MetadataResult(sessions);
    } else {
        Set<SessionMetadata> sessions = new HashSet<>();
        for (RaftSession session : raft.getSessions().getSessions()) {
            sessions.add(new SessionMetadata(session.sessionId().id(), session.serviceName(), session.serviceType().id()));
        }
        return new MetadataResult(sessions);
    }
}
Also used : RaftSession(io.atomix.protocols.raft.session.RaftSession) SessionMetadata(io.atomix.primitive.session.SessionMetadata) HashSet(java.util.HashSet)

Aggregations

SessionMetadata (io.atomix.primitive.session.SessionMetadata)1 RaftSession (io.atomix.protocols.raft.session.RaftSession)1 HashSet (java.util.HashSet)1