GWEventListenerRegistry.java
819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.zhaoonline.support.gateway.listener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* class name:GWEventRegistry <BR>
* class description: 这是一个单例 <BR>
* Remark: <BR>
* @version 1.00 2016年9月9日
* @author zhaoonline)yangyoupeng
*/
public enum GWEventListenerRegistry {
INSTANCE;
private List<GWEventListener> listeners=Collections.synchronizedList(new ArrayList<GWEventListener>());
public void registerListener(GWEventListener listener){
listeners.add(listener);
}
/**
* Method name: sendEvent <BR>
* Description: 并发的发送 <BR>
* Remark: <BR>
* @param event void<BR>
*/
public void sendEvent(GWEvent event){
listeners.parallelStream().forEach((listener) -> {
listener.receiveEvent(event);
});
}
}