Source Code Cross Referenced for ClusterPresenceService.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » presence » impl » 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.sakaiproject.presence.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/presence/tags/sakai_2-4-1/presence-impl/impl/src/java/org/sakaiproject/presence/impl/ClusterPresenceService.java $
003:         * $Id: ClusterPresenceService.java 15112 2006-09-21 19:10:54Z ggolden@umich.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.presence.impl;
021:
022:        import java.util.List;
023:
024:        import org.apache.commons.logging.Log;
025:        import org.apache.commons.logging.LogFactory;
026:        import org.sakaiproject.db.api.SqlService;
027:
028:        /**
029:         * <p>
030:         * ClusterPresenceService extends the BasePresenceService with a Storage model that keeps track of presence for a cluster of Sakai app servers, backed by a shared DB table.
031:         * </p>
032:         */
033:        public class ClusterPresenceService extends BasePresenceService {
034:            /** Our log (commons). */
035:            private static Log M_log = LogFactory
036:                    .getLog(ClusterPresenceService.class);
037:
038:            /**
039:             * Allocate a new storage object.
040:             * 
041:             * @return A new storage object.
042:             */
043:            protected Storage newStorage() {
044:                return new ClusterStorage();
045:            }
046:
047:            /** Dependency: SqlService */
048:            protected SqlService m_sqlService = null;
049:
050:            /**
051:             * Dependency: SqlService.
052:             * 
053:             * @param service
054:             *        The SqlService.
055:             */
056:            public void setSqlService(SqlService service) {
057:                m_sqlService = service;
058:            }
059:
060:            /** Configuration: to run the ddl on init or not. */
061:            protected boolean m_autoDdl = false;
062:
063:            /**
064:             * Configuration: to run the ddl on init or not.
065:             * 
066:             * @param value
067:             *        the auto ddl value.
068:             */
069:            public void setAutoDdl(String value) {
070:                m_autoDdl = new Boolean(value).booleanValue();
071:            }
072:
073:            /**********************************************************************************************************************************************************************************************************************************************************
074:             * Init and Destroy
075:             *********************************************************************************************************************************************************************************************************************************************************/
076:
077:            /**
078:             * Final initialization, once all dependencies are set.
079:             */
080:            public void init() {
081:                try {
082:                    // if we are auto-creating our schema, check and create
083:                    if (m_autoDdl) {
084:                        m_sqlService.ddl(this .getClass().getClassLoader(),
085:                                "sakai_presence");
086:                    }
087:
088:                    super .init();
089:                } catch (Throwable t) {
090:                    M_log.warn("init(): ", t);
091:                }
092:            }
093:
094:            /**********************************************************************************************************************************************************************************************************************************************************
095:             * Storage
096:             *********************************************************************************************************************************************************************************************************************************************************/
097:
098:            protected class ClusterStorage implements  Storage {
099:                /**
100:                 * {@inheritDoc}
101:                 */
102:                public void setPresence(String sessionId, String locationId) {
103:                    // send this to the database
104:                    String statement = "insert into SAKAI_PRESENCE (SESSION_ID,LOCATION_ID) values ( ?, ?)";
105:
106:                    // collect the fields
107:                    Object fields[] = new Object[2];
108:                    fields[0] = sessionId;
109:                    fields[1] = locationId;
110:
111:                    // process the insert
112:                    boolean ok = m_sqlService.dbWrite(statement, fields);
113:                    if (!ok) {
114:                        M_log.warn("setPresence(): dbWrite failed");
115:                    }
116:                }
117:
118:                /**
119:                 * {@inheritDoc}
120:                 */
121:                public void removePresence(String sessionId, String locationId) {
122:                    // form the SQL delete statement
123:                    String statement = "delete from SAKAI_PRESENCE"
124:                            + " where ( SESSION_ID = ? and LOCATION_ID = ?)";
125:
126:                    // setup the fields
127:                    Object[] fields = new Object[1];
128:                    fields[0] = sessionId;
129:
130:                    // process the remove
131:                    boolean ok = m_sqlService.dbWrite(statement, fields,
132:                            locationId);
133:                    if (!ok) {
134:                        M_log.warn("removePresence(): dbWrite failed");
135:                    }
136:                }
137:
138:                /**
139:                 * {@inheritDoc}
140:                 */
141:                public List getSessions(String locationId) {
142:                    // Note: this assumes
143:                    // 1) the UsageSessionService has a db component selected.
144:                    // 2) the presence table and the session table are in the same db.
145:
146:                    // to join the presence table to the session
147:                    String joinTable = "SAKAI_PRESENCE";
148:                    String joinAlias = "A";
149:                    String joinColumn = "SESSION_ID";
150:                    String joinCriteria = "A.LOCATION_ID = ?";
151:
152:                    // send in the locationId
153:                    Object[] fields = new Object[1];
154:                    fields[0] = locationId;
155:
156:                    // get these from usage session
157:                    List sessions = m_usageSessionService.getSessions(
158:                            joinTable, joinAlias, joinColumn, joinCriteria,
159:                            fields);
160:
161:                    return sessions;
162:                }
163:
164:                /**
165:                 * {@inheritDoc}
166:                 */
167:                public List getLocations() {
168:                    // form the SQL query
169:                    String statement = "select DISTINCT LOCATION_ID from SAKAI_PRESENCE";
170:
171:                    List locs = m_sqlService.dbRead(statement);
172:
173:                    return locs;
174:                }
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.