KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sessionEnhydra > PagedSessionHome


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: PagedSessionHome.java,v 1.2 2005/03/24 10:51:20 slobodan Exp $
23  */

24
25 package com.lutris.appserver.server.sessionEnhydra;
26
27 import java.util.Enumeration JavaDoc;
28 import java.util.Hashtable JavaDoc;
29 import java.util.Vector JavaDoc;
30
31 import com.lutris.appserver.server.Enhydra;
32 import com.lutris.appserver.server.session.SessionException;
33 import com.lutris.logging.Logger;
34 import com.lutris.util.Config;
35 import com.lutris.util.ConfigException;
36
37 /**
38  * The StandardSessionManager uses PagedSessionHome to manage
39  * a collection of sessions that can be paged to disk.<p>
40  *
41  * PagedSessionHome will page sessions to disk
42  * as soon as a pre-configured threshold of sessions has been
43  * reached. Only sessions in the 'passive' state will be
44  * paged to disk. If all sessions are in the 'active' state
45  * and the threshold has been reached, then a request to create
46  * a new session will block until one of the 'active' sessions
47  * goes into the 'passive' state. At this point the session
48  * that just became 'passive' is paged to disk and a new
49  * session is created.<p>
50  *
51  * Sessions are paged to disk by serializing
52  * the all data (excluding the session manager) that is
53  * associated with a session. This requires that
54  * the session data and user associated with a session
55  * are serializable.<p>
56  *
57  * The following parameters can be used to configure
58  * the PagedSessionHome. They should be grouped together in a section,
59  * normally <code>SessionManager.SessionHome</code>, which is specified to
60  * the constructor.<p>
61  *
62  * <ul>
63  *
64  * <li><code>PageThreshold: {int}</code><p>
65  * Specifies the maximum number of session that may reside in memory
66  * simultaneously. If set to zero the the paged session home acts
67  * as a write through cache. If set to -1, then the page threshold
68  * is assumed to be infinite and paging will never take place.
69  * If not set, defaults to -1.<p>
70  *
71  * <li><code>PageTimeThreshold: {long}</code><p>
72  * Specifies the amount of time a session may remain in memory
73  * before it is paged out to disk.
74  * If this parameter is not set, or, it is set to -1, then the session
75  * will not be paged out unless the <i>PageThreshold</i> is reached.<p>
76  *
77  * <li><code>PageWait: {int}</code><p>
78  * Specifies the maximum time (in milliseconds) that a thread will
79  * wait for a session to be created or retrieved. If the
80  * page threshold has been reached, then a thread has to wait for
81  * an existing session to be paged before a new session can be
82  * created or a pre-existing session (that has been paged to
83  * disk) can be activated. If not set, defaults to 1 minute.
84  * If this time is exceeded then an exception is thrown - this
85  * prevents a possible deadlock situation.<p>
86  *
87  * <li><code>PageDir: {String}</code><p>
88  * The directory where sessions will be paged. This setting is
89  * required.<p>
90  *
91  * <li><code>MaxSessions: {int}</code><p>
92  * Specifies the maximum number of in use concurrent sessions. If this value
93  * is exceeded then CreateSession() will throw a CreateSessionException.
94  * -1 indicates unlimited session. If MaxSessions is not set
95  * in the application's configuration then MaxSessions defaults to
96  * unlimited sessions.<p>
97  *
98  * </ul>
99  *
100  * @see StandardSession
101  * @see StandardSessionManager
102  * @version $Revision: 1.2 $
103  * @author Kyle Clark
104  */

105 public abstract class PagedSessionHome implements StandardSessionHome {
106
107     /**
108      * The active cache contains sessions that are
109      * actively in use (associated with) by a request.
110      */

111     private Hashtable JavaDoc activeCache = new Hashtable JavaDoc();
112
113     /**
114      * The active thread cache holds all the association
115      * between active sessions and the threads that have
116      * checked them out.
117      */

118     private Hashtable JavaDoc activeThreadCache = new Hashtable JavaDoc();
119
120     /**
121      * The passive cache contains sessions that
122      * aren't currently associated with a request.
123      */

124     private Hashtable JavaDoc passiveCache = new Hashtable JavaDoc();
125
126     /**
127      * Config options for paged session home.
128      */

129     private Config config;
130
131     /**
132      * Maximum number of allowed sessions.
133      */

134     private long maxSessions = -1;
135
136     /**
137      * The threshold where paging beings.
138      */

139     private long pageThreshold = -1;
140
141     /**
142      * The amount of time a session may remain in memory
143      * unused before it is paged out. In seconds.
144      */

145     private long pageTimeThreshold = -1;
146
147     /**
148      * The pageTimeThreshold timer.
149      */

150     private PagedSessionThresholdTimer thresholdTimer;
151
152     /**
153      * If a thread has to wait for a session to be paged
154      * before it can retrieve (get) or create a session then
155      * pageWait specifies that maximum amount of time
156      * that the thread will wait before an exception is
157      * thrown.
158      */

159     private long pageWait = 60000; // milliseconds
160

161     /**
162      * Configuration keys.
163      */

164     private final String JavaDoc MAX_SESSIONS_KEY = "MaxSessions";
165     private final String JavaDoc PAGE_THRESHOLD_KEY = "PageThreshold";
166     private final String JavaDoc PAGE_TIME_THRESHOLD_KEY = "PageTimeThreshold";
167     private final String JavaDoc PAGE_WAIT_KEY = "PageWait";
168     private final long UNDEFINED_MAX_SESSIONS = -1;
169
170     /**
171      * The class loader to use when reading in paged data.
172      */

173     protected ClassLoader JavaDoc loader;
174
175     /**
176      * The session manager associated with the session home.
177      */

178     protected StandardSessionManager sessionMgr;
179
180     /**
181      * @param sessionMgr
182      * The session manager associated with this session home.
183      * @param config
184      * Object parsed from configuration file. This should be
185      * for the section containing the standard session home configuration.
186      * @param loader
187      * The class load to use when load objects from persistent store.
188      * @exception ConfigException
189      * signifies a problem in the configuration file.
190      * @exception SessionException
191      * if the initialization fails.
192      */

193     public PagedSessionHome(StandardSessionManager sessionMgr,
194                             Config config, ClassLoader JavaDoc loader)
195         throws SessionException, ConfigException {
196         this.config = config;
197         this.loader = loader;
198         this.sessionMgr = sessionMgr;
199         if (config.containsKey(MAX_SESSIONS_KEY)) {
200             maxSessions = config.getLong(MAX_SESSIONS_KEY);
201         }
202         if (maxSessions <= 0) {
203             maxSessions = UNDEFINED_MAX_SESSIONS;
204         }
205         debug(MAX_SESSIONS_KEY + " = " + maxSessions);
206         pageThreshold = config.getLong(PAGE_THRESHOLD_KEY);
207         debug(PAGE_THRESHOLD_KEY + " = " + pageThreshold);
208         if (config.containsKey(PAGE_WAIT_KEY)) {
209             pageWait = config.getLong(PAGE_WAIT_KEY);
210             if (pageWait <= 0) {
211                 throw new ConfigException("PagedSessionHome: "
212                                           + "PageWait cannot be <= 0.");
213             }
214         }
215         if (config.containsKey(PAGE_TIME_THRESHOLD_KEY)) {
216             pageTimeThreshold = config.getLong(PAGE_TIME_THRESHOLD_KEY) * 1000;
217             if (!isWriteThroughCache() && (pageTimeThreshold > 0)) {
218                 thresholdTimer = new PagedSessionThresholdTimer(this, sessionMgr.app);
219                 thresholdTimer.start();
220             }
221         }
222         debug(PAGE_TIME_THRESHOLD_KEY + " = " + pageTimeThreshold);
223     }
224
225     /**
226      * Creates a new session instance in the cache. The
227      * session is associated with the session key and the
228      * current thread.
229      *
230      * @param sessionKey the key to associate with the session.
231      * @return the newly created session.
232      * @exception DuplicateKeyException
233      * if the session cannot
234      * be created because the key is already in use.
235      * @exception CreateSessionException
236      * if the session could not be created.
237      * @exception SessionException
238      * any other internal error.
239      */

240     public synchronized StandardSession createSession(String JavaDoc sessionKey)
241         throws CreateSessionException, DuplicateKeyException, SessionException {
242         if (containsKey(sessionKey)) {
243             throw new DuplicateKeyException("Session key "
244                                             + sessionKey + " is already in use.");
245         }
246         if ((maxSessions != UNDEFINED_MAX_SESSIONS) &&
247             (maxSessions <= size())) {
248             cleanupNewSession();
249             if (maxSessions <= size()) {
250                 throw new CreateSessionException("Maximum session limit of "
251                                                  + maxSessions
252                                                  + " sessions has been reached.");
253             }
254         }
255         ensureNewSession();
256         PagedSession session = newSession(sessionMgr, sessionKey);
257         SessionThread activeKey = new SessionThread(Thread.currentThread(),
258                                                     sessionKey);
259         session.incrementRefCount(); // keeps track of # of threads that reference session
260
activeThreadCache.put(activeKey, session);
261         activeCache.put(sessionKey, session);
262 // v. strahinja, 01 okt 2002 debug(3, "createSession: " + activeKey);
263
debug("createSession: " + activeKey);
264         return (StandardSession)session;
265     }
266
267     /**
268      * Creates a new session object. This method is intended to be
269      * overriden by classes that extend PagedSessionHome.
270      *
271      * @return a new session.
272      * @exception SessionException if an error occurs.
273      */

274     protected abstract PagedSession newSession(StandardSessionManager mgr,
275                                                String JavaDoc sessionKey)
276         throws SessionException;
277
278
279     /**
280      * Deletes a paged session. If the session doesn't exist then this
281      * is a noop.
282      *
283      * @param sessionKey the key identifying the session
284      * that should be deleted.
285      */

286     protected abstract void deleteSession(String JavaDoc sessionKey)
287         throws SessionException;
288
289     /**
290      * Returns the session associated with the session key.
291      * The session must already be associated with the current thread
292      * otherwize null is returned.
293      *
294      * @param sessionKey the session key
295      * @return the session.
296      * @see #getSession(Thread, String)
297      * @exception SessionException
298      * if the session could not be retrieved.
299      */

300     public synchronized StandardSession getSession(String JavaDoc sessionKey)
301         throws SessionException {
302 // v. strahinja, 01 okt 2002 debug(3, "get session: key = " + sessionKey);
303
debug("get session: key = " + sessionKey);
304         SessionThread activeKey = new SessionThread(Thread.currentThread(),
305                                                     sessionKey);
306         PagedSession s = (PagedSession)activeThreadCache.get(activeKey);
307         return s;
308     }
309
310     /**
311      * Returns the session associated with the session key.
312      * The session is associated with the specified thread.
313      * The session is put into the 'active' state.
314      *
315      * @param thread the thread to associate with the session.
316      * @param sessionKey the session key for the session
317      * that will be made 'active' and returned. If the
318      * session doesn't exist or it hasn't been
319      * associated with this thread then null is returned.
320      * @return the session.
321      * @exception SessionException
322      * if the session could not be retrieved.
323      */

324     public synchronized StandardSession getSession(Thread JavaDoc thread, String JavaDoc sessionKey)
325         throws SessionException {
326 // v. strahinja, 01 okt 2002 debug(3, "getSession: " + sessionKey);
327
debug("getSession: " + sessionKey);
328         SessionThread activeKey = new SessionThread(thread, sessionKey);
329         PagedSession s = (PagedSession)activeThreadCache.get(activeKey);
330         if (s == null) {
331             s = (PagedSession)activeCache.get(sessionKey);
332             if (s == null) {
333                 s = activateSession(sessionKey);
334             }
335             if (s != null) {
336                 activeThreadCache.put(activeKey, s);
337                 // keeps track of # of threads that reference session
338
s.incrementRefCount();
339             }
340         }
341         return s;
342     }
343
344     /**
345      * Removes the session associated with the session key.
346      *
347      * @param sessionKey the session key for the session
348      * that will be made 'active' and returned.
349      * @return the session.
350      * @exception SessionException
351      * if the session couldn't be removed.
352      */

353     public synchronized void removeSession(String JavaDoc sessionKey) throws SessionException {
354 // v. strahinja, 01 okt 2002 debug(3, "removeSession: " + sessionKey);
355
debug("removeSession: " + sessionKey);
356         Enumeration JavaDoc e = activeThreadCache.keys();
357         while (e.hasMoreElements()) {
358             SessionThread key = (SessionThread)e.nextElement();
359             if (key.sessionKey.equals(sessionKey)) {
360                 activeThreadCache.remove(key);
361             }
362         }
363         activeCache.remove(sessionKey);
364         passiveCache.remove(sessionKey);
365         deleteSession(sessionKey);
366         notify();
367     }
368
369     /**
370      * Puts an 'active' session into the 'passive' state.
371      *
372      * @param thread the thread associated with the session.
373      * @param sessionKey the session key for the session
374      * that will be made persistent.
375      * @exception SessionException
376      * if the session coulnd not be put into the passive state.
377      */

378     public synchronized void passivateSession(Thread JavaDoc thread, String JavaDoc sessionKey)
379         throws SessionException {
380         SessionThread activeKey = new SessionThread(thread, sessionKey);
381         try {
382 // v. strahinja, 01 okt 2002 debug(3, "passivateSession: " + activeKey);
383
debug("passivateSession: " + activeKey);
384             if (activeThreadCache.containsKey(activeKey)) {
385                 PagedSession s = (PagedSession)activeThreadCache.remove(activeKey);
386                 s.decrementRefCount();
387                 // If there aren't any other threads associated with the session
388
if (s.getRefCount() == 0) {
389                     if (isWriteThroughCache()) {
390                         pageOut(s);
391                     } else if ((pageThreshold < 0)
392                         || ((activeCache.size() + passiveCache.size()) < pageThreshold)) {
393 // v. strahinja, 01 okt 2002 debug(3, "active -> passive: " + sessionKey);
394
debug("active -> passive: " + sessionKey);
395                         passiveCache.put(sessionKey, s);
396                     } else {
397                         pageOut(s);
398                     }
399                     activeCache.remove(sessionKey);
400                 }
401             } else {
402 // v. strahinja, 01 okt 2002 debug(3, "passivateSession called but active session "
403
debug("passivateSession called but active session "
404                       + " doesn't exist: " + sessionKey);
405             }
406         } catch (Exception JavaDoc e) {
407             throw new SessionException(e);
408         } finally {
409             notify();
410         }
411     }
412
413     /**
414      * Pages a session to disk.
415      *
416      * @param session the session to page.
417      * @exception SessionException if the paged session could not be
418      * paged out.
419      */

420     protected abstract void pageOut(PagedSession s) throws SessionException;
421
422     /**
423      * Reads a paged session from disk.
424      *
425      * @param sessionKey the key identifying the session that should
426      * be paged in.
427      * @return the paged session that was read in. May be null if
428      * the session referenced by sessionKey doesn't exist.
429      * @exception SessionException if the paged session could not be
430      * read in.
431      */

432     protected abstract PagedSession pageIn(String JavaDoc sessionKey) throws SessionException;
433
434     /**
435      * Returns the number of paged sessions.
436      */

437     protected abstract int getPagedSessionCount() throws SessionException;
438
439     /**
440      * Puts a session into the 'active' state. Reads paged version
441      * if necessary.
442      *
443      * @param activeKey the session-thread key for the session
444      * that should be activated.
445      * @exception SessionException
446      * if the session cannot be activated.
447      */

448     private synchronized PagedSession activateSession(String JavaDoc sessionKey)
449         throws SessionException {
450         PagedSession session = null;
451         boolean isPaged = !activeCache.containsKey(sessionKey)
452             && !passiveCache.containsKey(sessionKey);
453 // v. strahinja, 01 okt 2002 debug(3, "activateSession: " + sessionKey);
454
debug("activateSession: " + sessionKey);
455         if (isPaged) {
456             ensureNewSession();
457             session = pageIn(sessionKey);
458         } else if (passiveCache.containsKey(sessionKey)) {
459 // v. strahinja, 01 okt 2002 debug(3, "passive -> active : " + sessionKey);
460
debug("passive -> active : " + sessionKey);
461             session = (PagedSession)passiveCache.remove(sessionKey);
462         } else if (activeCache.containsKey(sessionKey)) {
463 // v. strahinja, 01 okt 2002 debug(3, "session is active : " + sessionKey);
464
debug("session is active : " + sessionKey);
465             session = (PagedSession)activeCache.get(sessionKey);
466         }
467         if (session != null) {
468             activeCache.put(sessionKey, session);
469         }
470         return session;
471     }
472
473     /**
474      * Specifies if a key is currently in use.
475      *
476      * @param sessionKey the session key to be tested.
477      * @return true if the session key is in use.
478      * @exception SessionException if an error occurs.
479      */

480     public boolean containsKey(String JavaDoc sessionKey) throws SessionException {
481         if (activeCache.containsKey(sessionKey)
482             || passiveCache.containsKey(sessionKey)
483             || pagedSessionKeyExists(sessionKey)) {
484             return true;
485         }
486         return false;
487     }
488
489     /**
490      * Returns true if the specified session key is in use
491      * by a session that has been paged out.
492      *
493      * @param sessionKey the session key to test.
494      * @return true if the session key is in use by a paged session.
495      * @exception SessionException if an error occurs.
496      */

497     protected abstract boolean pagedSessionKeyExists(String JavaDoc sessionKey)
498         throws SessionException;
499
500     /**
501      * Returns the current number of sessions.
502      *
503      * @return the session count.
504      * @exception SessionException if an error occurs.
505      */

506     public int size() throws SessionException {
507         return activeCache.size() + passiveCache.size()
508             + getPagedSessionCount();
509     }
510
511     /**
512      * Returns the current number of sessions that are paged to
513      * persistent store.
514      *
515      * @return
516      * the 'paged' session count.
517      * @exception SessionException
518      * if the size cannot be determined
519      */

520     public int pagedSize() throws SessionException {
521         return getPagedSessionCount();
522     }
523
524     /**
525      * Returns an enumeration of keys for the cached sessions.
526      *
527      * @return the session keys enumeration.
528      * @exception SessionException if an error occurs.
529      */

530     public synchronized Enumeration JavaDoc keys() throws SessionException {
531         try {
532             Vector JavaDoc v = new Vector JavaDoc();
533             String JavaDoc sessionKey;
534             Enumeration JavaDoc e;
535             e = activeCache.keys();
536             while (e.hasMoreElements()) {
537                 sessionKey = (String JavaDoc)e.nextElement();
538                 if (!v.contains(sessionKey)) {
539                     v.addElement(sessionKey);
540                 }
541             }
542             e = passiveCache.keys();
543             while (e.hasMoreElements()) {
544                 sessionKey = (String JavaDoc)e.nextElement();
545                 if (!v.contains(sessionKey)) {
546                     v.addElement(sessionKey);
547                 }
548             }
549             e = getPagedSessionKeys();
550             while (e.hasMoreElements()) {
551                 sessionKey = (String JavaDoc)e.nextElement();
552                 if (!v.contains(sessionKey)) {
553                     v.addElement(sessionKey);
554                 }
555             }
556             return v.elements();
557         } catch (Exception JavaDoc e) {
558             throw new SessionException(e);
559         }
560     }
561
562     /**
563      * Returns an enumeration of the keys of all the sessions that have
564      * been paged out to persistent storage.
565      *
566      * @return the session key enumeration.
567      * @exception SessionException if an error occurs.
568      */

569     protected abstract Enumeration JavaDoc getPagedSessionKeys() throws SessionException;
570
571     /**
572      * Cleans up (removes) the oldest unused (new) session from the
573      * passive cache.
574      *
575      * @return true if an unused session was cleaned up.
576      */

577     private void cleanupNewSession() throws SessionException {
578         if (!cleanupNewPagedSession()) {
579             Enumeration JavaDoc e;
580             String JavaDoc key = null;
581             long oldestTime = -1;
582             e = passiveCache.keys();
583             while (e.hasMoreElements()) {
584                 PagedSession s = (PagedSession)passiveCache.get(e.nextElement());
585                 if (s.isNew()) {
586                     if ((oldestTime < 0)
587                         || (s.getTimeCreated() < oldestTime)) {
588                         oldestTime = s.getTimeCreated();
589                         key = s.getSessionKey();
590                     }
591                 }
592             }
593             if (key != null) {
594                 removeSession(key);
595             }
596         }
597     }
598
599     /**
600      * Pages out any sessions that are passive and have exceeded
601      * the page time threshold.
602      *
603      * @return returns the amount of time in milliseconds when
604      * the next check should occur.
605      */

606     long checkPassiveSessions() throws SessionException {
607         return checkPassiveSessions(pageTimeThreshold);
608     }
609
610     /**
611      * Pages out any sessions that are passive and have exceeded
612      * the page time threshold.
613      *
614      * @param threshold the threshold when a passive session
615      * should be paged.
616      * @return returns the amount of time in milliseconds when
617      * the next check should occur.
618      */

619     private synchronized long checkPassiveSessions(long threshold)
620         throws SessionException {
621         long nextCheck = threshold;
622         Enumeration JavaDoc e = passiveCache.elements();
623         long now = System.currentTimeMillis();
624         while (e.hasMoreElements()) {
625             PagedSession s = (PagedSession) e.nextElement();
626             long passiveTime = now - s.getTimeLastUsed();
627             if (passiveTime >= threshold) {
628                 pageOut(s);
629                 passiveCache.remove(s.getSessionKey());
630             } else if (nextCheck > (threshold - passiveTime)) {
631                 nextCheck = threshold - passiveTime;
632             }
633         }
634         return nextCheck;
635     }
636
637     /**
638      * Removes a session that is new and paged.
639      *
640      * @return true is a new session was found and deleted.
641      * @exception SessionException if an error occurs.
642      */

643     protected abstract boolean cleanupNewPagedSession() throws SessionException;
644
645
646     /**
647      * Ensures that a new session can be put into the list
648      * in-core sessions that are being managed.
649      * If necessary, this method will page a passive session disk in
650      * in order to guarantee that another session can be
651      * read into memory (or created). This method may block
652      * if a session first needs to be paged to disk.
653      */

654     private void ensureNewSession() throws SessionException {
655         if (pageThreshold > 0) { // If not a write-through cache....
656
while ((activeCache.size() + passiveCache.size()) > pageThreshold) {
657                 if (passiveCache.size() == 0) {
658                     try {
659 // v. strahinja, 01 okt 2002 debug(3, "waiting for a passive session that can be paged...");
660
debug("waiting for a passive session that can be paged...");
661                         wait(pageWait);
662                         if (passiveCache.size() <= 0) {
663                             throw new SessionException("Unable to activate session: "
664                                                        + "no sessions are ready to be paged.");
665                         }
666                     } catch (InterruptedException JavaDoc e) {
667                         // ignore
668
}
669                 } else {
670 // v. strahinja, 01 okt 2002 debug(3, "a passive session ready to be paged");
671
debug("a passive session ready to be paged");
672                     Enumeration JavaDoc keys = passiveCache.keys();
673                     PagedSession s = (PagedSession)passiveCache.get((String JavaDoc)keys.nextElement());
674                     pageOut(s);
675                     passiveCache.remove(s.getSessionKey());
676                 }
677             }
678         }
679     }
680
681     /**
682      * Shuts down the session home. Pages out all active sessions.
683      */

684     public synchronized void shutdown() {
685         try {
686             if (thresholdTimer != null) {
687                 thresholdTimer.shutdown();
688                 thresholdTimer = null;
689             }
690             // DT 17.11.2003 BEG
691
Enumeration JavaDoc e=activeThreadCache.keys();
692             while (e.hasMoreElements()){
693                     SessionThread s=(SessionThread)e.nextElement();
694                     passivateSession(s.thread, s.sessionKey);
695             }
696             // DT 17.11.2003 END
697
checkPassiveSessions(0);
698         } catch (Exception JavaDoc e) {
699         Enhydra.getLogChannel().write(Logger.ERROR,
700                                           "PagedSessionHome: "
701                                           + "failed to page out active and passive sessions.",
702                                           e);
703         }
704     }
705
706
707     /**
708      * Returns true if the current configuration is for
709      * a write trhough cache.
710      *
711      * @return true if write through cache is configured.
712      */

713     private boolean isWriteThroughCache() {
714         return (pageThreshold == 0);
715     }
716
717     /**
718      * Prints debug information under Logger.DEBUG.
719      *
720      * @param msg the message to print.
721      */

722     protected void debug(String JavaDoc msg) {
723     debug(0, msg);
724     }
725
726     /**
727      * Prints debug information under Logger.DEBUG.
728      *
729      * @param level the debug level.
730      * @param msg the message to print.
731      */

732     protected void debug(int level, String JavaDoc msg) {
733      int dbg = Logger.DEBUG;
734      switch (level) {
735      case 1:
736          dbg = Logger.DEBUG1;
737          break;
738      case 2:
739          dbg = Logger.DEBUG2;
740          break;
741      case 3:
742          dbg = Logger.DEBUG3;
743          break;
744      case 4:
745          dbg = Logger.DEBUG4;
746          break;
747      case 5:
748          dbg = Logger.DEBUG5;
749          break;
750      case 6:
751          dbg = Logger.DEBUG6;
752          break;
753      case 7:
754          dbg = Logger.DEBUG7;
755          break;
756      case 8:
757          dbg = Logger.DEBUG8;
758          break;
759      case 9:
760          dbg = Logger.DEBUG9;
761          break;
762      default:
763          dbg = Logger.DEBUG;
764          break;
765      }
766     Enhydra.getLogChannel().write(dbg, "PersistentSessionHome("
767                                       + Thread.currentThread().getName()
768                                       + "): " + msg);
769     }
770 }
771
772
773
Popular Tags