Action
Introduction
A class annotated with ActionController is an action class.
A method in an action class annotated with ActionMethod is an action (a business operation).
A standard action should be a non-static method, and private is recommended.
private visibility can get more aggressive JVM optimization.
Action mapping rules
- Add
ActionMethodannotation on business methods. - Business methods cannot be
static. - Business methods must be declared in an action class.
Business methods in an action class are usually called actions, and an action is responsible for specific business logic.
- @ActionController: main route (applied to business class)
- @ActionMethod: sub-route (applied to business method)
Action Definition
An action is a normal Java method.
- Method parameters represent data sent by requester.
- Method return value represents data returned by server to requester.
@ActionController(1)
public class DemoAction {
@ActionMethod(0)
private HelloMessage here(HelloMessage message) {
message.name = message.name + ", here ";
return message;
}
@ActionMethod(1)
private HelloMessage say(HelloMessage message) {
message.name = message.name + ", say ";
return message;
}
}
If you only need to write business logic, your learning of the business framework can stop here.
As you can see, network programming can be this simple.
Business Parameters
HelloMessage is a data protocol used for client-server data interaction.
@ProtobufClass
public class HelloMessage {
public String name;
}
By default, data protocols are serialized using JProtobuf.
Action Return Values
Actions can have return values. After an action is executed, the business framework sends the return value to the requester.