Author: manik.surtani(a)jboss.com
Date: 2008-01-21 09:17:57 -0500 (Mon, 21 Jan 2008)
New Revision: 5165
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-18
14:18:58 UTC (rev 5164)
+++
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-01-21
14:17:57 UTC (rev 5165)
@@ -77,6 +77,16 @@
}
/**
+ * Crates and adds an interceptor at the end of the chain
+ */
+ private void addInterceptor(Interceptor first, Class<? extends Interceptor>
clazz) throws IllegalAccessException, InstantiationException
+ {
+ if (first == null) return;
+ while (first.getNext() != null) first = first.getNext();
+ first.setNext(createInterceptor(clazz));
+ }
+
+ /**
* Adds an interceptor at the end of the chain
*/
private void addInterceptor(Interceptor first, Interceptor i)
@@ -88,107 +98,60 @@
private Interceptor createPessimisticInterceptorChain() throws IllegalAccessException,
InstantiationException, ClassNotFoundException
{
- Interceptor call_interceptor;
- Interceptor lock_interceptor;
- Interceptor repl_interceptor = null;
- Interceptor cache_loader_interceptor = null;
- Interceptor cache_store_interceptor = null;
- Interceptor unlock_interceptor;
- Interceptor passivation_interceptor = null;
- Interceptor activation_interceptor = null;
- Interceptor cacheMgmtInterceptor;
- Interceptor txInterceptor;
- Interceptor eviction_interceptor;
- Interceptor dataGravitatorInterceptor = null;
- Interceptor invocationCtxInterceptor =
createInterceptor(InvocationContextInterceptor.class);
- Interceptor notificationInterceptor =
createInterceptor(NotificationInterceptor.class);
- Interceptor first = null;
-
-
- call_interceptor = createInterceptor(CallInterceptor.class);
// load the icInterceptor first
- first = setFirstInterceptor(invocationCtxInterceptor);
+ Interceptor first = setFirstInterceptor(InvocationContextInterceptor.class);
+ // load the cache management interceptor next
+ if (configuration.getExposeManagementStatistics()) addInterceptor(first,
CacheMgmtInterceptor.class);
- if (isUsingBuddyReplication()) dataGravitatorInterceptor =
createInterceptor(DataGravitatorInterceptor.class);
+ // load the tx interceptor
+ addInterceptor(first, TxInterceptor.class);
- lock_interceptor = createInterceptor(PessimisticLockInterceptor.class);
+ addInterceptor(first, NotificationInterceptor.class);
- unlock_interceptor = createInterceptor(UnlockInterceptor.class);
-
- cacheMgmtInterceptor = createInterceptor(CacheMgmtInterceptor.class);
-
- txInterceptor = createInterceptor(TxInterceptor.class);
-
switch (configuration.getCacheMode())
{
case REPL_SYNC:
case REPL_ASYNC:
- repl_interceptor = createInterceptor(ReplicationInterceptor.class);
+ addInterceptor(first, ReplicationInterceptor.class);
break;
case INVALIDATION_SYNC:
case INVALIDATION_ASYNC:
- repl_interceptor = createInterceptor(InvalidationInterceptor.class);
+ addInterceptor(first, InvalidationInterceptor.class);
break;
case LOCAL:
//Nothing...
}
+ addInterceptor(first, PessimisticLockInterceptor.class);
+ addInterceptor(first, UnlockInterceptor.class);
+
if (isUsingCacheLoaders())
{
if (configuration.getCacheLoaderConfig().isPassivation())
{
- activation_interceptor = createInterceptor(ActivationInterceptor.class);
- passivation_interceptor = createInterceptor(PassivationInterceptor.class);
+ addInterceptor(first, ActivationInterceptor.class);
+ addInterceptor(first, PassivationInterceptor.class);
+
}
else
{
- cache_loader_interceptor = createInterceptor(CacheLoaderInterceptor.class);
- cache_store_interceptor = createInterceptor(CacheStoreInterceptor.class);
+ addInterceptor(first, CacheLoaderInterceptor.class);
+ addInterceptor(first, CacheStoreInterceptor.class);
+
}
}
- // load the cache management interceptor next
- if (configuration.getExposeManagementStatistics())
- {
- addInterceptor(first, cacheMgmtInterceptor);
- }
+ if (isUsingBuddyReplication()) addInterceptor(first,
DataGravitatorInterceptor.class);
- // load the tx interceptor
- addInterceptor(first, txInterceptor);
-
- addInterceptor(first, notificationInterceptor);
-
- if (repl_interceptor != null) addInterceptor(first, repl_interceptor);
-
- addInterceptor(first, lock_interceptor);
-
-
- if (unlock_interceptor != null) addInterceptor(first, unlock_interceptor);
-
- if (activation_interceptor != null)
- {
- addInterceptor(first, activation_interceptor);
- addInterceptor(first, passivation_interceptor);
- }
-
- if (cache_loader_interceptor != null)
- {
- addInterceptor(first, cache_loader_interceptor);
- addInterceptor(first, cache_store_interceptor);
- }
-
- if (dataGravitatorInterceptor != null) addInterceptor(first,
dataGravitatorInterceptor);
-
if (configuration.getEvictionConfig() != null &&
configuration.getEvictionConfig().isValidConfig())
{
- eviction_interceptor = createInterceptor(EvictionInterceptor.class);
- addInterceptor(first, eviction_interceptor);
+ addInterceptor(first, EvictionInterceptor.class);
}
- addInterceptor(first, call_interceptor);
-
- return setLastInterceptorPointer(first, call_interceptor);
+ Interceptor callInterceptor = createInterceptor(CallInterceptor.class);
+ addInterceptor(first, callInterceptor);
+ return setLastInterceptorPointer(first, callInterceptor);
}
private boolean isUsingCacheLoaders()
@@ -203,79 +166,43 @@
private Interceptor createOptimisticInterceptorChain() throws IllegalAccessException,
InstantiationException, ClassNotFoundException
{
- Interceptor txInterceptor, replicationInterceptor = null, lockInterceptor,
validationInterceptor;
- Interceptor createIfNotExistsInterceptor, nodeInterceptor, invokerInterceptor,
activationInterceptor = null;
- Interceptor passivationInterceptor = null, cacheLoaderInterceptor = null,
cacheStoreInterceptor = null, first = null;
- Interceptor cacheMgmtInterceptor, evictionInterceptor = null,
dataGravitatorInterceptor = null;
- Interceptor invocationCtxInterceptor =
createInterceptor(InvocationContextInterceptor.class);
- Interceptor notificationInterceptor =
createInterceptor(NotificationInterceptor.class);
-
// load the icInterceptor first
- first = setFirstInterceptor(invocationCtxInterceptor);
+ Interceptor first = setFirstInterceptor(InvocationContextInterceptor.class);
+ if (configuration.getExposeManagementStatistics()) addInterceptor(first,
CacheMgmtInterceptor.class);
- if (isUsingCacheLoaders())
- {
- if (configuration.getCacheLoaderConfig().isPassivation())
- {
- activationInterceptor = createInterceptor(ActivationInterceptor.class);
- passivationInterceptor = createInterceptor(PassivationInterceptor.class);
- }
- else
- {
- cacheLoaderInterceptor = createInterceptor(CacheLoaderInterceptor.class);
- cacheStoreInterceptor = createInterceptor(CacheStoreInterceptor.class);
- }
- }
+ addInterceptor(first, TxInterceptor.class);
+ addInterceptor(first, NotificationInterceptor.class);
- txInterceptor = createInterceptor(TxInterceptor.class);
-
- if (isUsingBuddyReplication()) dataGravitatorInterceptor =
createInterceptor(DataGravitatorInterceptor.class);
-
switch (configuration.getCacheMode())
{
case REPL_SYNC:
case REPL_ASYNC:
- replicationInterceptor =
createInterceptor(OptimisticReplicationInterceptor.class);
+ addInterceptor(first, OptimisticReplicationInterceptor.class);
break;
case INVALIDATION_SYNC:
case INVALIDATION_ASYNC:
- replicationInterceptor = createInterceptor(InvalidationInterceptor.class);
+ addInterceptor(first, InvalidationInterceptor.class);
break;
case LOCAL:
//Nothing...
}
- lockInterceptor = createInterceptor(OptimisticLockingInterceptor.class);
-
- validationInterceptor = createInterceptor(OptimisticValidatorInterceptor.class);
-
- createIfNotExistsInterceptor =
createInterceptor(OptimisticCreateIfNotExistsInterceptor.class);
-
- nodeInterceptor = createInterceptor(OptimisticNodeInterceptor.class);
-
- invokerInterceptor = createInterceptor(CallInterceptor.class);
-
- if (configuration.getEvictionConfig() != null &&
configuration.getEvictionConfig().isValidConfig())
+ Interceptor activationInterceptor = null, passivationInterceptor = null,
cacheLoaderInterceptor = null, cacheStoreInterceptor = null;
+ if (isUsingCacheLoaders())
{
- evictionInterceptor = createInterceptor(EvictionInterceptor.class);
+ if (configuration.getCacheLoaderConfig().isPassivation())
+ {
+ activationInterceptor = createInterceptor(ActivationInterceptor.class);
+ passivationInterceptor = createInterceptor(PassivationInterceptor.class);
+ }
+ else
+ {
+ cacheLoaderInterceptor = createInterceptor(CacheLoaderInterceptor.class);
+ cacheStoreInterceptor = createInterceptor(CacheStoreInterceptor.class);
+ }
}
- if (configuration.getExposeManagementStatistics())
- {
- cacheMgmtInterceptor = createInterceptor(CacheMgmtInterceptor.class);
- addInterceptor(first, cacheMgmtInterceptor);
- }
-
- if (txInterceptor != null)
- {
- addInterceptor(first, txInterceptor);
- }
-
- addInterceptor(first, notificationInterceptor);
-
- addInterceptor(first, replicationInterceptor);
-
if (passivationInterceptor != null &&
!configuration.getCacheLoaderConfig().isFetchPersistentState())
{
addInterceptor(first, passivationInterceptor);
@@ -308,25 +235,26 @@
}
}
- if (dataGravitatorInterceptor != null)
- {
- addInterceptor(first, dataGravitatorInterceptor);
- }
+ if (isUsingBuddyReplication()) addInterceptor(first,
DataGravitatorInterceptor.class);
+ addInterceptor(first, OptimisticLockingInterceptor.class);
- addInterceptor(first, lockInterceptor);
-
- addInterceptor(first, validationInterceptor);
- addInterceptor(first, createIfNotExistsInterceptor);
-
+ addInterceptor(first, OptimisticValidatorInterceptor.class);
+ addInterceptor(first, OptimisticCreateIfNotExistsInterceptor.class);
// eviction interceptor to come before the optimistic node interceptor
- addInterceptor(first, evictionInterceptor);
+ if (configuration.getEvictionConfig() != null &&
configuration.getEvictionConfig().isValidConfig())
+ addInterceptor(first, EvictionInterceptor.class);
- addInterceptor(first, nodeInterceptor);
+ addInterceptor(first, OptimisticNodeInterceptor.class);
- addInterceptor(first, invokerInterceptor);
+ Interceptor callInterceptor = createInterceptor(CallInterceptor.class);
+ addInterceptor(first, callInterceptor);
+ return setLastInterceptorPointer(first, callInterceptor);
+ }
- return setLastInterceptorPointer(first, invokerInterceptor);
+ public Interceptor setFirstInterceptor(Class<? extends Interceptor> clazz)
throws IllegalAccessException, InstantiationException
+ {
+ return setFirstInterceptor(createInterceptor(clazz));
}
public Interceptor setFirstInterceptor(Interceptor i)