rpcfy.RPCMethodDelegate Maven / Gradle / Ivy
Show all versions of rpcfy-annotations Show documentation
package rpcfy;
/**
* Represents a delegate to be called for a method in an interface is marked as {@link rpcfy.annotations.RPCfy}.
*
* Use this to selectively delegate a method to a local delegate instead of to be proxied through RPC
*
* @param The interface that is marked as {@link rpcfy.annotations.RPCfy}
*
* @see JsonRPCMessageHandler#addMethodDelegate(RPCMethodDelegate)
*/
public class RPCMethodDelegate {
private Class interfaceClass;
private T delegate;
private int methodId;
/**
* Initialize this instance with the interface class and method id
*
* @param interfaceClass The class of interface.
* @param methodId Method id, defined in the generated Proxy class.
* @param delegate The instance to which this method needs to be delegated.
*/
public RPCMethodDelegate(Class interfaceClass, int methodId, T delegate) {
this.interfaceClass = interfaceClass;
this.methodId = methodId;
this.delegate = delegate;
}
@Override
public int hashCode() {
return 13 * interfaceClass.hashCode() + 19 * methodId;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof RPCMethodDelegate) {
return ((RPCMethodDelegate) obj).interfaceClass.equals(interfaceClass) && ((RPCMethodDelegate) obj).methodId == methodId;
}
return false;
}
/**
* Returns the delegated instance
*/
T getDelegate() {
return delegate;
}
}