r5317: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Wed, 16 Jul 2003 16:40:35 +0000 (16:40 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Wed, 16 Jul 2003 16:40:35 +0000 (16:40 +0000)
classes.lisp
log.lisp [new file with mode: 0644]
sessions.lisp
wol.asd

index 869cc9ee3617f6ff649d25c04d4493b8c5cdd144..70f01b33592981b0c4719ce95d0c52dd01f31404 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: classes.lisp,v 1.1 2003/07/16 16:02:21 kevin Exp $
+;;;; $Id: classes.lisp,v 1.2 2003/07/16 16:40:35 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2001-2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
@@ -26,6 +26,8 @@
 (defclass websession ()
   ((key :initarg :key :accessor websession-key)
    (lastref :initarg :lastref :accessor websession-lastref)
+   (lifetime :initarg :lifetime :initform nil
+            :accessor websession-lifetime)
    (data :initform nil :accessor websession-data)
    (method :initarg :method :accessor websession-method)
    (variables :initform (make-hash-table :test 'equal)
diff --git a/log.lisp b/log.lisp
new file mode 100644 (file)
index 0000000..3793720
--- /dev/null
+++ b/log.lisp
@@ -0,0 +1,18 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: wol -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          log.lisp
+;;;; Purpose:       Logging functions
+;;;; Programmer:    Kevin M. Rosenberg
+;;;; Date Started:  July 2003
+;;;;
+;;;; $Id: log.lisp,v 1.1 2003/07/16 16:40:35 kevin Exp $
+;;;;
+;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
+;;;; *************************************************************************
+
+(in-package #:wol)
+
+(defun add-log-entry (project fmt &rest args)
+  (apply #'cmsg fmt args))
index 227483bab3dabc19313794702c6a80d9db9bb87c..b5bc55944f226c25ccee4cb1bb18073e249c501b 100644 (file)
@@ -7,19 +7,13 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: sessions.lisp,v 1.1 2003/07/16 16:02:21 kevin Exp $
+;;;; $Id: sessions.lisp,v 1.2 2003/07/16 16:40:35 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
 
 (in-package #:wol)
 
-(defun start-reaper ()
-  (process-run-function "wol-reaper"
-    (lambda () (reap-sessions) (kmrcl::process-sleep *reap-interval*))))
-
-(defun reap-sessions ()
-  (cmsg-c :debug "Reaping"))
 
 (defun make-new-session-id ()
   (random-string :length 24 :set :lower-alphanumeric))
@@ -48,6 +42,7 @@
         (sess (make-instance 'websession
                 :key key
                 :lastref (get-universal-time)
+                :lifetime (lifetime (session-master (entity-project ent)))
                 :method method))
         (hash (sessions (session-master (entity-project ent)))))
     (when hash
              (getf (request-plist req) :session-id))
         (setf (websession-from-req req) 
           (ensure-websession it req ent :uri))))
+
+
+
+;;; Reap expired sessions
+
+
+(defun start-reaper ()
+  (process-run-function "wol-reaper"
+    (lambda () (reap-sessions) (kmrcl::process-sleep *reap-interval*))))
+
+(defun reap-sessions ()
+  (cmsg-c :debug "Reaping")
+  (dolist (expired (find-expired-sessions))
+    (flush-expired expired)))
+
+(defun find-expired-sessions ()
+  (loop for s in (all-sessions)
+       when (is-session-expired (car s))
+       collect s))
+
+(defun all-sessions (&aux s)
+  (dolist (p *active-projects* s)
+    (let ((sm (session-master p))
+         (sessions (when sm (sessions sm))))
+      (when sessions
+       (maphash
+        (lambda (k v)
+          (declare (ignore k))
+          (push (cons v p) s))
+        sessions)))))
+
+(defmethod flush-expired (s)
+  (let ((sessions (sessions (session-master (cdr s)))))
+    (remhash (car s) sessions)
+    (add-log-entry (cdr s) "flush expired session: key=~A" (websession-key (car s)))))
+
+(defun is-session-expired (ws)
+  (> (get-universal-time)  (+ (websession-lastref ws)
+                             (websession-lifetime ws))))
diff --git a/wol.asd b/wol.asd
index 15ed38f1f4f33698a64b626284abe7f6b6d90b27..664a8fbaf1ff06239f4d4d0c751d940cab55ccb4 100644 (file)
--- a/wol.asd
+++ b/wol.asd
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: wol.asd,v 1.1 2003/07/16 16:02:21 kevin Exp $
+;;;; $Id: wol.asd,v 1.2 2003/07/16 16:40:35 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
@@ -33,4 +33,5 @@
      (:file "project" :depends-on ("classes"))
      (:file "sessions" :depends-on ("classes"))
      (:file "uri" :depends-on ("classes"))
+     (:file "log" :depends-on ("classes"))
      ))