Author: manik.surtani(a)jboss.com
Date: 2008-01-21 09:26:50 -0500 (Mon, 21 Jan 2008)
New Revision: 5166
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
Log:
Simplified chain construction logic
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-01-21
14:17:57 UTC (rev 5165)
+++
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-01-21
14:26:50 UTC (rev 5166)
@@ -34,18 +34,6 @@
return new InterceptorChainFactory();
}
- public Interceptor buildInterceptorChain() throws IllegalAccessException,
ClassNotFoundException, InstantiationException
- {
- if (configuration.isNodeLockingOptimistic())
- {
- return createOptimisticInterceptorChain();
- }
- else
- {
- return createPessimisticInterceptorChain();
- }
- }
-
public static Interceptor setLastInterceptorPointer(Interceptor first, Interceptor
last)
{
Interceptor i = first;
@@ -96,8 +84,9 @@
first.setNext(i);
}
- private Interceptor createPessimisticInterceptorChain() throws IllegalAccessException,
InstantiationException, ClassNotFoundException
+ public Interceptor buildInterceptorChain() throws IllegalAccessException,
InstantiationException, ClassNotFoundException
{
+ boolean optimistic = configuration.isNodeLockingOptimistic();
// load the icInterceptor first
Interceptor first = setFirstInterceptor(InvocationContextInterceptor.class);
@@ -123,8 +112,11 @@
//Nothing...
}
- addInterceptor(first, PessimisticLockInterceptor.class);
- addInterceptor(first, UnlockInterceptor.class);
+ if (!optimistic)
+ {
+ addInterceptor(first, PessimisticLockInterceptor.class);
+ addInterceptor(first, UnlockInterceptor.class);
+ }
if (isUsingCacheLoaders())
{
@@ -144,11 +136,18 @@
if (isUsingBuddyReplication()) addInterceptor(first,
DataGravitatorInterceptor.class);
- if (configuration.getEvictionConfig() != null &&
configuration.getEvictionConfig().isValidConfig())
+ if (optimistic)
{
- addInterceptor(first, EvictionInterceptor.class);
+ addInterceptor(first, OptimisticLockingInterceptor.class);
+ addInterceptor(first, OptimisticValidatorInterceptor.class);
+ addInterceptor(first, OptimisticCreateIfNotExistsInterceptor.class);
}
+ // eviction interceptor to come before the optimistic node interceptor
+ if (configuration.getEvictionConfig() != null &&
configuration.getEvictionConfig().isValidConfig())
+ addInterceptor(first, EvictionInterceptor.class);
+ if (optimistic) addInterceptor(first, OptimisticNodeInterceptor.class);
+
Interceptor callInterceptor = createInterceptor(CallInterceptor.class);
addInterceptor(first, callInterceptor);
return setLastInterceptorPointer(first, callInterceptor);
@@ -164,94 +163,6 @@
return configuration.getBuddyReplicationConfig() != null &&
configuration.getBuddyReplicationConfig().isEnabled();
}
- private Interceptor createOptimisticInterceptorChain() throws IllegalAccessException,
InstantiationException, ClassNotFoundException
- {
- // load the icInterceptor first
- Interceptor first = setFirstInterceptor(InvocationContextInterceptor.class);
-
- if (configuration.getExposeManagementStatistics()) addInterceptor(first,
CacheMgmtInterceptor.class);
-
- addInterceptor(first, TxInterceptor.class);
- addInterceptor(first, NotificationInterceptor.class);
-
- switch (configuration.getCacheMode())
- {
- case REPL_SYNC:
- case REPL_ASYNC:
- addInterceptor(first, OptimisticReplicationInterceptor.class);
- break;
- case INVALIDATION_SYNC:
- case INVALIDATION_ASYNC:
- addInterceptor(first, InvalidationInterceptor.class);
- break;
- case LOCAL:
- //Nothing...
- }
-
- Interceptor activationInterceptor = null, passivationInterceptor = null,
cacheLoaderInterceptor = null, cacheStoreInterceptor = null;
- if (isUsingCacheLoaders())
- {
- if (configuration.getCacheLoaderConfig().isPassivation())
- {
- activationInterceptor = createInterceptor(ActivationInterceptor.class);
- passivationInterceptor = createInterceptor(PassivationInterceptor.class);
- }
- else
- {
- cacheLoaderInterceptor = createInterceptor(CacheLoaderInterceptor.class);
- cacheStoreInterceptor = createInterceptor(CacheStoreInterceptor.class);
- }
- }
-
- if (passivationInterceptor != null &&
!configuration.getCacheLoaderConfig().isFetchPersistentState())
- {
- addInterceptor(first, passivationInterceptor);
- }
-
- // add the cache store interceptor here
- if (cacheStoreInterceptor != null &&
!configuration.getCacheLoaderConfig().isFetchPersistentState())
- {
- addInterceptor(first, cacheStoreInterceptor);
- }
-
- // cache loader interceptor is only invoked if we are ready to write to the actual
tree cache
- if (activationInterceptor != null)
- {
- addInterceptor(first, activationInterceptor);
-
- if (configuration.getCacheLoaderConfig().isFetchPersistentState())
- {
- addInterceptor(first, passivationInterceptor);
- }
- }
-
- if (cacheLoaderInterceptor != null)
- {
- addInterceptor(first, cacheLoaderInterceptor);
-
- if (configuration.getCacheLoaderConfig().isFetchPersistentState())
- {
- addInterceptor(first, cacheStoreInterceptor);
- }
- }
-
- if (isUsingBuddyReplication()) addInterceptor(first,
DataGravitatorInterceptor.class);
-
- addInterceptor(first, OptimisticLockingInterceptor.class);
-
- addInterceptor(first, OptimisticValidatorInterceptor.class);
- addInterceptor(first, OptimisticCreateIfNotExistsInterceptor.class);
- // eviction interceptor to come before the optimistic node interceptor
- if (configuration.getEvictionConfig() != null &&
configuration.getEvictionConfig().isValidConfig())
- addInterceptor(first, EvictionInterceptor.class);
-
- addInterceptor(first, OptimisticNodeInterceptor.class);
-
- Interceptor callInterceptor = createInterceptor(CallInterceptor.class);
- addInterceptor(first, callInterceptor);
- return setLastInterceptorPointer(first, callInterceptor);
- }
-
public Interceptor setFirstInterceptor(Class<? extends Interceptor> clazz)
throws IllegalAccessException, InstantiationException
{
return setFirstInterceptor(createInterceptor(clazz));