saker.build Documentation TaskDoc JavaDoc Packages
Annotated methods will be redirected to the specified method when called on a remote proxy.

This annotation can be used to handle direct calls to a method on a remote proxy, and modify the behavior of it.

The specified method needs to have the declaring interface as a first parameter, and exactly the same parameter types as the subject method. The method return types must be exactly the same as well. The specified method must be static.

If a call is issued to the remote method then it will be redirected to the specified method with the proxy object as the first parameter and the method parameters forwarded to the specified method.

The first parameter is the proxy object which is an instance of RemoteProxyObject. The method RMIUtils.invokeRedirectRemoteMethod(Method, Object, Object...) can be used to bypass this annotation and directly call the redirected method on the remote object.

The default values of the annotation specifies a static method with the same name as the subject method and declared in the same interface as the subject method. Specify type() to denote a method in a different class, and use method() to specify a different redirect method name.

Simple usage example:

 // The function call is redirected to a static method which parses the parameter String.
 interface Stub {
 	@RMIRedirect(type = Redirects.class, method = "functionRedirect")
 	public int function(String param);
 }
 
 class Redirects {
 	public static int functionRedirect(Stub s, String param) {
 		return Integer.parseInt(param);
 	}
 }
 

Invoking redirected method:

 interface Stub {
 	@RMIRedirect
 	public int function(String param);
 
 	public static int function(Stub s, String param) {
 		//RMIUtils is used to invoke the redirected method, which bypasses it.
 		//getFunctionMethod() gets the java.lang.reflect.Method instance for Stub.function(String)
 		//    (This method should be cached for performance in a real implementation.)
 		//The stub and a modified parameter is passed to the invoker function.
 		try {
 			return RMIUtils.invokeRedirectRemoteMethod(getFunctionMethod(), s, param + "-modified");
 		} catch (InvocationTargetException e) {
 			//handle e.getTargetException() exception thrown by the remote implementation
 		}
 	}
 }
 
Methods
public String
method() default ""
The name of the redirect target method.
public Class<?>
type() default RMIRedirect.class
The declaring type of the redirect target method.
public abstract String method() default ""
The name of the redirect target method.
The name of the method to call. Same as the annotated method by default.
public abstract Class<?> type() default RMIRedirect.class
The declaring type of the redirect target method.
The enclosing type of the specified method. Same as the annotated method declaring type by default.