Class: SessionStore

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/quartz_flow/session.rb

Overview

Use SessionStore.instance to access the singleton.

Instance Method Summary collapse

Constructor Details

#initializeSessionStore

Returns a new instance of SessionStore.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/quartz_flow/session.rb', line 25

def initialize
  @sessions = {}  
  @session_mutex = Mutex.new
  @audit_thread = Thread.new do
    while true
      begin
        sleep 10
        audit_sessions  
      rescue
      end
    end
  end
end

Instance Method Details

#audit_sessionsObject



74
75
76
77
78
79
80
81
82
# File 'lib/quartz_flow/session.rb', line 74

def audit_sessions
  @sessions.each do |k,session|
    if session.expired?
      @session_mutex.synchronize do
        @sessions.delete k
      end
    end
  end
end

#end_session(sid) ⇒ Object



51
52
53
54
55
56
# File 'lib/quartz_flow/session.rb', line 51

def end_session(sid)
  return if ! sid
  @session_mutex.synchronize do
    @sessions.delete sid
  end
end

#start_session(login) ⇒ Object

Start a new session for the specified user.



40
41
42
43
44
45
46
47
48
49
# File 'lib/quartz_flow/session.rb', line 40

def start_session()
  sid = nil
  while ! sid || @sessions.has_key?(sid)
    sid = RandString.make_random_string(256)
  end
  @session_mutex.synchronize do 
    @sessions[sid] = Session.new(sid, )
  end
  sid
end

#valid_session?(sid) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/quartz_flow/session.rb', line 58

def valid_session?(sid)
  rc = false
  return rc if ! sid
  @session_mutex.synchronize do
    session = @sessions[sid]
    if session != nil 
      if !session.expired?
        rc = true
      else
        @sessions.delete sid
      end
    end
  end
  rc
end