Source Code Cross Referenced for ContextCache.java in  » Portal » Open-Portal » com » sun » portal » wireless » taglibs » base » 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 » Portal » Open Portal » com.sun.portal.wireless.taglibs.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: ContextCache.java,v 1.9 2005/10/18 22:28:22 js143762 Exp $
003:         * Copyright 2002 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.wireless.taglibs.base;
014:
015:        import java.lang.*;
016:        import java.util.*;
017:        import java.util.logging.Logger;
018:        import java.util.logging.Level;
019:        import java.util.logging.LogRecord;
020:
021:        import com.iplanet.sso.*;
022:        import com.sun.portal.log.common.PortalLogger;
023:
024:        //import com.sun.portal.profile.*;
025:
026:        /**
027:         * ContextCache - cache to hold Context
028:         * 
029:         * @author John Saare
030:         * @version 2.0
031:         * @see Context
032:         */
033:        public class ContextCache {
034:
035:            protected static HashMap contextCache = new HashMap(5);
036:            protected static final int START_SIZE = 1023;
037:            protected HashMap contexts = null;
038:
039:            // Create a logger for this class
040:            private static Logger debugLogger = PortalLogger
041:                    .getLogger(ContextCache.class);
042:
043:            /**
044:             * Private ContextCache constructor; use getInstance()
045:             * instead to get a handle to an instance.
046:             */
047:            public ContextCache() {
048:                contexts = new HashMap(START_SIZE);
049:            }
050:
051:            /**
052:             * Return an instance; creating one if needed
053:             * 
054:             * @return the ContextCache instance
055:             */
056:            public static synchronized ContextCache getInstance(String className) {
057:                ContextCache c = (ContextCache) contextCache.get(className);
058:
059:                if (c != null) {
060:                    return c;
061:                }
062:
063:                c = new ContextCache();
064:                contextCache.put(className, c);
065:
066:                return c;
067:            }
068:
069:            /**
070:             * Put a context into the cache
071:             * 
072:             * @param context the context
073:             */
074:            public void put(Context context, String configName) {
075:                put(context, configName, true);
076:            }
077:
078:            /**
079:             * Put a context into the cache
080:             * 
081:             * @param context  the context
082:             * @param listener whether to add a session listener
083:             */
084:            public synchronized void put(Context context, String configName,
085:                    boolean listener) {
086:                SSOTokenID sid = context.getSessionID();
087:                String sidString = sid.toString();
088:                if (configName != null) {
089:                    sidString = sidString + configName;
090:                }
091:                contexts.put(sidString, context);
092:                if (listener) {
093:                    HashMapReaper reaper = new HashMapReaper(sidString,
094:                            contexts);
095:                    try {
096:                        context.getSession().addSSOTokenListener(reaper);
097:                    } catch (SSOException e) {
098:                        if (debugLogger.isLoggable(Level.INFO)) {
099:                            LogRecord logRecord = new LogRecord(Level.INFO,
100:                                    "PSMA_CSPWTB0016");
101:                            logRecord.setParameters(new Object[] { sidString });
102:                            logRecord.setThrown(e);
103:                            logRecord.setLoggerName(debugLogger.getName());
104:                            debugLogger.log(logRecord);
105:                        }
106:                    }
107:
108:                }
109:            }
110:
111:            /**
112:             * Remove a context from the cache
113:             * 
114:             * @param context  the context
115:             * @param configName  the configName used
116:             */
117:            public synchronized void remove(Context context, String configName) {
118:                SSOTokenID sid = context.getSessionID();
119:                String sidString = sid.toString();
120:                if (configName != null) {
121:                    sidString = sidString + configName;
122:                }
123:                Context lcontext = (Context) contexts.get(sidString);
124:                contexts.remove(sidString);
125:                // no way to remove listeners from ssotokens, so it'll keep on 
126:                // listening until the session expires.  Memory hit?  somewhat.
127:                // Performance hit?  small.  Will exception be thrown if there
128:                // continues to be new contexts created and stored?  maybe.
129:            }
130:
131:            /**
132:             * Get context from the specified session
133:             * 
134:             * @param session the portal session
135:             * @return the saved context
136:             */
137:            public synchronized Context get(SSOToken session, String configName) {
138:                if (session == null) {
139:                    return null;
140:                }
141:
142:                String sidString = session.getTokenID().toString();
143:                if (configName != null)
144:                    sidString = sidString + configName;
145:                Context context = (Context) contexts.get(sidString);
146:
147:                return context;
148:            }
149:
150:            /*
151:             * This class is used to purge the caches of per-session entries.
152:             */
153:            private class HashMapReaper implements  SSOTokenListener {
154:
155:                private String key;
156:                private HashMap hashMap;
157:
158:                HashMapReaper(String key, HashMap hashMap) {
159:                    this .key = key;
160:                    this .hashMap = hashMap;
161:                }
162:
163:                /**
164:                 * Implements SSOTokenListener "ssoTokenChanged" method.
165:                 */
166:                public void ssoTokenChanged(com.iplanet.sso.SSOTokenEvent evt) {
167:                    try {
168:                        SSOToken token = evt.getToken();
169:                        int evtType = evt.getType();
170:
171:                        if (evtType != evt.SSO_TOKEN_DESTROY
172:                                && evtType != evt.SSO_TOKEN_IDLE_TIMEOUT
173:                                && evtType != evt.SSO_TOKEN_MAX_TIMEOUT) {
174:                            return;
175:                        }
176:
177:                        clearCache();
178:
179:                    } catch (Exception e) {
180:                        debugLogger.log(Level.INFO, "PSMA_CSPWTB0001", e);
181:                    }
182:                }
183:
184:                public void clearCache() {
185:                    try {
186:                        Context tempContext = (Context) hashMap.get(key);
187:                        tempContext.closeConnection();
188:                    } catch (Exception ex) {
189:                    }
190:                    hashMap.remove(key);
191:                }
192:
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.