| Method from org.hibernate.cache.jbc2.builder.SharedCacheInstanceManager Detail: |
protected void configureTransactionManager(Cache cache,
Settings settings,
Properties properties) {
TransactionManager tm = null;
if (settings.getTransactionManagerLookup() != null) {
tm = settings.getTransactionManagerLookup().getTransactionManager(properties);
}
Configuration cacheConfig = cache.getConfiguration();
TransactionManager cacheTm = cacheConfig.getRuntimeConfig().getTransactionManager();
if (!safeEquals(tm, cacheTm)) {
if (cache.getCacheStatus() != CacheStatus.INSTANTIATED
&& cache.getCacheStatus() != CacheStatus.DESTROYED) {
log.debug("JBoss Cache is already started with a transaction manager ("
+ cacheTm + ") that is not equal to our own (" + tm + ")");
} else {
// Configure the cache to use our TM
cacheConfig.getRuntimeConfig().setTransactionManager(tm);
if (tm == null) {
// Make sure JBC doesn't look one up
cacheConfig.setTransactionManagerLookupClass(null);
}
}
}
}
|
protected Cache createSharedCache(Settings settings,
Properties properties) {
String configResource = PropertiesHelper.getString(CACHE_RESOURCE_PROP, properties, DEFAULT_CACHE_RESOURCE);
return DefaultCacheFactory.getInstance().createCache(configResource, false);
}
Create a cache using the given settings and properties. |
public Cache getCollectionCacheInstance() {
return use2ndLevel ? cache : null;
}
|
public Cache getEntityCacheInstance() {
return use2ndLevel ? cache : null;
}
|
public Cache getQueryCacheInstance() {
if (!useQuery)
return null;
if (CacheHelper.isClusteredInvalidation(cache)) {
throw new CacheException("Query cache not supported for clustered invalidation");
}
return cache;
}
|
public Cache getTimestampsCacheInstance() {
if (!useQuery)
return null;
if (CacheHelper.isClusteredInvalidation(cache)) {
throw new CacheException("Query cache not supported for clustered invalidation");
}
return cache;
}
|
public void start(Settings settings,
Properties properties) throws CacheException {
use2ndLevel = settings.isSecondLevelCacheEnabled();
useQuery = settings.isQueryCacheEnabled();
if (cache == null) {
if (channelFactory == null) {
String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE);
if (muxStacks != null) {
channelFactory = new JChannelFactory();
try {
channelFactory.setMultiplexerConfig(muxStacks);
}
catch (Exception e) {
throw new CacheException("Problem setting ChannelFactory config", e);
}
}
}
cache = createSharedCache(settings, properties);
configureTransactionManager(cache, settings, properties);
if (cache.getConfiguration().getMultiplexerStack() != null
&& cache.getConfiguration().getRuntimeConfig().getMuxChannelFactory() == null) {
cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(channelFactory);
}
}
cache.start();
}
|
public void stop() {
if (cache != null) {
stopSharedCache(cache);
}
}
|
protected void stopSharedCache(Cache cache) {
try {
if (cache.getCacheStatus() == CacheStatus.STARTED) {
cache.stop();
}
if (cache.getCacheStatus() != CacheStatus.DESTROYED
&& cache.getCacheStatus() != CacheStatus.INSTANTIATED) {
cache.destroy();
}
} catch (Throwable t) {
log.warn("Unable to stop cache instance", t);
}
}
|