Source Code Cross Referenced for CustomClassAdapterTestApp.java in  » Net » Terracotta » com » tctest » 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 » Terracotta » com.tctest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tctest;
006:
007:        import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
008:
009:        import com.tc.asm.ClassAdapter;
010:        import com.tc.asm.ClassVisitor;
011:        import com.tc.asm.MethodVisitor;
012:        import com.tc.asm.Opcodes;
013:        import com.tc.exception.TCNonPortableObjectError;
014:        import com.tc.object.bytecode.ClassAdapterFactory;
015:        import com.tc.object.config.ConfigVisitor;
016:        import com.tc.object.config.DSOClientConfigHelper;
017:        import com.tc.object.config.TransparencyClassSpec;
018:        import com.tc.object.config.spec.CyclicBarrierSpec;
019:        import com.tc.simulator.app.ApplicationConfig;
020:        import com.tc.simulator.listener.ListenerProvider;
021:        import com.tc.util.Assert;
022:        import com.tctest.runner.AbstractErrorCatchingTransparentApp;
023:
024:        import java.util.HashMap;
025:        import java.util.Map;
026:
027:        /**
028:         * Test to make sure custom adapted class and its inherited classes can be shared under DSO
029:         *
030:         * @author hhuynh
031:         */
032:        public class CustomClassAdapterTestApp extends
033:                AbstractErrorCatchingTransparentApp {
034:            private Map root = new HashMap();
035:            private CyclicBarrier barrier;
036:
037:            public CustomClassAdapterTestApp(String appId,
038:                    ApplicationConfig cfg, ListenerProvider listenerProvider) {
039:                super (appId, cfg, listenerProvider);
040:                barrier = new CyclicBarrier(getParticipantCount());
041:            }
042:
043:            protected void runTest() throws Throwable {
044:                Foo foo = new Foo();
045:                Assert.assertEquals(-1, foo.getVal());
046:                Assert.assertEquals(0, foo.getRealVal());
047:                foo.setVal(100);
048:                Assert.assertEquals(-1, foo.getVal());
049:                Assert.assertEquals(100, foo.getRealVal());
050:
051:                FooKid fooKid = new FooKid();
052:                fooKid.setVal(100);
053:                Assert.assertEquals(-1, fooKid.getVal());
054:                Assert.assertEquals(-2, fooKid.getDoubleVal());
055:
056:                if (barrier.barrier() == 0) {
057:                    synchronized (root) {
058:                        foo.setVal(200);
059:                        fooKid.setVal(200);
060:                        root.put("foo", foo);
061:                        root.put("fooKid", fooKid);
062:                    }
063:                }
064:
065:                barrier.barrier();
066:                Foo sharedFoo = (Foo) root.get("foo");
067:                Assert.assertEquals(-1, foo.getVal());
068:                Assert.assertEquals(200, sharedFoo.getRealVal());
069:
070:                FooKid sharedFooKid = (FooKid) root.get("fooKid");
071:                Assert.assertEquals(-1, fooKid.getVal());
072:                Assert.assertEquals(-2, sharedFooKid.getDoubleVal());
073:
074:                // also make sure a class that happens to have a custom adapter isn't also
075:                // portable (ie. it must be included to be portable)
076:                AdaptedButNotIncluded a = new AdaptedButNotIncluded();
077:                Assert.assertEquals(-1, a.getVal()); // tests that adaption did happen
078:                try {
079:                    synchronized (root) {
080:                        root.put("test", new AdaptedButNotIncluded());
081:                    }
082:                    throw new AssertionError("Type is portable");
083:                } catch (TCNonPortableObjectError e) {
084:                    // expected
085:                }
086:            }
087:
088:            public static void visitL1DSOConfig(ConfigVisitor visitor,
089:                    DSOClientConfigHelper config) {
090:                CyclicBarrierSpec cbspec = new CyclicBarrierSpec();
091:                cbspec.visit(visitor, config);
092:
093:                String testClass = CustomClassAdapterTestApp.class.getName();
094:                TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
095:
096:                String methodExpression = "* " + testClass + "*.*(..)";
097:                config.addWriteAutolock(methodExpression);
098:                spec.addRoot("root", "root");
099:                spec.addRoot("barrier", "barrier");
100:
101:                config.addIncludePattern(Foo.class.getName());
102:                config.addIncludePattern(FooKid.class.getName());
103:                config.addCustomAdapter(Foo.class.getName(),
104:                        new GetValAdapter());
105:
106:                config.addCustomAdapter(AdaptedButNotIncluded.class.getName(),
107:                        new GetValAdapter());
108:            }
109:
110:        }
111:
112:        class AdaptedButNotIncluded {
113:            private int val;
114:
115:            public int getVal() {
116:                return val;
117:            }
118:        }
119:
120:        class Foo {
121:            private int val;
122:
123:            public int getVal() {
124:                return val;
125:            }
126:
127:            public void setVal(int val) {
128:                this .val = val;
129:            }
130:
131:            public int getRealVal() {
132:                return val;
133:            }
134:        }
135:
136:        class FooKid extends Foo {
137:            public int getDoubleVal() {
138:                return getVal() * 2;
139:            }
140:        }
141:
142:        class GetValAdapter extends ClassAdapter implements  Opcodes,
143:                ClassAdapterFactory {
144:
145:            public GetValAdapter() {
146:                super (null);
147:            }
148:
149:            public GetValAdapter(ClassVisitor cv) {
150:                super (cv);
151:            }
152:
153:            public GetValAdapter(ClassVisitor visitor, ClassLoader loader) {
154:                super (visitor);
155:            }
156:
157:            public MethodVisitor visitMethod(final int access,
158:                    final String name, final String desc,
159:                    final String signature, final String[] exceptions) {
160:                if ("getVal".equals(name)) {
161:                    MethodVisitor mv = super .visitMethod(ACC_PUBLIC, "getVal",
162:                            "()I", null, null);
163:                    mv.visitCode();
164:                    mv.visitInsn(ICONST_M1);
165:                    mv.visitInsn(IRETURN);
166:                    mv.visitMaxs(0, 0);
167:                    mv.visitEnd();
168:                    return null;
169:                }
170:                return cv
171:                        .visitMethod(access, name, desc, signature, exceptions);
172:            }
173:
174:            public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
175:                return new GetValAdapter(visitor, loader);
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.