50 lines
928 B
Markdown
50 lines
928 B
Markdown
|
# 使用
|
||
|
|
||
|
## 状态机的使用
|
||
|
|
||
|
* 实现一个Master循环
|
||
|
```java
|
||
|
@MasterRegister
|
||
|
public class MasterProcessor implements MasterExecute {
|
||
|
|
||
|
/**
|
||
|
* 主循环入口
|
||
|
*/
|
||
|
@Override
|
||
|
public void loop(MasterContext cxt) {
|
||
|
//TODO:
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
* 实现多个Worker RPC接口
|
||
|
```java
|
||
|
@WorkerRegister
|
||
|
public class PacketsProcessor implements RpcProcessor<PacketsProcessor.PacketsRequest> {
|
||
|
|
||
|
/**
|
||
|
* 请求参数类
|
||
|
*/
|
||
|
@Setter
|
||
|
@Getter
|
||
|
public static class PacketsRequest implements Serializable {
|
||
|
private ArrayList<Any> packets = new ArrayList<>(); // 传参
|
||
|
private int Code; // 传参
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void handleRequest(RpcContext rpcCtx, PacketsRequest request) {
|
||
|
// TODO: 处理请求
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 返回请求的类名
|
||
|
*/
|
||
|
@Override
|
||
|
public String interest() {
|
||
|
return PacketsRequest.class.getName();
|
||
|
}
|
||
|
}
|
||
|
```
|