Yarn状态机
This commit is contained in:
parent
eb1d736834
commit
a4be6d16d8
58
yarn/yarn_event.md
Normal file
58
yarn/yarn_event.md
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
# 简介
|
||||||
|
|
||||||
|
Yarn采用了基于事件驱动的并发模型:
|
||||||
|
|
||||||
|
- 所有状态机都实现了EventHandler接口,很多服务(类名通常带有Service后缀)也实现了该接口,它们都是事件处理器
|
||||||
|
- 需要异步处理的事件由中央异步调度器(类名通常带有Dispatcher后缀)统一接收/派发,需要同步处理的事件直接交给相应的事件处理器。
|
||||||
|
|
||||||
|
![pic](https://pan.zeekling.cn/zeekling/hadoop/event/state_event_001.png)
|
||||||
|
|
||||||
|
某些事件处理器不仅处理事件,也会向中央异步调度器发送事件。
|
||||||
|
|
||||||
|
|
||||||
|
# 事件处理器定义
|
||||||
|
|
||||||
|
事件处理器定义如下:
|
||||||
|
|
||||||
|
```java
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
@Public
|
||||||
|
@Evolving
|
||||||
|
public interface EventHandler<T extends Event> {
|
||||||
|
|
||||||
|
void handle(T event);
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
只有一个handler函数,如参是事件:
|
||||||
|
|
||||||
|
|
||||||
|
# 中央处理器AsyncDispatcher
|
||||||
|
|
||||||
|
AsyncDispatcher 实现了接口Dispatcher,Dispatcher中定义了事件Dispatcher的接口。主要提供两个功能:
|
||||||
|
- 注册不同类型的事件。
|
||||||
|
- 获取所有的事件处理器。
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Public
|
||||||
|
@Evolving
|
||||||
|
public interface Dispatcher {
|
||||||
|
|
||||||
|
EventHandler<Event> getEventHandler();
|
||||||
|
|
||||||
|
void register(Class<? extends Enum> eventType, EventHandler handler);
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
AsyncDispatcher实现了Dispatcher接口,也扩展了AbstractService,表明AsyncDispatcher也是一个服务:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class AsyncDispatcher extends AbstractService implements Dispatcher {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user