Source Code Cross Referenced for ProtocolTester.java in  » Net » JGroups-2.4.1-sp3 » org » jgroups » debug » 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 » Net » JGroups 2.4.1 sp3 » org.jgroups.debug 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: ProtocolTester.java,v 1.7 2006/01/28 10:51:19 belaban Exp $
002:
003:        package org.jgroups.debug;
004:
005:        import org.apache.commons.logging.Log;
006:        import org.apache.commons.logging.LogFactory;
007:        import org.jgroups.Event;
008:        import org.jgroups.Message;
009:        import org.jgroups.stack.Configurator;
010:        import org.jgroups.stack.Protocol;
011:        import org.jgroups.stack.ProtocolStack;
012:        import org.jgroups.util.Util;
013:
014:        /**
015:         * Generic class to test one or more protocol layers directly. Sets up a protocol stack consisting of
016:         * the top layer (which is essentially given by the user and is the test harness), the specified protocol(s) and
017:         * a bottom layer (which is automatically added), which sends all received messages immediately back up the
018:         * stack (swapping sender and receiver address of the message).
019:         * 
020:         * @author Bela Ban
021:         * @author March 23 2001
022:         */
023:        public class ProtocolTester {
024:            Protocol harness = null, top, bottom;
025:            String props = null;
026:            Configurator config = null;
027:
028:            protected final Log log = LogFactory.getLog(this .getClass());
029:
030:            public ProtocolTester(String prot_spec, Protocol harness)
031:                    throws Exception {
032:                if (prot_spec == null || harness == null)
033:                    throw new Exception(
034:                            "ProtocolTester(): prot_spec or harness is null");
035:
036:                props = prot_spec;
037:                this .harness = harness;
038:                props = "LOOPBACK:" + props; // add a loopback layer at the bottom of the stack
039:
040:                config = new Configurator();
041:                ProtocolStack stack = new ProtocolStack();
042:                top = config.setupProtocolStack(props, stack);
043:                harness.setDownProtocol(top);
044:                top.setUpProtocol(harness); // +++
045:
046:                bottom = getBottomProtocol(top);
047:                config.startProtocolStack(bottom);
048:
049:                // has to be set after StartProtocolStack, otherwise the up and down handler threads in the harness
050:                // will be started as well (we don't want that) !
051:                // top.setUpProtocol(harness);
052:            }
053:
054:            public String getProtocolSpec() {
055:                return props;
056:            }
057:
058:            public void start() throws Exception {
059:                Protocol p;
060:                if (harness != null) {
061:                    p = harness;
062:                    while (p != null) {
063:                        p.start();
064:                        p = p.getDownProtocol();
065:                    }
066:                    config.startProtocolStack(harness);
067:                } else if (top != null) {
068:                    p = top;
069:                    while (p != null) {
070:                        p.start();
071:                        p = p.getDownProtocol();
072:                    }
073:                    config.startProtocolStack(top);
074:                }
075:            }
076:
077:            public void stop() {
078:                Protocol p;
079:                if (harness != null) {
080:                    p = harness;
081:                    while (p != null) {
082:                        p.stop();
083:                        p = p.getDownProtocol();
084:                    }
085:                    config.stopProtocolStack(harness);
086:                } else if (top != null) {
087:                    p = top;
088:                    while (p != null) {
089:                        p.stop();
090:                        p = p.getDownProtocol();
091:                    }
092:                    config.stopProtocolStack(top);
093:                }
094:            }
095:
096:            private final Protocol getBottomProtocol(Protocol top) {
097:                Protocol tmp;
098:
099:                if (top == null)
100:                    return null;
101:
102:                tmp = top;
103:                while (tmp.getDownProtocol() != null)
104:                    tmp = tmp.getDownProtocol();
105:                return tmp;
106:            }
107:
108:            public static void main(String[] args) {
109:                String props;
110:                ProtocolTester t;
111:                Harness h;
112:
113:                if (args.length < 1 || args.length > 2) {
114:                    System.out
115:                            .println("ProtocolTester <protocol stack spec> [-trace]");
116:                    return;
117:                }
118:                props = args[0];
119:
120:                try {
121:                    h = new Harness();
122:                    t = new ProtocolTester(props, h);
123:                    System.out.println("protocol specification is "
124:                            + t.getProtocolSpec());
125:                    h.down(new Event(Event.BECOME_SERVER));
126:                    for (int i = 0; i < 5; i++) {
127:                        System.out.println("Sending msg #" + i);
128:                        h.down(new Event(Event.MSG, new Message(null, null,
129:                                "Hello world #" + i)));
130:                    }
131:                    Util.sleep(500);
132:                    t.stop();
133:                } catch (Exception ex) {
134:                    System.err.println(ex);
135:                }
136:            }
137:
138:            private static class Harness extends Protocol {
139:
140:                public String getName() {
141:                    return "Harness";
142:                }
143:
144:                public void up(Event evt) {
145:                    System.out.println("Harness.up(): " + evt);
146:                }
147:
148:            }
149:
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.