Ejemplo n.º 1
0
        public SessionManager(Option <ICluster> cluster, SystemName system, ProcessName nodeName, VectorConflictStrategy strategy)
        {
            this.cluster  = cluster;
            this.system   = system;
            this.nodeName = nodeName;

            Sync = new SessionSync(system, nodeName, strategy);

            cluster.Iter(c =>
            {
                notify = c.SubscribeToChannel <SessionAction>(SessionsNotify).Subscribe(act => Sync.Incoming(act));

                var now = DateTime.UtcNow;

                // Look for stranded sessions that haven't been removed properly.  This is done once only
                // on startup because the systems should be shutting down sessions on their own.  This just
                // catches the situation where an app-domain died without shutting down properly.
                c.GetAllHashFieldsInBatch(c.QuerySessionKeys().ToSeq())
                .Map(sessions =>
                     sessions.Filter(vals => (from ts in vals.Find(LastAccessKey).Map(v => new DateTime((long)v))
                                              from to in vals.Find(TimeoutKey).Map(v => (long)v)
                                              where ts < now.AddSeconds(-to * 2)
                                              select true).IfNone(false))
                     .Keys)
                .Map(Seq)
                .Do(strandedSessions => SupplementarySessionManager.removeSessionIdFromSuppMap(c, strandedSessions.Map(ReverseSessionKey)))
                .Do(strandedSessions => c.DeleteMany(strandedSessions))
                .Map(strandedSessions => strandedSessions.Iter(sessionId => c.PublishToChannel(SessionsNotify, SessionAction.Stop(sessionId, system, nodeName))));;



                // Remove session keys when an in-memory session ends
                ended = SessionEnded.Subscribe(sid => Stop(sid));

                touch = Sync.Touched.Subscribe(tup =>
                {
                    try
                    {
                        //check if the session has not been stopped in the meantime or expired
                        if (c.HashFieldAddOrUpdateIfKeyExists(SessionKey(tup.Item1), LastAccessKey, DateTime.UtcNow.Ticks))
                        {
                            c.PublishToChannel(SessionsNotify, SessionAction.Touch(tup.Item1, system, nodeName));
                        }
                    }
                    catch (Exception e)
                    {
                        logErr(e);
                    }
                });
            });
        }
Ejemplo n.º 2
0
        public SessionManager(Option <ICluster> cluster, SystemName system, ProcessName nodeName, VectorConflictStrategy strategy)
        {
            this.cluster  = cluster;
            this.system   = system;
            this.nodeName = nodeName;

            Sync = new SessionSync(system, nodeName, strategy);

            cluster.Iter(c =>
            {
                notify = c.SubscribeToChannel <SessionAction>(SessionsNotify).Subscribe(act => Sync.Incoming(act));

                var now = DateTime.UtcNow;

                // Look for stranded sessions that haven't been removed properly.  This is done once only
                // on startup because the systems should be shutting down sessions on their own.  This just
                // catches the situation where an app-domain died without shutting down properly.
                c.QuerySessionKeys()
                .Map(key =>
                     from ts in c.GetHashField <long>(key, LastAccessKey)
                     from to in c.GetHashField <int>(key, TimeoutKey)
                     where new DateTime(ts) < now.AddSeconds(-to * 2) // Multiply by 2, just to catch genuine non-active sessions
                     select c.Delete(key))
                .Iter(id => { });

                // Remove session keys when an in-memory session ends
                ended = SessionEnded.Subscribe(sid => Stop(sid));

                touch = Sync.Touched.Subscribe(tup =>
                {
                    try
                    {
                        c.HashFieldAddOrUpdate(SessionKey(tup.Item1), LastAccessKey, DateTime.UtcNow.Ticks);
                        c.PublishToChannel(SessionsNotify, SessionAction.Touch(tup.Item1, system, nodeName));
                    }
                    catch (Exception e)
                    {
                        logErr(e);
                    }
                });
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Setup
 /// </summary>
 /// <param name="sessionManager">Process ID of the session manager</param>
 /// <param name="checkFreq">Frequency to check</param>
 public static (SessionSync, Time) Setup(SessionSync sync, Time checkFreq) =>
 (sync, checkFreq);
Ejemplo n.º 4
0
 /// <summary>
 /// Setup
 /// </summary>
 /// <param name="sessionManager">Process ID of the session manager</param>
 /// <param name="checkFreq">Frequency to check</param>
 public static Tuple <SessionSync, Time> Setup(SessionSync sync, Time checkFreq) =>
 Tuple(sync, checkFreq);