configuration.getTransactionLockingMode() == LockingMode.OPTIMISTIC && configuration.isEnableVersioning();
boolean invocationBatching = configuration.isInvocationBatchingEnabled();
// load the icInterceptor first
CommandInterceptor first;
if (invocationBatching) {
first = createInterceptor(BatchingInterceptor.class);
} else {
first = createInterceptor(InvocationContextInterceptor.class);
}
InterceptorChain interceptorChain = new InterceptorChain(first);
// add the interceptor chain to the registry first, since some interceptors may ask for it.
componentRegistry.registerComponent(interceptorChain, InterceptorChain.class);
// add marshallable check interceptor for situations where we want to figure out before marshalling
if (isUsingMarshalledValues(configuration) || configuration.isUseAsyncMarshalling()
|| configuration.isUseReplQueue() || hasAsyncStore())
interceptorChain.appendInterceptor(createInterceptor(IsMarshallableInterceptor.class));
// NOW add the ICI if we are using batching!
if (invocationBatching) {
interceptorChain.appendInterceptor(createInterceptor(InvocationContextInterceptor.class));
}
// load the cache management interceptor next
if (configuration.isExposeJmxStatistics())
interceptorChain.appendInterceptor(createInterceptor(CacheMgmtInterceptor.class));
// load the state transfer lock interceptor
// the state transfer lock ensures that the cache member list is up-to-date
// so it's necessary even if state transfer is disabled
if (configuration.getCacheMode().isDistributed() || configuration.getCacheMode().isReplicated())
interceptorChain.appendInterceptor(createInterceptor(StateTransferLockInterceptor.class));
// load the tx interceptor
if (configuration.isTransactionalCache()) {
if (configuration.getCacheMode().isDistributed())
interceptorChain.appendInterceptor(createInterceptor(DistTxInterceptor.class));
else
interceptorChain.appendInterceptor(createInterceptor(TxInterceptor.class));
}
if (isUsingMarshalledValues(configuration))
interceptorChain.appendInterceptor(createInterceptor(MarshalledValueInterceptor.class));
interceptorChain.appendInterceptor(createInterceptor(NotificationInterceptor.class));
if (configuration.isUseEagerLocking()) {
configuration.fluent().transaction().lockingMode(LockingMode.PESSIMISTIC);
}
if (configuration.isTransactionalCache()) {
if (configuration.getTransactionLockingMode() == LockingMode.PESSIMISTIC) {
interceptorChain.appendInterceptor(createInterceptor(PessimisticLockingInterceptor.class));
} else {
interceptorChain.appendInterceptor(createInterceptor(OptimisticLockingInterceptor.class));
}
} else {
interceptorChain.appendInterceptor(createInterceptor(NonTransactionalLockingInterceptor.class));
}
if (needsVersionAwareComponents && configuration.getCacheMode().isClustered())
interceptorChain.appendInterceptor(createInterceptor(VersionedEntryWrappingInterceptor.class));
else
interceptorChain.appendInterceptor(createInterceptor(EntryWrappingInterceptor.class));
if (configuration.isUsingCacheLoaders()) {
if (configuration.getCacheLoaderManagerConfig().isPassivation()) {
interceptorChain.appendInterceptor(createInterceptor(ActivationInterceptor.class));
interceptorChain.appendInterceptor(createInterceptor(PassivationInterceptor.class));
} else {
interceptorChain.appendInterceptor(createInterceptor(CacheLoaderInterceptor.class));
switch (configuration.getCacheMode()) {
case DIST_SYNC:
case DIST_ASYNC:
interceptorChain.appendInterceptor(createInterceptor(DistCacheStoreInterceptor.class));
break;
default:
interceptorChain.appendInterceptor(createInterceptor(CacheStoreInterceptor.class));
break;
}
}
}
if (configuration.isEnableDeadlockDetection()) {
interceptorChain.appendInterceptor(createInterceptor(DeadlockDetectingInterceptor.class));
}
switch (configuration.getCacheMode()) {
case REPL_SYNC:
if (needsVersionAwareComponents) {
interceptorChain.appendInterceptor(createInterceptor(VersionedReplicationInterceptor.class));
break;
}
case REPL_ASYNC:
interceptorChain.appendInterceptor(createInterceptor(ReplicationInterceptor.class));
break;
case INVALIDATION_SYNC:
case INVALIDATION_ASYNC:
interceptorChain.appendInterceptor(createInterceptor(InvalidationInterceptor.class));
break;
case DIST_SYNC:
if (needsVersionAwareComponents) {
interceptorChain.appendInterceptor(createInterceptor(VersionedDistributionInterceptor.class));
break;
}
case DIST_ASYNC:
interceptorChain.appendInterceptor(createInterceptor(DistributionInterceptor.class));
break;
case LOCAL:
//Nothing...
}
CommandInterceptor callInterceptor = createInterceptor(CallInterceptor.class);
interceptorChain.appendInterceptor(callInterceptor);
if (log.isTraceEnabled()) log.trace("Finished building default interceptor chain.");
buildCustomInterceptors(interceptorChain, configuration.getCustomInterceptors());
return interceptorChain;
}