mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-07 16:03:10 +00:00
@@ -17,6 +17,7 @@
|
||||
package com.l2jserver.service.cache;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Arrays;
|
||||
@@ -75,12 +76,21 @@ public class EhCacheService extends AbstractService implements CacheService {
|
||||
return method.invoke(instance, args);
|
||||
final MethodInvocation invocation = new MethodInvocation(
|
||||
method, args);
|
||||
Object result = interfaceCache.get(invocation)
|
||||
.getObjectValue();
|
||||
if (result == null) {
|
||||
result = method.invoke(instance, args);
|
||||
interfaceCache.put(new Element(invocation, result));
|
||||
}
|
||||
Element element = interfaceCache.get(invocation);
|
||||
if (element == null)
|
||||
return doInvoke(invocation, proxy, method, args);
|
||||
Object result = element.getObjectValue();
|
||||
if (result == null)
|
||||
return doInvoke(invocation, proxy, method, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object doInvoke(MethodInvocation invocation,
|
||||
Object proxy, Method method, Object[] args)
|
||||
throws IllegalArgumentException,
|
||||
IllegalAccessException, InvocationTargetException {
|
||||
Object result = method.invoke(instance, args);
|
||||
interfaceCache.put(new Element(invocation, result));
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -147,8 +147,6 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
@Override
|
||||
public <I extends ObjectID<?>> void add(I id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
if (id == null)
|
||||
return;
|
||||
cache.put(new Element(id.getID(), id));
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
@Override
|
||||
public boolean add(WorldObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkNotNull(object.getID(), "id");
|
||||
log.debug("Adding object {} to world", object);
|
||||
return objects.add(object);
|
||||
}
|
||||
@@ -96,6 +97,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
@Override
|
||||
public boolean remove(WorldObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkNotNull(object.getID(), "id");
|
||||
log.debug("Removing object {} from world", object);
|
||||
// we also need to remove all listeners for this object
|
||||
dispatcher.clear(object.getID());
|
||||
@@ -105,6 +107,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
@Override
|
||||
public boolean contains(WorldObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkNotNull(object.getID(), "id");
|
||||
return objects.contains(object);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user