Source Code Cross Referenced for MessAdmin.java in  » Profiler » MessAdmin » clime » messadmin » core » 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 » Profiler » MessAdmin » clime.messadmin.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package clime.messadmin.core;
004:
005:        import java.util.Set;
006:
007:        import clime.messadmin.model.Application;
008:        import clime.messadmin.model.Server;
009:        import clime.messadmin.model.Session;
010:
011:        /**
012:         * Manages actions on WebApp and Sessions. Used by admin servlet and JMX.
013:         * @author Cédrik LIME
014:         */
015:        public class MessAdmin {
016:
017:            private MessAdmin() {
018:                super ();
019:            }
020:
021:            public static String getVersion() {
022:                String result = "";//$NON-NLS-1$
023:                Package p = MessAdmin.class.getPackage();
024:                if (p != null) {
025:                    result = p.getImplementationVersion();
026:                }
027:                return result;
028:            }
029:
030:            /**
031:             * If message if blank or null, remove ServletContext attribute, otherwise inject message into ServletContext
032:             * @param applicationIds
033:             * @param message
034:             * @return number of modified sessions
035:             */
036:            public static int injectApplicationsPermanent(
037:                    String[] applicationIds, String message) {
038:                if (null == applicationIds) {
039:                    return 0;
040:                }
041:                int nbAffectedApplications = 0;
042:                for (int i = 0; i < applicationIds.length; ++i) {
043:                    String applicationId = applicationIds[i];
044:                    Application application = Server.getInstance()
045:                            .getApplication(applicationId);
046:                    if (null == application) {
047:                        // Shouldn't happen, but let's play nice...
048:                        //log("WARNING: can't inject message for null application " + applicationId);
049:                        continue;
050:                    }
051:                    boolean actionDone = application
052:                            .injectPermanentMessage(message);
053:                    if (actionDone) {
054:                        ++nbAffectedApplications;
055:                    }
056:                }
057:                return nbAffectedApplications;
058:            }
059:
060:            /**
061:             * If message if blank or null, remove ServletContext attribute, otherwise inject message into ServletContext
062:             * @param applicationIds
063:             * @param message
064:             * @return number of modified sessions
065:             */
066:            public static int injectApplicationsOnce(String[] applicationIds,
067:                    String message) {
068:                if (null == applicationIds) {
069:                    return 0;
070:                }
071:                int nbAffectedApplications = 0;
072:                for (int i = 0; i < applicationIds.length; ++i) {
073:                    String applicationId = applicationIds[i];
074:                    int result = injectAllSessions(applicationId, message);
075:                    if (result > 0) {
076:                        ++nbAffectedApplications;
077:                    }
078:                }
079:                return nbAffectedApplications;
080:            }
081:
082:            /**
083:             * If message if blank or null, remove HttpSession attribute, otherwise inject message into HttpSessions
084:             * @param message
085:             * @return number of modified sessions
086:             */
087:            public static int injectAllSessions(String context, String message) {
088:                Set/*<String>*/activeSessionIds = Server.getInstance()
089:                        .getApplication(context).getActiveSessionsIds();
090:                String[] sessionIds = new String[activeSessionIds.size()];
091:                sessionIds = (String[]) activeSessionIds.toArray(sessionIds);
092:                return injectSessions(context, sessionIds, message);
093:            }
094:
095:            /**
096:             * If message if blank or null, remove HttpSession attribute, otherwise inject message into HttpSessions
097:             * @param sessionIds
098:             * @param message
099:             * @return number of modified sessions
100:             */
101:            public static int injectSessions(String context,
102:                    String[] sessionIds, String message) {
103:                if (null == sessionIds) {
104:                    return 0;
105:                }
106:                int nbAffectedSessions = 0;
107:                Application application = Server.getInstance().getApplication(
108:                        context);
109:                for (int i = 0; i < sessionIds.length; ++i) {
110:                    String sessionId = sessionIds[i];
111:                    Session session = application.getSession(sessionId);
112:                    if (null == session) {
113:                        // Shouldn't happen, but let's play nice...
114:                        //log("WARNING: can't inject message for null session " + sessionId);
115:                        continue;
116:                    }
117:                    boolean actionDone = session.injectMessage(message);
118:                    if (actionDone) {
119:                        ++nbAffectedSessions;
120:                    }
121:                }
122:                return nbAffectedSessions;
123:            }
124:
125:            /**
126:             * Invalidate HttpSessions
127:             * @param sessionIds
128:             * @return number of invalidated sessions
129:             */
130:            public static int invalidateSessions(String context,
131:                    String[] sessionIds) {
132:                if (null == sessionIds) {
133:                    return 0;
134:                }
135:                int nbAffectedSessions = 0;
136:                Application application = Server.getInstance().getApplication(
137:                        context);
138:                for (int i = 0; i < sessionIds.length; ++i) {
139:                    String sessionId = sessionIds[i];
140:                    Session session = application.getSession(sessionId);
141:                    if (null == session) {
142:                        // Shouldn't happen, but let's play nice...
143:                        //log("WARNING: can't invalidate null session " + sessionId);
144:                        continue;
145:                    }
146:                    try {
147:                        session.getSessionInfo().invalidate();
148:                        ++nbAffectedSessions;
149:                        //log("Invalidating session id " + sessionId);
150:                    } catch (IllegalStateException ise) {
151:                        //log("Can't invalidate already invalidated session id " + sessionId);
152:                    }
153:                }
154:                return nbAffectedSessions;
155:            }
156:
157:            /**
158:             * Removes an attribute from an HttpSession
159:             * @param sessionId
160:             * @param attributeName
161:             * @return true if there was an attribute removed, false otherwise
162:             */
163:            public static boolean removeSessionAttribute(String context,
164:                    String sessionId, String attributeName) {
165:                Session session = Server.getInstance().getApplication(context)
166:                        .getSession(sessionId);
167:                if (null == session) {
168:                    // Shouldn't happen, but let's play nice...
169:                    //log("WARNING: can't remove attribute '" + attributeName + "' for null session " + sessionId);
170:                    return false;
171:                }
172:                boolean wasPresent = false;
173:                try {
174:                    wasPresent = (null != session.getSessionInfo()
175:                            .getAttribute(attributeName));
176:                    session.getSessionInfo().removeAttribute(attributeName);
177:                } catch (IllegalStateException ise) {
178:                    //log("Can't remote attribute '" + attributeName + "' for invalidated session id " + session.getId());
179:                }
180:                return wasPresent;
181:            }
182:
183:            /**
184:             * Sets the maximum inactive interval (session timeout) an HttpSession
185:             * @param sessionId
186:             * @param maxInactiveInterval in seconds
187:             * @return old value for maxInactiveInterval
188:             */
189:            public static int setSessionMaxInactiveInterval(String context,
190:                    String sessionId, int maxInactiveInterval) {
191:                Session session = Server.getInstance().getApplication(context)
192:                        .getSession(sessionId);
193:                if (null == session) {
194:                    // Shouldn't happen, but let's play nice...
195:                    //log("WARNING: can't set timout for null session " + sessionId);
196:                    return 0;
197:                }
198:                try {
199:                    int oldMaxInactiveInterval = session.getSessionInfo()
200:                            .getMaxInactiveInterval();
201:                    session.getSessionInfo().setMaxInactiveInterval(
202:                            maxInactiveInterval);
203:                    return oldMaxInactiveInterval;
204:                } catch (IllegalStateException ise) {
205:                    // invalidated session
206:                    return 0;
207:                }
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.