Source Code Cross Referenced for ListenForClusterTests.java in  » Cache » OSCache » com » opensymphony » oscache » plugins » clustersupport » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.plugins.clustersupport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.oscache.plugins.clustersupport;
006:
007:        import com.opensymphony.oscache.base.Cache;
008:        import com.opensymphony.oscache.base.Config;
009:        import com.opensymphony.oscache.base.FinalizationException;
010:        import com.opensymphony.oscache.base.InitializationException;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:
015:        /**
016:         * <p>This should be used in conjunction with the cluster test cases. Run this
017:         * program to set up listeners for the various clustering implementations so
018:         * you can see that the test messages are being received correctly.</p>
019:         *
020:         * <p>A shutdown hook is installed so the listeners can be shut down cleanly.</p>
021:         *
022:         * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
023:         */
024:        public final class ListenForClusterTests {
025:            ArrayList listeners = new ArrayList();
026:            Cache cache;
027:
028:            private void mainLoop() {
029:                Thread shutdownHook = new ShutdownHookThread("");
030:                Runtime.getRuntime().addShutdownHook(shutdownHook);
031:                System.out.println();
032:                System.out
033:                        .println("------------------------------------------------");
034:                System.out
035:                        .println("Waiting for cluster messages... (CTRL-C to exit)");
036:                System.out
037:                        .println("------------------------------------------------");
038:
039:                while (true) {
040:                    try {
041:                        Thread.sleep(250);
042:                    } catch (InterruptedException ie) {
043:                    }
044:                }
045:            }
046:
047:            private void initListeners() {
048:                BaseTestBroadcastingListener testcase = null;
049:                AbstractBroadcastingListener listener;
050:                Cache cache = new Cache(true, false, false);
051:
052:                // Add the JavaGroups listener
053:                try {
054:                    testcase = new TestJavaGroupsBroadcastingListener(
055:                            "JavaGroups");
056:                    listener = testcase.getListener();
057:                    listener.initialize(cache, testcase.getConfig());
058:                    cache.addCacheEventListener(listener);
059:                    listeners.add(listener);
060:                } catch (InitializationException e) {
061:                    System.out
062:                            .println("The JavaGroups listener could not be initialized: "
063:                                    + e);
064:                }
065:
066:                // Add the JMS listener
067:                try {
068:                    testcase = new TestJMSBroadcastingListener("JMS");
069:                    listener = testcase.getListener();
070:
071:                    Config config = testcase.getConfig();
072:                    config.set("cache.cluster.jms.node.name", "cacheNode2");
073:
074:                    listener.initialize(cache, config);
075:                    cache.addCacheEventListener(listener);
076:                    listeners.add(listener);
077:                } catch (InitializationException e) {
078:                    System.out
079:                            .println("The JMS listener could not be initialized: "
080:                                    + e);
081:                }
082:            }
083:
084:            /**
085:             * Starts up the cluster listeners.
086:             */
087:            public static void main(String[] args) {
088:                ListenForClusterTests listen = new ListenForClusterTests();
089:
090:                listen.initListeners();
091:
092:                listen.mainLoop();
093:            }
094:
095:            /**
096:             * Inner class that handles the shutdown event
097:             */
098:            class ShutdownHookThread extends Thread {
099:                protected String message;
100:
101:                public ShutdownHookThread(String message) {
102:                    this .message = message;
103:                }
104:
105:                /**
106:                 * This is executed when the application is forcibly shutdown (via
107:                 * CTRL-C etc). Any configured listeners are shut down here.
108:                 */
109:                public void run() {
110:                    System.out
111:                            .println("Shutting down the cluster listeners...");
112:
113:                    for (Iterator it = listeners.iterator(); it.hasNext();) {
114:                        try {
115:                            ((AbstractBroadcastingListener) it.next())
116:                                    .finialize();
117:                        } catch (FinalizationException e) {
118:                            System.out
119:                                    .println("The listener could not be shut down cleanly: "
120:                                            + e);
121:                        }
122:                    }
123:
124:                    System.out.println("Shutdown complete.");
125:                }
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.