2020-12-04 22:25:40 +00:00
|
|
|
package org.syndicate_lang.actors;
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationHandler;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
public abstract class AbstractProxy<T> implements InvocationHandler {
|
|
|
|
protected final Remote<T> _ref;
|
|
|
|
|
|
|
|
public AbstractProxy(Remote<T> ref) {
|
|
|
|
this._ref = ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Remote<T> ref() {
|
|
|
|
return this._ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract boolean isSync();
|
|
|
|
|
|
|
|
private static Method toStringMethod;
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
toStringMethod = Object.class.getMethod("toString");
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
toStringMethod = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-12-09 19:54:47 +00:00
|
|
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
2020-12-04 22:25:40 +00:00
|
|
|
if (method.equals(toStringMethod)) {
|
|
|
|
return this._ref.toString();
|
|
|
|
}
|
|
|
|
return dispatch(method, args);
|
|
|
|
}
|
|
|
|
|
2020-12-09 19:54:47 +00:00
|
|
|
abstract Object dispatch(Method method, Object[] args);
|
2020-12-04 22:25:40 +00:00
|
|
|
}
|