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


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/courier/tags/sakai_2-4-1/courier-impl/impl/src/java/org/sakaiproject/courier/impl/BasicCourierService.java $
003:         * $Id: BasicCourierService.java 6940 2006-03-23 16:35:31Z ggolden@umich.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 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.courier.impl;
021:
022:        // imports
023:        import java.util.Hashtable;
024:        import java.util.Iterator;
025:        import java.util.List;
026:        import java.util.Map;
027:        import java.util.Vector;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:        import org.sakaiproject.courier.api.CourierService;
032:        import org.sakaiproject.courier.api.Delivery;
033:        import org.sakaiproject.util.StringUtil;
034:
035:        /**
036:         * <p>
037:         * BasicCourierService is the implementation for the CourierService.
038:         * </p>
039:         */
040:        public class BasicCourierService implements  CourierService {
041:            /** Our logger. */
042:            private static Log M_log = LogFactory
043:                    .getLog(BasicCourierService.class);
044:
045:            /** Stores a List of Deliveries for each address, keyed by address. */
046:            protected Map m_addresses = new Hashtable();
047:
048:            /**********************************************************************************************************************************************************************************************************************************************************
049:             * Dependencies and their setter methods
050:             *********************************************************************************************************************************************************************************************************************************************************/
051:
052:            /**********************************************************************************************************************************************************************************************************************************************************
053:             * Init and Destroy
054:             *********************************************************************************************************************************************************************************************************************************************************/
055:
056:            /**
057:             * Final initialization, once all dependencies are set.
058:             */
059:            public void init() {
060:                m_addresses.clear();
061:                M_log.info("init()");
062:            }
063:
064:            /**
065:             * Returns to uninitialized state.
066:             */
067:            public void destroy() {
068:                m_addresses.clear();
069:                M_log.info("destroy()");
070:            }
071:
072:            /**********************************************************************************************************************************************************************************************************************************************************
073:             * CourierService implementation
074:             *********************************************************************************************************************************************************************************************************************************************************/
075:
076:            /**
077:             * Queue up a delivery for the client window identified in the Delivery object. The particular form of delivery is determined by the type of Delivery object sent.
078:             * 
079:             * @param delivery
080:             *        The Delivery (or extension) object to deliver.
081:             */
082:            public void deliver(Delivery delivery) {
083:                if (M_log.isDebugEnabled())
084:                    M_log.debug("deliver(): " + delivery);
085:
086:                String address = delivery.getAddress();
087:
088:                // find the entry in m_addresses
089:                List deliveries = (List) m_addresses.get(address);
090:
091:                // create if needed
092:                if (deliveries == null) {
093:                    synchronized (m_addresses) {
094:                        deliveries = (List) m_addresses.get(address);
095:                        if (deliveries == null) {
096:                            deliveries = new Vector();
097:                            m_addresses.put(address, deliveries);
098:                        }
099:                    }
100:                }
101:
102:                // if this doesn't exist in the list already, add it
103:                synchronized (deliveries) {
104:                    if (!deliveries.contains(delivery)) {
105:                        deliveries.add(delivery);
106:                    }
107:                }
108:            }
109:
110:            /**
111:             * Clear any pending delivery requests to the particular client window for this element.
112:             * 
113:             * @param address
114:             *        The address of the client window.
115:             * @param elementId
116:             *        The id of the html element.
117:             */
118:            public void clear(String address, String elementId) {
119:                if (M_log.isDebugEnabled())
120:                    M_log.debug("clear(): " + address + ", " + elementId);
121:
122:                // find the entry in m_addresses
123:                List deliveries = (List) m_addresses.get(address);
124:
125:                // if not there we are done
126:                if (deliveries == null)
127:                    return;
128:
129:                // remove any Deliveries with this elementId
130:                synchronized (deliveries) {
131:                    for (Iterator it = deliveries.iterator(); it.hasNext();) {
132:                        Delivery delivery = (Delivery) it.next();
133:                        if (!StringUtil.different(delivery.getElement(),
134:                                elementId)) {
135:                            it.remove();
136:                        }
137:                    }
138:                }
139:
140:                // if none left, remove it from the list
141:                if (deliveries.isEmpty()) {
142:                    synchronized (m_addresses) {
143:                        m_addresses.remove(address);
144:                    }
145:                }
146:            }
147:
148:            /**
149:             * Clear any pending delivery requests to this session client window.
150:             * 
151:             * @param address
152:             *        The address of client window.
153:             */
154:            public void clear(String address) {
155:                if (M_log.isDebugEnabled())
156:                    M_log.debug("clear(): " + address);
157:
158:                // remove this portal from m_addresses
159:                synchronized (m_addresses) {
160:                    m_addresses.remove(address);
161:                }
162:            }
163:
164:            /**
165:             * Access and de-queue the Deliveries queued up for a particular session client window.
166:             * 
167:             * @param address
168:             *        The address of client window.
169:             * @return a List of Delivery objects addressed to this session client window.
170:             */
171:            public List getDeliveries(String address) {
172:                if (M_log.isDebugEnabled())
173:                    M_log.debug("getDeliveries(): " + address);
174:
175:                // find the entry in m_addresses
176:                List deliveries = null;
177:                synchronized (m_addresses) {
178:                    deliveries = (List) m_addresses.get(address);
179:                    if (deliveries != null) {
180:                        m_addresses.remove(address);
181:                    }
182:                }
183:
184:                // if empty, return something
185:                if (deliveries == null) {
186:                    deliveries = new Vector();
187:                }
188:
189:                // "act" all the deliveries
190:                for (Iterator it = deliveries.iterator(); it.hasNext();) {
191:                    Delivery delivery = (Delivery) it.next();
192:                    delivery.act();
193:                }
194:
195:                return deliveries;
196:            }
197:
198:            /**
199:             * Check to see if there are any deliveries queued up for a particular session client window.
200:             * 
201:             * @param address
202:             *        The address of the client window.
203:             * @return true if there are deliveries for this client window, false if not.
204:             */
205:            public boolean hasDeliveries(String address) {
206:                if (M_log.isDebugEnabled())
207:                    M_log.debug("hasDeliveries(): " + address);
208:
209:                // find the entry in m_addresses
210:                List deliveries = (List) m_addresses.get(address);
211:                if (deliveries == null)
212:                    return false;
213:
214:                return (!deliveries.isEmpty());
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.