Source Code Cross Referenced for MetasearchSessionManager.java in  » ERP-CRM-Financial » sakai » org » sakaibrary » xserver » session » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaibrary.xserver.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.sakaibrary.xserver.session;
002:
003:        import net.sf.ehcache.Cache;
004:        import net.sf.ehcache.CacheException;
005:        import net.sf.ehcache.CacheManager;
006:        import net.sf.ehcache.Element;
007:
008:        /**
009:         * MetasearchSessionManager is a Singleton class designed for session
010:         * management in metasearching applications.  It makes use of ehcache
011:         * and MetasearchSession objects indexed by globally unique identifiers
012:         * to hold all session state for individual sessions.
013:         * 
014:         * @author gbhatnag
015:         */
016:        public class MetasearchSessionManager implements  java.io.Serializable {
017:            /* constants */
018:            private static final String CACHE_NAME = "org.sakaibrary.xserver.session.MetasearchSession";
019:            private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
020:                    .getLog("org.sakaibrary.osid.repository.xserver.session.MetasearchSessionManager");
021:
022:            /* private static variables */
023:            private static MetasearchSessionManager metasearchSessionManager;
024:            private static CacheManager cacheManager;
025:            private static Cache cache;
026:
027:            /**
028:             * Private constructor to ensure only one MetasearchSessionManager
029:             * is instantiated.  Initializes ehcache components CacheManager
030:             * and Cache.
031:             */
032:            private MetasearchSessionManager() {
033:                try {
034:                    cacheManager = CacheManager.create();
035:
036:                    // add the cache to the CacheManager if it doesn't already exist
037:                    if (!cacheManager.cacheExists(CACHE_NAME)) {
038:                        // create a cache using ehcache 1.2.4 constructor
039:                        Cache temp = new Cache(
040:                                CACHE_NAME, // cache name
041:                                50, // maxElementsInMemory
042:                                net.sf.ehcache.store.MemoryStoreEvictionPolicy.LRU,
043:                                true, // overflowToDisk
044:                                "ignored", // disk store path - ignored, CacheManager sets it using setter injection
045:                                false, // eternal
046:                                0L, // time to live (seconds)
047:                                900L, // time to idle (seconds)
048:                                false, // diskPersistent
049:                                120L, // diskExpiryThreadIntervalSeconds
050:                                null, // registeredEventListeners
051:                                null // bootstrapCacheLoader
052:                        );
053:                        cacheManager.addCache(temp);
054:                    }
055:
056:                    // get cache for use
057:                    cache = cacheManager.getCache(CACHE_NAME);
058:                } catch (CacheException ce) {
059:                    LOG
060:                            .warn(
061:                                    "MetasearchSessionManager() failed to create CacheManager or Cache",
062:                                    ce);
063:                }
064:
065:                LOG.info("ehcache session initiated properly.");
066:            }
067:
068:            /**
069:             * Gets the Singleton instance of MetasearchSessionManager
070:             * 
071:             * @return an instance of MetasearchSessionManager
072:             */
073:            public static synchronized MetasearchSessionManager getInstance() {
074:                if (metasearchSessionManager == null) {
075:                    metasearchSessionManager = new MetasearchSessionManager();
076:                }
077:
078:                return metasearchSessionManager;
079:            }
080:
081:            /**
082:             * Puts the MetasearchSession object into the MetasearchSessionManager
083:             * cache indexed by the guid.  If the guid already exists, the
084:             * MetasearchSession object is updated with the given object.
085:             * 
086:             * @param guid a globally unique identifier String
087:             * @param ms the MetasearchSession object to be put/updated in the
088:             * MetasearchSessionManager cache.
089:             */
090:            public void putMetasearchSession(String guid, MetasearchSession ms) {
091:                // given guid and ms.getGuid() should match -- TODO new Exception Type?
092:                if (!ms.getGuid().equals(guid)) {
093:                    LOG
094:                            .warn("putMetasearchSession(): putting MetasearchSession into "
095:                                    + "ehcache with mismatched guids...");
096:                }
097:
098:                // the following puts if guid is new, updates if guid is old
099:                cache.put(new Element(guid, ms));
100:            }
101:
102:            /**
103:             * Gets the MetasearchSession object out of the MetasearchSessionManager
104:             * cache indexed by the guid.
105:             * 
106:             * @param guid a globally unique identifier String
107:             * @return the MetasearchSession object if it exists and has not expired,
108:             * otherwise, null
109:             */
110:            public MetasearchSession getMetasearchSession(String guid) {
111:                Element element = null;
112:                try {
113:                    element = cache.get(guid);
114:                } catch (CacheException ce) {
115:                    LOG.warn("MetasearchSessionManager.getMetasearchSession()"
116:                            + " cannot get cache with guid: " + guid, ce);
117:                }
118:
119:                // element could have expired
120:                boolean isExpired = (element == null) ? true : cache
121:                        .isExpired(element);
122:
123:                return isExpired ? null : (MetasearchSession) element
124:                        .getValue();
125:            }
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.