ConfigurationFor annotation = cfg.getClass().getAnnotation(ConfigurationFor.class);
if (annotation == null) {
throw log.loaderConfigurationDoesNotSpecifyLoaderClass(cfg.getClass().getName());
}
Object instance = Util.getInstance(annotation.value());
CacheWriter writer = instance instanceof CacheWriter ? (CacheWriter) instance : null;
CacheLoader loader = instance instanceof CacheLoader ? (CacheLoader) instance : null;
if (cfg.ignoreModifications())
writer = null;
if (cfg.singletonStore().enabled() && writer != null) {
writer = (writer instanceof AdvancedCacheWriter) ?
new AdvancedSingletonCacheWriter(writer, cfg.singletonStore()) :
new SingletonCacheWriter(writer, cfg.singletonStore());
}
if (cfg.async().enabled() && writer != null) {
writer = createAsyncWriter(writer);
if (loader != null) {
AtomicReference<State> state = ((AsyncCacheWriter) writer).getState();
loader = (loader instanceof AdvancedCacheLoader) ?
new AdvancedAsyncCacheLoader(loader, state) : new AsyncCacheLoader(loader, state);
}
}
InitializationContextImpl ctx = new InitializationContextImpl(cfg, cache, m, timeService, byteBufferFactory,
marshalledEntryFactory);
if (loader != null) {
if (loader instanceof DelegatingCacheLoader)
loader.init(ctx);
loaders.add(loader);
configMap.put(loader, cfg);
}
if (writer != null) {
if (writer instanceof DelegatingCacheWriter)
writer.init(ctx);
writers.add(writer);
configMap.put(writer, cfg);
}
//the delegates only propagate init if the underlaying object is a delegate as well.