public class EventLinkTest {
@Test
public void syncEventTest() throws IOException, URISyntaxException, InterruptedException {
System.out.println("--->>syncEventTest<<--");
AppContext appContext = Hasor.createAppContext();
EventContext ec = appContext.getEnvironment().getEventContext();
//
final String EventName = "MyEvent";//事件链的终端
final String SeedEvent = "SeedEvent";//种子事件
//1.添加事件监听器F
ec.addListener(EventName, new MyListener());
ec.addListener(SeedEvent, new EventListener() {
public void onEvent(String event, Object[] params) throws Throwable {
AppContext app = (AppContext) params[0];
EventContext localEC = app.getEnvironment().getEventContext();
System.out.println("before MyEvent.");
localEC.fireAsyncEvent(EventName, 1);
localEC.fireAsyncEvent(EventName, 2);
}
});
//2.引发种子事件
ec.fireAsyncEvent(SeedEvent, appContext);
//3.由于是同步事件,因此下面这条日志会在事件处理完毕之后喷出