Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
*/
package com.maxifier.mxcache.clean;
import com.maxifier.mxcache.Cached;
import com.maxifier.mxcache.NonInstrumentedCacheException;
import com.maxifier.mxcache.caches.Cache;
import com.maxifier.mxcache.caches.CleaningNode;
import com.maxifier.mxcache.impl.resource.AbstractDependencyNode;
import com.maxifier.mxcache.impl.resource.DependencyNode;
import com.maxifier.mxcache.impl.resource.DependencyTracker;
import com.maxifier.mxcache.provider.CacheDescriptor;
import gnu.trove.map.hash.THashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*;
/**
* CleanableRegister - this class maintains a list of Cleanable and cache instances.
* It's a single access point to all cache cleaning operations.
*
* @author Andrey Yakoushin ([email protected])
* @author Alexander Kochurov ([email protected])
*/
public final class CleanableRegister implements CacheCleaner {
private static final Logger logger = LoggerFactory.getLogger(CleanableRegister.class);
private final Map, ClassCleanableInstanceList> classCleanMap = new THashMap, ClassCleanableInstanceList>();
/**
* For each class there are two DependencyNodes: one for static methods and one for its instance methods.
*
* Instance method node depends on static node and on instance nodes of parent classes and interfaces.
*
* So it's enough to invalidate static node to invalidate all static caches of cache, instance caches of this
* class and all instance caches of its child classes too. This is what {@link #clearCacheByClass(Class)} does.
*/
private final Map, DependencyNode> classStaticNodes = new THashMap, DependencyNode>();
private final Map, DependencyNode> classInstanceNodes = new THashMap, DependencyNode>();
private final Map groupNodes = new THashMap();
private final Map tagNodes = new THashMap();
private static final Cleanable EMPTY_CLEANABLE = new EmptyCleanable();
//---- Methods called from static initializer of classes generated with MxCache instrumentator ---------------------
/**
* Called from generated class registration method
* @param clazz registered class
* @param cleanable cleaner for this class
* @param groups cache id by group mapping
* @param tags cache id by tag mapping
* @param type of class
*/
public synchronized void registerClass(Class clazz, Cleanable cleanable, @Nullable Map groups, @Nullable Map tags) {
if (clazz.isInterface()) {
throw new IllegalArgumentException("Interface could not have cached methods!");
}
ClassCleanableInstanceList superClassList = getClassList(clazz.getSuperclass());
//noinspection unchecked
ClassCleanableInstanceList instanceList = new ClassCleanableInstanceList(superClassList, cleanable, groups, tags, clazz);
ClassCleanableInstanceList oldValue = classCleanMap.put(clazz, instanceList);
if (oldValue != null) {
throw new IllegalStateException(clazz + " already registered");
}
}
@SuppressWarnings({ "unchecked" })
private synchronized ClassCleanableInstanceList