Source Code Cross Referenced for OpenAjaxSynchronizer.java in  » Ajax » dwr » org » directwebremoting » proxy » openajax » 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 » Ajax » dwr » org.directwebremoting.proxy.openajax 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.directwebremoting.proxy.openajax;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:
006:        import org.directwebremoting.Container;
007:        import org.directwebremoting.ScriptSession;
008:        import org.directwebremoting.WebContext;
009:        import org.directwebremoting.WebContextFactory;
010:        import org.directwebremoting.event.ScriptSessionEvent;
011:        import org.directwebremoting.event.ScriptSessionListener;
012:        import org.directwebremoting.extend.ScriptSessionManager;
013:
014:        /**
015:         * This class is designed for export by DWR to enable the OpenAjax hub to
016:         * exchange publish/subscribe data with the server.
017:         * @author Joe Walker [joe at getahead dot ltd dot uk]
018:         */
019:        public class OpenAjaxSynchronizer {
020:            /**
021:             * 
022:             */
023:            public OpenAjaxSynchronizer() {
024:                Container container = WebContextFactory.get().getContainer();
025:
026:                ScriptSessionManager scriptSessionManager = (ScriptSessionManager) container
027:                        .getBean(ScriptSessionManager.class.getName());
028:                scriptSessionManager
029:                        .addScriptSessionListener(new CustomScriptSessionListener());
030:
031:                pubSubHub = (PubSubHub) container.getBean(PubSubHub.class
032:                        .getName());
033:                pubSubHub.subscribe(PubSubHub.ANY_PREFIX, PubSubHub.ANY_NAME,
034:                        new OpenAjaxSynchronizingPublishListener(this ));
035:                pubSubHub
036:                        .addSubscriptionListener(new OpenAjaxSynchronizingSubscriptionListener(
037:                                this ));
038:            }
039:
040:            /**
041:             * Called by clients that wish to be included in the whole hub sync thing.
042:             */
043:            public void enroll() {
044:                WebContext webContext = WebContextFactory.get();
045:                ScriptSession scriptSession = webContext.getScriptSession();
046:                synchronized (enrolledScriptSessions) {
047:                    enrolledScriptSessions.add(scriptSession);
048:                }
049:            }
050:
051:            /**
052:             * This method allows the client side hub synchronizer to forward publish
053:             * messages to the server hub
054:             * @param prefix The prefix that was published to
055:             * @param name The name that was published to
056:             * @param data The published data
057:             * @param hubsVisited The list of hubs that this message has been through
058:             */
059:            public void publish(String prefix, String name, String data,
060:                    List<String> hubsVisited) {
061:                WebContext webContext = WebContextFactory.get();
062:
063:                String httpSessionId = webContext.getSession(true).getId();
064:                String scriptSessionId = webContext.getScriptSession().getId();
065:
066:                pubSubHub.publish(httpSessionId, scriptSessionId, prefix, name,
067:                        data, hubsVisited);
068:            }
069:
070:            /**
071:             * Get a list of the {@link ScriptSession}s that are part of this
072:             * distributed hub. 
073:             * @return The current list of known enrolled {@link ScriptSession}s
074:             */
075:            protected List<ScriptSession> getEnrolledScriptSessions() {
076:                List<ScriptSession> reply = new ArrayList<ScriptSession>();
077:                synchronized (enrolledScriptSessions) {
078:                    reply.addAll(enrolledScriptSessions);
079:                }
080:                return reply;
081:            }
082:
083:            /**
084:             * The current server side hub
085:             */
086:            private PubSubHub pubSubHub;
087:
088:            /**
089:             * The current list of known enrolled {@link ScriptSession}s
090:             */
091:            protected List<ScriptSession> enrolledScriptSessions = new ArrayList<ScriptSession>();
092:
093:            /**
094:             * We need to know when pages go away so we don't keep publishing changes
095:             * to them.
096:             */
097:            protected final class CustomScriptSessionListener implements 
098:                    ScriptSessionListener {
099:                /* (non-Javadoc)
100:                 * @see org.directwebremoting.event.ScriptSessionListener#sessionCreated(org.directwebremoting.event.ScriptSessionEvent)
101:                 */
102:                public void sessionCreated(ScriptSessionEvent ev) {
103:                    // The creation of a ScriptSession is not important, because they
104:                    // might not enroll. We care about the enrolled ones that have gone
105:                    // away.
106:                }
107:
108:                /* (non-Javadoc)
109:                 * @see org.directwebremoting.event.ScriptSessionListener#sessionDestroyed(org.directwebremoting.event.ScriptSessionEvent)
110:                 */
111:                public void sessionDestroyed(ScriptSessionEvent ev) {
112:                    ScriptSession scriptSession = ev.getSession();
113:                    synchronized (enrolledScriptSessions) {
114:                        enrolledScriptSessions.add(scriptSession);
115:                    }
116:                }
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.