Search in sources :

Example 1 with ClusterTestCacheWrapperKey

use of com.pamirs.pradar.cache.ClusterTestCacheWrapperKey in project LinkAgent by shulieTech.

the class CacheGetKeysInterceptor method getResult0.

@Override
protected Object getResult0(Advice advice) {
    Object result = advice.getReturnObj();
    if (!(result instanceof List)) {
        return result;
    }
    List keys = (List) result;
    List list = new ArrayList();
    boolean replace = false;
    for (Object key : keys) {
        if (key instanceof ClusterTestCacheWrapperKey) {
            list.add(((ClusterTestCacheWrapperKey) key).getKey());
            replace = true;
        } else {
            list.add(key);
        }
    }
    if (replace) {
        return list;
    }
    return result;
}
Also used : ClusterTestCacheWrapperKey(com.pamirs.pradar.cache.ClusterTestCacheWrapperKey) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with ClusterTestCacheWrapperKey

use of com.pamirs.pradar.cache.ClusterTestCacheWrapperKey in project LinkAgent by shulieTech.

the class CacheKeyInterceptor1 method doBefore.

@Override
public void doBefore(Advice advice) throws Throwable {
    if (!Pradar.isClusterTest()) {
        return;
    }
    Object[] args = advice.getParameterArray();
    if (ArrayUtils.isEmpty(args)) {
        return;
    }
    Object key = advice.getParameterArray()[0];
    if (!(key instanceof ClusterTestCacheWrapperKey)) {
        advice.changeParameter(0, new ClusterTestCacheWrapperKey(key));
    }
}
Also used : ClusterTestCacheWrapperKey(com.pamirs.pradar.cache.ClusterTestCacheWrapperKey)

Example 3 with ClusterTestCacheWrapperKey

use of com.pamirs.pradar.cache.ClusterTestCacheWrapperKey in project LinkAgent by shulieTech.

the class CacheGetAllRemoveAllInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    Object result = advice.getReturnObj();
    if (!(result instanceof Map)) {
        return;
    }
    Map map = (Map) advice.getReturnObj();
    Map resultMap = new HashMap();
    Set<Map.Entry> set = map.entrySet();
    boolean replace = false;
    for (Map.Entry entry : set) {
        Object key = entry.getKey();
        if (key instanceof ClusterTestCacheWrapperKey) {
            key = ((ClusterTestCacheWrapperKey) key).getKey();
            replace = true;
        }
        Object value = entry.getValue();
        if (value instanceof Element) {
            Element element = (Element) value;
            if (element.getObjectKey() instanceof ClusterTestCacheWrapperKey) {
                value = new Element(((ClusterTestCacheWrapperKey) element.getObjectKey()).getKey(), element.getObjectValue(), element.getVersion(), element.getCreationTime(), element.getLastAccessTime(), element.getHitCount(), element.usesCacheDefaultLifespan(), element.getTimeToLive(), element.getTimeToIdle(), element.getLastUpdateTime());
                replace = true;
            }
        }
        resultMap.put(key, value);
    }
    if (replace) {
        ProcessController.returnImmediately(advice.getBehavior().getReturnType(), resultMap);
    }
}
Also used : ClusterTestCacheWrapperKey(com.pamirs.pradar.cache.ClusterTestCacheWrapperKey) Element(net.sf.ehcache.Element)

Example 4 with ClusterTestCacheWrapperKey

use of com.pamirs.pradar.cache.ClusterTestCacheWrapperKey in project LinkAgent by shulieTech.

the class CacheGetAllRemoveAllInterceptor method doBefore.

@Override
public void doBefore(Advice advice) throws Throwable {
    if (!Pradar.isClusterTest()) {
        return;
    }
    Object[] args = advice.getParameterArray();
    if (ArrayUtils.isEmpty(args)) {
        return;
    }
    if (args[0] instanceof Set) {
        Set argsSet = (Set) args[0];
        Set set = buildSet(argsSet);
        boolean replace = false;
        for (Object key : argsSet) {
            if (key instanceof ClusterTestCacheWrapperKey) {
                set.add(key);
            } else {
                ClusterTestCacheWrapperKey clusterTestCacheWrapperKey = new ClusterTestCacheWrapperKey(key);
                set.add(clusterTestCacheWrapperKey);
                replace = true;
            }
        }
        if (replace) {
            advice.changeParameter(0, set);
        }
    } else if (args[0] instanceof Collection) {
        Collection coll = (Collection) args[0];
        List list = new ArrayList();
        boolean replace = false;
        for (Object key : coll) {
            if (key instanceof ClusterTestCacheWrapperKey) {
                list.add(key);
            } else {
                ClusterTestCacheWrapperKey clusterTestCacheWrapperKey = new ClusterTestCacheWrapperKey(key);
                list.add(clusterTestCacheWrapperKey);
                replace = true;
            }
        }
        if (replace) {
            advice.changeParameter(0, list);
        }
    }
}
Also used : CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ClusterTestCacheWrapperKey(com.pamirs.pradar.cache.ClusterTestCacheWrapperKey)

Example 5 with ClusterTestCacheWrapperKey

use of com.pamirs.pradar.cache.ClusterTestCacheWrapperKey in project LinkAgent by shulieTech.

the class CachePutAllInterceptor method getParameter0.

@Override
protected Object[] getParameter0(Advice advice) throws Throwable {
    if (!Pradar.isClusterTest()) {
        return advice.getParameterArray();
    }
    Object[] args = advice.getParameterArray();
    if (ArrayUtils.isEmpty(args)) {
        return args;
    }
    if (!(args[0] instanceof Map)) {
        return args;
    }
    Map oldArg = (Map) args[0];
    Map map = buildMap(oldArg);
    boolean replace = false;
    Set<Map.Entry> entrySet = oldArg.entrySet();
    for (Map.Entry entry : entrySet) {
        if (entry.getKey() instanceof ClusterTestCacheWrapperKey) {
            map.put(entry.getKey(), entry.getValue());
        } else {
            ClusterTestCacheWrapperKey clusterTestCacheWrapperKey = new ClusterTestCacheWrapperKey(entry.getKey());
            map.put(clusterTestCacheWrapperKey, entry.getValue());
            replace = true;
        }
    }
    if (replace) {
        args[0] = map;
    }
    return args;
}
Also used : ClusterTestCacheWrapperKey(com.pamirs.pradar.cache.ClusterTestCacheWrapperKey) TreeMap(java.util.TreeMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

ClusterTestCacheWrapperKey (com.pamirs.pradar.cache.ClusterTestCacheWrapperKey)26 Element (net.sf.ehcache.Element)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 WrapEntry (com.pamirs.attach.plugin.caffeine.utils.WrapEntry)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1