GWEventListenerRegistry.java 819 Bytes
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);
		});
	}
	
}