Client Development
As described below, for client development, you need to use the @HafCall annotation to mark the called remote function.
public class Client {
private String ip;
public Client(String ip) {
this.ip = ip;
}
@HafCall(ip = "ip", method = "TestMain.testService", exception = ClientException.class, timeout = "300")
public void testCSAdd(int a, int b) throws ClientException {
int res = TestMain.testService(a, b);
System.out.println(res);
}
}
The @HafCall annotation supports the following fields:
- ip: indicates the IP address of the offload node to which the function will be pushed down. It is mandatory. This field can be an IP address or a member variable name of the string type. Ensure that the member variable name is a valid IP address.
- method: indicates the accessed server function, which consists of the class name and function name. This parameter is mandatory.
- exception: indicates the exception thrown when the pushdown fails. This parameter is mandatory.
- timeout: indicates the timeout interval for pushing down the function. The default value is 1800s.
In client/server pushdown mode, both the client and server use an FST tool to serialize objects. If objects that cannot be directly serialized exist, specify serializers for the client and server; for details, see 3.
public class Client {
@HafSerializer(clazz = Page.class, serializer = PageSerializer.class)
@HafCall(ip = "ip", method = "NoMainService.getPageTest", exception = Exception.class)
public Page getPage() throws Exception {
Page page = NoMainService.getPageTest();
return page;
}
}
public class NoMainService {
@HafSerializer(clazz = Page.class, serializer = PageSerializer.class)
@HafService
public static Page getPageTest() {
Page page = new Page("testPage", 10);
System.out.println(page);
return page;
}
}
Parent topic: Client/Server Pushdown Mode