/** * Creates a service session. * * @param sessionId the session to create * @param memberId the owning node ID * @return the service session */ public PrimaryBackupSession createSession(long sessionId, MemberId memberId) { PrimaryBackupSession session = new PrimaryBackupSession(SessionId.from(sessionId), memberId, service.serializer(), this); if (sessions.putIfAbsent(sessionId, session) == null) { service.register(session); } return session; }
/** * Gets or creates a session. * * @param sessionId the session identifier * @return the session */ private Session getOrCreateSession(SessionId sessionId) { Session session = sessions.get(sessionId); if (session == null) { session = new LocalSession(sessionId, name(), type(), null, service.serializer()); sessions.put(session.sessionId(), session); service.register(session); } return session; }
/** * Registers the given session. * * @param index The index of the registration. * @param timestamp The timestamp of the registration. * @param session The session to register. */ public long openSession(long index, long timestamp, RaftSession session) { log.debug("Opening session {}", session.sessionId()); // Update the state machine index/timestamp. tick(index, timestamp); // Set the session timestamp to the current service timestamp. session.setLastUpdated(currentTimestamp); // Expire sessions that have timed out. expireSessions(currentTimestamp); // Add the session to the sessions list. session.open(); service.register(sessions.addSession(session)); // Commit the index, causing events to be sent to clients if necessary. commit(); // Complete the future. return session.sessionId().id(); }
session.setLastUpdated(sessionTimestamp); session.open(); service.register(sessions.addSession(session));