[jbosscache-commits] JBoss Cache SVN: r4874 - in core/trunk/src/main/java/org/jboss/cache: config and 5 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Tue Dec 18 15:45:18 EST 2007
Author: manik.surtani at jboss.com
Date: 2007-12-18 15:45:17 -0500 (Tue, 18 Dec 2007)
New Revision: 4874
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java
core/trunk/src/main/java/org/jboss/cache/util/reflect/ReflectionUtil.java
Log:
better success rates
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -45,6 +45,7 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.util.CachePrinter;
import org.jboss.cache.util.ThreadGate;
import org.jboss.cache.util.concurrent.ConcurrentHashSet;
import org.jgroups.*;
@@ -182,6 +183,7 @@
private final ComponentRegistry componentRegistry;
private NodeFactory nodeFactory;
private CacheSPI spi;
+ private Interceptor interceptorChain;
/**
* Constructs an uninitialized CacheImpl.
@@ -213,7 +215,8 @@
@Inject
private void injectDependencies(Notifier notifier, RegionManager regionManager, TransactionManager transactionManager, Marshaller marshaller,
TransactionTable transactionTable, StateTransferManager stateTransferManager, NodeFactory nodeFactory,
- CacheSPI spi, CacheMessageListener messageListener, @ComponentName("remoteDelegate")RemoteCacheInvocationDelegate remoteDelegate)
+ CacheSPI spi, CacheMessageListener messageListener, @ComponentName("remoteDelegate")RemoteCacheInvocationDelegate remoteDelegate,
+ Interceptor interceptorChain)
{
this.notifier = notifier;
this.regionManager = regionManager;
@@ -225,6 +228,7 @@
this.messageListener = messageListener;
this.remoteDelegate = remoteDelegate;
this.marshaller = marshaller;
+ this.interceptorChain = interceptorChain;
}
public Configuration getConfiguration()
@@ -634,6 +638,12 @@
// start all internal components
componentRegistry.start();
+ if (log.isInfoEnabled())
+ {
+ log.info("Interceptor chain is:\n" + CachePrinter.printInterceptorChain(interceptorChain));
+ }
+
+
correctRootNodeType();
// createTransactionManager();
@@ -3770,15 +3780,13 @@
private List<Interceptor> getInterceptors()
{
- Interceptor i = componentRegistry.getComponent(Interceptor.class);
InterceptorChainFactory icf = componentRegistry.getComponent(InterceptorChainFactory.class);
- return icf.asList(i);
+ return icf.asList(interceptorChain);
}
private void setInterceptorChain(Interceptor startOfNewChain)
{
componentRegistry.registerComponent(Interceptor.class.getName(), startOfNewChain);
- componentRegistry.updateDependencies();
}
public synchronized void addInterceptor(Interceptor i, int position)
Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -148,7 +148,19 @@
return clone;
}
+ /**
+ * Loops through all individual cache loader configs and checks if fetchPersistentState is set on any of them
+ */
+ public boolean isFetchPersistentState()
+ {
+ for (IndividualCacheLoaderConfig iclc : cacheLoaderConfigs)
+ {
+ if (iclc.isFetchPersistentState()) return true;
+ }
+ return false;
+ }
+
/**
* Configuration object that holds the confguration of an individual cache loader.
*
Modified: core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -34,9 +34,10 @@
protected transient Log log = LogFactory.getLog(getClass());
private transient CacheSPI cache; // back-reference to test whether the cache is running.
- private final Set<ConfigurationComponent> children =
- Collections.synchronizedSet(new HashSet<ConfigurationComponent>());
+ private final Set<ConfigurationComponent> children = Collections.synchronizedSet(new HashSet<ConfigurationComponent>());
private ComponentRegistry cr;
+ // a workaround to get over immutability checks
+ private boolean accessible;
protected ConfigurationComponent()
{
@@ -104,7 +105,7 @@
{
try
{
- if (cache != null && cache.getCacheStatus() != null && (cache.getCacheStatus() == CacheStatus.STARTED || cache.getCacheStatus() == CacheStatus.STARTING) && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
+ if (!accessible && cache != null && cache.getCacheStatus() != null && (cache.getCacheStatus() == CacheStatus.STARTED || cache.getCacheStatus() == CacheStatus.STARTING) && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
{
throw new ConfigurationException("Attempted to modify a non-Dynamic configuration element [" + fieldName + "] after the cache has started!");
}
@@ -113,6 +114,10 @@
{
log.warn("Field " + fieldName + " not found!!");
}
+ finally
+ {
+ accessible = false;
+ }
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -6,12 +6,10 @@
*/
package org.jboss.cache.factories;
-import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.jboss.cache.interceptors.*;
-import org.jboss.cache.loader.CacheLoaderManager;
import java.util.ArrayList;
import java.util.List;
@@ -101,12 +99,8 @@
call_interceptor = createInterceptor(CallInterceptor.class);
- //((CallInterceptor) call_interceptor).setTreeCacheInstance();
- if (componentRegistry.getOrCreateComponent(null, BuddyManager.class) != null)
- {
- dataGravitatorInterceptor = createInterceptor(DataGravitatorInterceptor.class);
- }
+ if (isUsingBuddyReplication()) dataGravitatorInterceptor = createInterceptor(DataGravitatorInterceptor.class);
lock_interceptor = createInterceptor(PessimisticLockInterceptor.class);
@@ -130,11 +124,9 @@
//Nothing...
}
- CacheLoaderManager cacheLoaderMgr = componentRegistry.getOrCreateComponent(null, CacheLoaderManager.class);
-
- if (cacheLoaderMgr != null && cacheLoaderMgr.getCacheLoader() != null)
+ if (isUsingCacheLoaders())
{
- if (cacheLoaderMgr.isPassivation())
+ if (configuration.getCacheLoaderConfig().isPassivation())
{
activation_interceptor = createInterceptor(ActivationInterceptor.class);
passivation_interceptor = createInterceptor(PassivationInterceptor.class);
@@ -285,14 +277,19 @@
addInterceptor(first, call_interceptor);
}
- if (log.isDebugEnabled())
- {
- log.debug("interceptor chain is:\n" + printInterceptorChain(first));
- }
-
return setLastInterceptorPointer(first, call_interceptor);
}
+ private boolean isUsingCacheLoaders()
+ {
+ return configuration.getCacheLoaderConfig() != null && !configuration.getCacheLoaderConfig().getIndividualCacheLoaderConfigs().isEmpty();
+ }
+
+ private boolean isUsingBuddyReplication()
+ {
+ return configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled();
+ }
+
private Interceptor createOptimisticInterceptorChain() throws IllegalAccessException, InstantiationException, ClassNotFoundException
{
Interceptor txInterceptor, replicationInterceptor = null, lockInterceptor, validationInterceptor;
@@ -302,10 +299,9 @@
Interceptor invocationCtxInterceptor = createInterceptor(InvocationContextInterceptor.class);
Interceptor notificationInterceptor = createInterceptor(NotificationInterceptor.class);
- CacheLoaderManager cacheLoaderManager = componentRegistry.getOrCreateComponent(null, CacheLoaderManager.class);
- if (cacheLoaderManager != null && cacheLoaderManager.getCacheLoader() != null)
+ if (isUsingCacheLoaders())
{
- if (cacheLoaderManager.isPassivation())
+ if (configuration.getCacheLoaderConfig().isPassivation())
{
activationInterceptor = createInterceptor(ActivationInterceptor.class);
passivationInterceptor = createInterceptor(PassivationInterceptor.class);
@@ -319,10 +315,7 @@
txInterceptor = createInterceptor(TxInterceptor.class);
- if (componentRegistry.getOrCreateComponent(null, BuddyManager.class) != null)
- {
- dataGravitatorInterceptor = createInterceptor(DataGravitatorInterceptor.class);
- }
+ if (isUsingBuddyReplication()) dataGravitatorInterceptor = createInterceptor(DataGravitatorInterceptor.class);
switch (configuration.getCacheMode())
{
@@ -394,7 +387,7 @@
addInterceptor(first, replicationInterceptor);
}
- if (passivationInterceptor != null && !cacheLoaderManager.isFetchPersistentState())
+ if (passivationInterceptor != null && !configuration.getCacheLoaderConfig().isFetchPersistentState())
{
if (first == null)
{
@@ -407,7 +400,7 @@
}
// add the cache store interceptor here
- if (cacheStoreInterceptor != null && !cacheLoaderManager.isFetchPersistentState())
+ if (cacheStoreInterceptor != null && !configuration.getCacheLoaderConfig().isFetchPersistentState())
{
if (first == null)
{
@@ -431,7 +424,7 @@
addInterceptor(first, activationInterceptor);
}
- if (cacheLoaderManager.isFetchPersistentState())
+ if (configuration.getCacheLoaderConfig().isFetchPersistentState())
{
if (first == null)
{
@@ -455,7 +448,7 @@
addInterceptor(first, cacheLoaderInterceptor);
}
- if (cacheLoaderManager.isFetchPersistentState())
+ if (configuration.getCacheLoaderConfig().isFetchPersistentState())
{
if (first == null)
{
@@ -537,28 +530,9 @@
addInterceptor(first, invokerInterceptor);
}
- if (log.isInfoEnabled())
- {
- log.info("interceptor chain is:\n" + printInterceptorChain(first));
- }
-
return setLastInterceptorPointer(first, invokerInterceptor);
}
- public String printInterceptorChain(Interceptor i)
- {
- StringBuffer sb = new StringBuffer();
- if (i != null)
- {
- if (i.getNext() != null)
- {
- sb.append(printInterceptorChain(i.getNext())).append("\n");
- }
- sb.append(i.getClass());
- }
- return sb.toString();
- }
-
public List<Interceptor> asList(Interceptor interceptor)
{
if (interceptor == null)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -38,7 +38,6 @@
/**
* Class representing an interceptor.
- * <em>Note that this will be replaced by {@link org.jboss.aop.advice.Interceptor} in one of the next releases</em>
*
* @author Bela Ban
* @version $Id$
Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -18,6 +18,7 @@
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.factories.annotations.Stop;
+import org.jboss.cache.util.reflect.ReflectionUtil;
import java.util.ArrayList;
import java.util.Iterator;
@@ -79,7 +80,7 @@
@Inject
public void setConfig(CacheLoaderConfig config, CacheSPI cache, Configuration configuration) throws CacheException
{
- this.config = config == null ? new CacheLoaderConfig() : config;
+ this.config = config == null ? configuration.getCacheLoaderConfig() : config;
this.cache = cache;
this.configuration = configuration;
@@ -159,6 +160,7 @@
}
// Update the config with those actually used by the loaders
+ ReflectionUtil.setValue(config, "accessible", true);
config.setIndividualCacheLoaderConfigs(finalConfigs);
return tmpLoader;
@@ -390,6 +392,21 @@
@Start
public void startCacheLoader() throws CacheException
{
+ if (config == null) config = configuration.getCacheLoaderConfig();
+
+ if (config != null && loader == null)
+ {
+ try
+ {
+ loader = createCacheLoader();
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to create cache loaders", e);
+ }
+ }
+
+
if (loader != null)
{
try
Modified: core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -56,4 +56,19 @@
}
return b.toString();
}
+
+ public static String printInterceptorChain(Interceptor i)
+ {
+ StringBuffer sb = new StringBuffer();
+ if (i != null)
+ {
+ if (i.getNext() != null)
+ {
+ sb.append(printInterceptorChain(i.getNext())).append("\n");
+ }
+ sb.append(">> ");
+ sb.append(i.getClass().getName());
+ }
+ return sb.toString();
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/util/reflect/ReflectionUtil.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/reflect/ReflectionUtil.java 2007-12-18 20:00:25 UTC (rev 4873)
+++ core/trunk/src/main/java/org/jboss/cache/util/reflect/ReflectionUtil.java 2007-12-18 20:45:17 UTC (rev 4874)
@@ -1,6 +1,10 @@
package org.jboss.cache.util.reflect;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
@@ -15,6 +19,8 @@
*/
public class ReflectionUtil
{
+ private static Log log = LogFactory.getLog(ReflectionUtil.class);
+
/**
* Returns a set of Methods that contain the given method annotation. This includes all public, protected, package and private
* methods, as well as those of superclasses. Note that this does *not* include overridden methods.
@@ -70,4 +76,34 @@
}
return false;
}
+
+ public static void setValue(Object instance, String fieldName, Object value)
+ {
+ try
+ {
+ Field f = findFieldRecursively(instance.getClass(), fieldName);
+ if (f == null)
+ throw new NoSuchMethodException("Cannot find field " + fieldName + " on " + instance.getClass() + " or superclasses");
+ f.setAccessible(true);
+ f.set(instance, value);
+ }
+ catch (Exception e)
+ {
+ log.error("Unable to set value!", e);
+ }
+ }
+
+ private static Field findFieldRecursively(Class c, String fieldName)
+ {
+ Field f = null;
+ try
+ {
+ f = c.getDeclaredField(fieldName);
+ }
+ catch (NoSuchFieldException e)
+ {
+ if (!c.equals(Object.class)) f = findFieldRecursively(c.getSuperclass(), fieldName);
+ }
+ return f;
+ }
}
More information about the jbosscache-commits
mailing list