All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anysoft.util.WatcherHub Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.anysoft.util;

import java.util.ArrayList;
import java.util.List;

/**
 * WatcherHub
 * 
 * 
* 用于保存多个监听器,并分发消息到多个监听器 * * @author duanyy * * @param * * @version 1.6.6.5 [20161121 duanyy]
* - 增加allChanged方法,以便通知Watcher所有对象已经改变 * */ public class WatcherHub implements Watcher { @Override public void added(String id, data _data) { for (Watcher w:listeners){ if (w != null){ w.added(id, _data); } } } @Override public void removed(String id, data _data) { for (Watcher w:listeners){ if (w != null){ w.removed(id, _data); } } } @Override public void changed(String id, data _data) { for (Watcher w:listeners){ if (w != null){ w.changed(id, _data); } } } @Override public void allChanged() { for (Watcher w:listeners){ if (w != null){ w.allChanged(); } } } /** * 注册监听器 * @param watcher */ public void addWatcher(Watcher watcher){ listeners.add(watcher); } /** * 注销监听器 * @param watcher */ public void removeWatcher(Watcher watcher){ listeners.remove(watcher); } protected List> listeners = new ArrayList>(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy