| | |
| | |
|
| | | private static final LockList<EventListener> ALL_TOPICS_EVENT = new LockList<EventListener>();//所有主题消息
|
| | |
|
| | | // private static final ArrayMap<String, List<EventListener>> EVENT = new ArrayMap<>();
|
| | | // private static final ArrayMap<String, List<EventListener>> EVENT = new ArrayMap<>();
|
| | | private static final LockArrayMap<String, List<EventListener>> EVENT = new LockArrayMap<String, List<EventListener>>();
|
| | |
|
| | | private static final ExecutorService ioThread = ThreadToolUtils.getInstance().newFixedThreadPool(2);
|
| | |
| | | if (ev != null && !ev.isEmpty()) {
|
| | | // TYPE.remove(listener);
|
| | | ev.remove(listener);
|
| | | LogUtils.i(String.format("移除订阅主题:%s,当前回调数量:%s", tag, ev.size()));
|
| | | LogUtils.i(String.format("移除订阅主题:%s,当前回调数量:%s",tag,ev.size()));
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
| | |
|
| | | /**
|
| | | * 两个主题是否匹配
|
| | | *
|
| | | * @param desString 字典中的主题
|
| | | * @param desString 字典中的主题
|
| | | * @param sourceString 接收到的主题
|
| | | * @return
|
| | | */
|
| | | boolean isMatch(String desString, String sourceString) {
|
| | | boolean isMatch(String desString,String sourceString) {
|
| | | String[] des = desString.split("/");
|
| | | String[] source = sourceString.split("/");
|
| | | if (des.length != source.length) {
|
| | |
| | |
|
| | | /**
|
| | | * 事件分发器,分发所有在接口列表中的事件
|
| | | *
|
| | | * @param topicTag -
|
| | | * @param o -
|
| | | * @param topicTag
|
| | | * @param o
|
| | | */
|
| | | public synchronized void post(String topicTag, final Object o) {
|
| | | public synchronized void post(String topicTag, @NonNull Object o) {
|
| | | try {
|
| | | for (String key : EVENT.keySet()) {
|
| | | if (!isMatch(key, topicTag)) {
|
| | |
| | | }
|
| | | //开发分发事件
|
| | | for (EventListener listener : ALL_TOPICS_EVENT) {
|
| | | // ThreadToolUtils.getInstance().runOnUiThread(new Runnable() {
|
| | | // @Override
|
| | | // public void run() {
|
| | | if (listener != null) {
|
| | | listener.onMessage(o);
|
| | | }
|
| | | // }
|
| | | // });
|
| | | ThreadToolUtils.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | if (listener != null) {
|
| | | listener.onMessage(o);
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | | } catch (Exception e) {
|
| | | }catch (Exception e){
|
| | | LogUtils.e(e.getMessage());
|
| | | }
|
| | |
|
| | |
| | | public synchronized void filePost() {
|
| | | //TODO
|
| | | }
|
| | |
|
| | | /**
|
| | | * 注册所有主题消息的监听
|
| | | *
|
| | | * @param listener
|
| | | */
|
| | | public synchronized void registerAllTopicsListener(EventListener listener) {
|
| | |
| | |
|
| | | /**
|
| | | * 取消所有主题消息的监听
|
| | | *
|
| | | * @param listener
|
| | | */
|
| | | public synchronized void removeAllTopicsListener(EventListener listener) {
|
| | |
| | | });
|
| | | }
|
| | |
|
| | | private synchronized void clear() {
|
| | | public synchronized void clear() {
|
| | | ALL_TOPICS_EVENT.clear();
|
| | | EVENT.clear();
|
| | | // TYPE.clear();
|
| | | }
|
| | |
|
| | | private synchronized void release() {
|
| | | public synchronized void release() {
|
| | | clear();
|
| | | ioThread.shutdownNow();
|
| | | }
|