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;
}
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));
}
}
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);
}
}
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);
}
}
}
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;
}
Aggregations