001: package org.terracotta.modules.ehcache.commons_1_0;
002:
003: import org.osgi.framework.Bundle;
004: import org.osgi.framework.BundleContext;
005: import org.terracotta.modules.configuration.TerracottaConfiguratorModule;
006:
007: import com.tc.object.bytecode.ClassAdapterFactory;
008: import com.tc.object.config.ConfigLockLevel;
009: import com.tc.object.config.TransparencyClassSpec;
010:
011: public abstract class EhcacheTerracottaCommonsConfigurator extends
012: TerracottaConfiguratorModule implements IConstants {
013:
014: protected void addInstrumentation(final BundleContext context) {
015: super .addInstrumentation(context);
016:
017: // find the bundle that contains the replacement classes
018: Bundle bundle = getExportedBundle(context,
019: getExportedBundleName());
020: Bundle this Bundle = getExportedBundle(context,
021: COMMON_EHCACHE_BUNDLE_NAME);
022: if (null == bundle) {
023: throw new RuntimeException(
024: "Couldn't find bundle with symbolic name '"
025: + getExportedBundleName()
026: + "' during the instrumentation configuration of the bundle '"
027: + context.getBundle().getSymbolicName()
028: + "'.");
029: }
030:
031: // setup the replacement classes
032: addClassReplacement(bundle, CACHE_CLASS_NAME_DOTS,
033: CACHETC_CLASS_NAME_DOTS);
034: addClassReplacement(bundle,
035: MEMORYSTOREEVICTIONPOLICY_CLASS_NAME_DOTS,
036: MEMORYSTOREEVICTIONPOLICYTC_CLASS_NAME_DOTS);
037:
038: // setup the class resources
039: addExportedBundleClass(this Bundle,
040: "net.sf.ehcache.store.TimeExpiryMemoryStore");
041: addExportedBundleClass(this Bundle,
042: "net.sf.ehcache.store.TimeExpiryMemoryStore$SpoolingTimeExpiryMap");
043: addExportedBundleClass(this Bundle,
044: "org.terracotta.modules.ehcache.commons_1_0.util.Util");
045: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap");
046: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap$EntriesIterator");
047: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap$EntrySetWrapper");
048: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap$EntryWrapper");
049: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap$KeySetWrapper");
050: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap$KeysIterator");
051: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap$ValuesCollectionWrapper");
052: addExportedTcJarClass("com.tcclient.ehcache.TimeExpiryMap$ValuesIterator");
053: addExportedTcJarClass("com.tcclient.cache.CacheConfig");
054: addExportedTcJarClass("com.tcclient.cache.CacheData");
055: addExportedTcJarClass("com.tcclient.cache.CacheDataStore");
056: addExportedTcJarClass("com.tcclient.cache.CacheEntryInvalidator");
057: addExportedTcJarClass("com.tcclient.cache.CacheInvalidationTimer");
058: addExportedTcJarClass("com.tcclient.cache.CacheInvalidationTimer$EvictionRunner");
059: addExportedTcJarClass("com.tcclient.cache.Expirable");
060: addExportedTcJarClass("com.tcclient.cache.Lock");
061: addExportedTcJarClass("com.tcclient.cache.Timestamp");
062: addExportedTcJarClass("com.tcclient.cache.GlobalKeySet");
063: addExportedTcJarClass("com.tc.util.Util");
064:
065: // explicitly excluding autolocking
066: configHelper
067: .addAutoLockExcludePattern("* com.tcclient.cache.CacheData.*(..)");
068: configHelper
069: .addAutoLockExcludePattern("* com.tcclient.cache.CacheDataStore.*(..)");
070: configHelper
071: .addAutoLockExcludePattern("* com.tcclient.cache.Lock.*(..)");
072: configHelper
073: .addAutoLockExcludePattern("* com.tcclient.cache.Timestamp.*(..)");
074: configHelper
075: .addAutoLockExcludePattern("* com.tcclient.ehcache..*(..)");
076: configHelper
077: .addAutoLockExcludePattern("* net.sf.ehcache.store.TimeExpiryMemoryStore.*(..)");
078: configHelper
079: .addAutoLockExcludePattern("* net.sf.ehcache.store.TimeExpiryMemoryStore$SpoolingTimeExpiryMap.*(..)");
080: configHelper
081: .addAutoLockExcludePattern("* net.sf.ehcache.Cache.*(..)");
082: configHelper
083: .addAutoLockExcludePattern("* net.sf.ehcache.Ehcache.*(..)");
084: configHelper
085: .addAutoLockExcludePattern("* net.sf.ehcache.Statistics.*(..)");
086: configHelper
087: .addAutoLockExcludePattern("* net.sf.ehcache.Status.*(..)");
088: configHelper
089: .addAutoLockExcludePattern("* net.sf.ehcache.bootstrap.*..*(..)");
090: configHelper
091: .addAutoLockExcludePattern("* net.sf.ehcache.config.*..*(..)");
092: configHelper
093: .addAutoLockExcludePattern("* net.sf.ehcache.constructs.asynchronous.*.*(..)");
094: configHelper
095: .addAutoLockExcludePattern("* net.sf.ehcache.constructs.blocking.*.*(..)");
096: configHelper
097: .addAutoLockExcludePattern("* net.sf.ehcache.constructs.concurrent.ConcurrencyUtil.*(..)");
098: configHelper
099: .addAutoLockExcludePattern("* net.sf.ehcache.constructs.concurrent.Sync.*(..)");
100: configHelper
101: .addAutoLockExcludePattern("* net.sf.ehcache.distribution.*..*(..)");
102: configHelper
103: .addAutoLockExcludePattern("* net.sf.ehcache.event.*..*(..)");
104: configHelper
105: .addAutoLockExcludePattern("* net.sf.ehcache.hibernate.*..*(..)");
106: configHelper
107: .addAutoLockExcludePattern("* net.sf.ehcache.jcache.*..*(..)");
108: configHelper
109: .addAutoLockExcludePattern("* net.sf.ehcache.management.*..*(..)");
110: configHelper
111: .addAutoLockExcludePattern("* net.sf.ehcache.store.*..*(..)");
112: configHelper
113: .addAutoLockExcludePattern("* net.sf.ehcache.util.*..*(..)");
114:
115: configHelper
116: .addAutolock(
117: "* net.sf.ehcache.constructs.concurrent.Mutex.acquire(..)",
118: ConfigLockLevel.WRITE);
119: configHelper
120: .addAutolock(
121: "* net.sf.ehcache.constructs.concurrent.Mutex.attempt(..)",
122: ConfigLockLevel.WRITE);
123: configHelper
124: .addAutolock(
125: "* net.sf.ehcache.constructs.concurrent.Mutex.release(..)",
126: ConfigLockLevel.WRITE);
127:
128: // perform the rest of the configuration
129: configHelper.addIncludePattern("com.tcclient.cache.*", false,
130: false, false);
131: configHelper.addIncludePattern("com.tcclient.ehcache.*", false,
132: false, false);
133: TransparencyClassSpec spec = configHelper
134: .getOrCreateSpec("com.tcclient.cache.CacheDataStore");
135: spec.setHonorTransient(true);
136: spec.setCallMethodOnLoad("initialize");
137: spec.addDistributedMethodCall("stopInvalidatorThread", "()V",
138: false);
139: spec = configHelper
140: .getOrCreateSpec("com.tcclient.cache.CacheData");
141: spec.setCallConstructorOnLoad(true);
142: spec.setHonorTransient(true);
143:
144: ClassAdapterFactory factory = new EhcacheMemoryStoreAdapter();
145: spec = configHelper
146: .getOrCreateSpec(MEMORYSTORE_CLASS_NAME_DOTS);
147: spec.setCustomClassAdapter(factory);
148:
149: // autolocking
150: configHelper.addAutolock(
151: " * com.tcclient.cache.GlobalKeySet.*(..)",
152: ConfigLockLevel.WRITE);
153: }
154:
155: protected abstract String getExportedBundleName();
156: }
|