- Jakarta EE Cookbook
- Elder Moraes
- 159字
- 2021-06-24 16:12:35
How it works...
First, we are building a server to manage our event and observers:
public static void main(String[] args){
try(SeContainer container =
SeContainerInitializer.newInstance().initialize()){
container
.getBeanManager()
.fireEvent(new ExampleEvent("event: "
+ System.currentTimeMillis()));
}
}
This will give us all of the resources needed to run the recipe as if it were a Jakarta EE server.
Then, we build an observer, as follows:
public void thisEventBefore(
@Observes @Priority(Interceptor.Priority.APPLICATION - 200)
MyEvent event){
System.out.println("thisEventBefore: " + event.getValue());
}
So, we have three important topics:
- @Observes: This annotation is used to tell the server that it needs to watch the events fired with MyEvent.
- @Priority: This annotation informs in which priority order this observer needs to run; it receives an int parameter, and the execution order is ascendant.
- MyEvent event: This is the event being observed.
In the thisEventBefore method and thisEventAfter, we only changed the @Priority value and the server took care of running it in the right order.
推薦閱讀
- 潮流:UI設計必修課
- MySQL數據庫應用與管理 第2版
- 新編Premiere Pro CC從入門到精通
- Amazon S3 Cookbook
- Windows Forensics Cookbook
- Asynchronous Android Programming(Second Edition)
- UVM實戰
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Java Web從入門到精通(第3版)
- 石墨烯改性塑料
- Python+Office:輕松實現Python辦公自動化
- Redmine Cookbook
- XML程序設計(第二版)
- 你好!Java
- Cinder:Begin Creative Coding