/// <summary> /// Gets an active session id using the supplementary session id /// </summary> /// <param name="sessionId"></param> /// <returns></returns> internal Option <SessionId> GetSessionId(SupplementarySessionId sessionId) => (from ses in sessions from vector in ses.Value.Data.Find(SupplementarySessionId.Key) from v in vector.Vector where v is SupplementarySessionId && ((SupplementarySessionId)v).Value == sessionId.Value select ses.Key).HeadOrNone();
/// <summary> /// update session id or supplementary sessionId /// </summary> /// <param name="sessionId"></param> /// <param name="suppSessionId"></param> /// <returns></returns> internal LanguageExt.Unit Update(SessionId sessionId, SupplementarySessionId suppSessionId) { //remove old supp-sessions: Remove(sessionId); lock (sync) { suppToSession = suppToSession.AddOrUpdate(suppSessionId, sessionId); sessionToSupp = sessionToSupp.AddOrUpdate(sessionId, suppSessionId); } return(unit); }
internal static Option <SessionId> getSessionIdFromSuppMap(ICluster cluster, SupplementarySessionId sessionId) => cluster.GetHashField <string>(suppToSessionKey, sessionId.Value).Map(v => new SessionId(v));
internal static LanguageExt.Unit setSuppSessionInSuppMap(ICluster cluster, SessionId sessionId, SupplementarySessionId suppSessionId) { //delete any old supp-sessions to keep in sync removeSessionIdFromSuppMap(cluster, sessionId); cluster.HashFieldAddOrUpdate(sessionToSuppKey, sessionId.Value, suppSessionId.Value); cluster.HashFieldAddOrUpdate(suppToSessionKey, suppSessionId.Value, sessionId.Value); return(unit); }
/// <summary> /// Attempts to get a SessionId by supplementary session ID. /// </summary> /// <param name="supplementarySessionId"></param> /// <returns></returns> public Option <SessionId> GetSessionId(SupplementarySessionId supplementarySessionId) => Sync.GetSessionId(supplementarySessionId) || getSessionIdFromCluster(supplementarySessionId);
Option <SessionId> getSessionIdFromCluster(SupplementarySessionId suppSessionId) => from c in cluster from s in SupplementarySessionManager.getSessionIdFromSuppMap(c, suppSessionId) from to in c.GetHashField <int>(SessionKey(s), TimeoutKey) let _ = Sync.UpdateSupplementarySessionId(s, suppSessionId) select Sync.Start(s, to);
/// <summary> /// Attempts to get a SessionId by supplementary session ID. Only checked locally. /// </summary> /// <param name="supplementarySessionId"></param> /// <returns></returns> public Option <SessionId> GetSessionId(SupplementarySessionId supplementarySessionId) => Sync.GetSessionId(supplementarySessionId);
/// <summary> /// Gets session id from supplementary sessionId /// </summary> /// <param name="sessionId"></param> /// <returns></returns> internal Option <SessionId> GetSessionId(SupplementarySessionId sessionId) => suppToSession.Find(sessionId);