001: /*
002: * All content copyright (c) 2003-2006 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 com.tc.aspectwerkz.reflect.impl.asm.AsmClassInfo;
008: import com.tc.object.config.ConfigVisitor;
009: import com.tc.object.config.DSOClientConfigHelper;
010: import com.tc.object.config.TransparencyClassSpec;
011: import com.tc.simulator.app.ApplicationConfig;
012: import com.tc.simulator.listener.ListenerProvider;
013: import com.tc.util.Assert;
014: import com.tctest.runner.AbstractTransparentApp;
015:
016: import java.util.concurrent.CyclicBarrier;
017: import java.util.concurrent.locks.ReentrantReadWriteLock;
018: import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
019:
020: public class AddIncludeClassFromBootJarTestApp extends
021: AbstractTransparentApp {
022: private final CyclicBarrier barrier;
023: private final DataRoot dataRoot = new DataRoot();
024:
025: private final ReentrantReadWriteLock RWL = new ReentrantReadWriteLock();
026:
027: public AddIncludeClassFromBootJarTestApp(String appId,
028: ApplicationConfig cfg, ListenerProvider listenerProvider) {
029: super (appId, cfg, listenerProvider);
030: barrier = new CyclicBarrier(getParticipantCount());
031: }
032:
033: public void run() {
034: try {
035: int index = barrier.await();
036:
037: if (index == 0) {
038: WriteLock writeLock = RWL.writeLock();
039: writeLock.lock();
040: try {
041: dataRoot.setStr("test Str");
042: } finally {
043: writeLock.unlock();
044: }
045: }
046:
047: barrier.await();
048:
049: WriteLock writeLock = RWL.writeLock();
050: writeLock.lock();
051: try {
052: Assert.assertEquals("test Str", dataRoot.getStr());
053: } finally {
054: writeLock.unlock();
055: }
056: } catch (Throwable t) {
057: notifyError(t);
058: }
059: }
060:
061: public static void visitL1DSOConfig(ConfigVisitor visitor,
062: DSOClientConfigHelper config) {
063: String testClass = AddIncludeClassFromBootJarTestApp.class
064: .getName();
065: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
066:
067: config.addIncludePattern(testClass + "$*");
068:
069: String methodExpression = "* " + testClass + "*.*(..)";
070: config.addWriteAutolock(methodExpression);
071:
072: spec.addRoot("RWL", "RWL");
073: spec.addRoot("barrier", "barrier");
074: spec.addRoot("dataRoot", "dataRoot");
075:
076: // Add ReentrantReadWriteLock.WriteLock to the config again with honor transient set.
077: String className = ReentrantReadWriteLock.WriteLock.class
078: .getName();
079: config.addIncludeAndLockIfRequired(className, true, true,
080: false, "* " + className + ".*(..)", AsmClassInfo
081: .getClassInfo(className,
082: ReentrantReadWriteLock.class
083: .getClassLoader()));
084: }
085:
086: private static class DataRoot {
087: private String str;
088:
089: public DataRoot() {
090: super ();
091: }
092:
093: public void setStr(String str) {
094: this .str = str;
095: }
096:
097: public String getStr() {
098: return this.str;
099: }
100: }
101:
102: }
|