@Test public void testUnlistensOnUnknownListeners() { Query query = Query.atPath(path("foo/bar")); SyncEngine syncSpy = mock(SyncEngine.class); EventManager manager = new EventManager(syncSpy); manager.removeQueryListener(queryListener(query)); verify(syncSpy, never()).stopListening(query); }
public void removeQueryListener(QueryListener listener) { Query query = listener.getQuery(); QueryListenersInfo queryInfo = queries.get(query); boolean lastListen = false; if (queryInfo != null) { queryInfo.listeners.remove(listener); lastListen = queryInfo.listeners.isEmpty(); } if (lastListen) { queries.remove(query); syncEngine.stopListening(query); } }
EventManager implements SyncEngineCallback { public void removeQueryListener(QueryListener listener) { Query query = listener.getQuery(); QueryListenersInfo queryInfo = queries.get(query); boolean lastListen = false; if (queryInfo != null) { queryInfo.listeners.remove(listener); lastListen = queryInfo.listeners.isEmpty(); } if (lastListen) { queries.remove(query); syncEngine.stopListening(query); } } }
EventManager implements SyncEngineCallback { public void removeQueryListener(QueryListener listener) { Query query = listener.getQuery(); QueryListenersInfo queryInfo = queries.get(query); boolean lastListen = false; if (queryInfo != null) { queryInfo.listeners.remove(listener); lastListen = queryInfo.listeners.isEmpty(); } if (lastListen) { queries.remove(query); syncEngine.stopListening(query); } } EventManager(SyncEngine syncEngine); }
EventManager implements SyncEngineCallback { public void removeQueryListener(QueryListener listener) { Query query = listener.getQuery(); QueryListenersInfo queryInfo = queries.get(query); boolean lastListen = false; if (queryInfo != null) { queryInfo.listeners.remove(listener); lastListen = queryInfo.listeners.isEmpty(); } if (lastListen) { queries.remove(query); syncEngine.stopListening(query); } } EventManager(SyncEngine syncEngine); int addQueryListener(QueryListener queryListener); void removeQueryListener(QueryListener listener); void addSnapshotsInSyncListener(EventListener<Void> listener); void removeSnapshotsInSyncListener(EventListener<Void> listener); @Override void onViewSnapshots(List<ViewSnapshot> snapshotList); @Override void onError(Query query, Status error); @Override void handleOnlineStateChange(OnlineState onlineState); }
EventManager implements SyncEngineCallback { public void removeQueryListener(QueryListener listener) { Query query = listener.getQuery(); QueryListenersInfo queryInfo = queries.get(query); boolean lastListen = false; if (queryInfo != null) { queryInfo.listeners.remove(listener); lastListen = queryInfo.listeners.isEmpty(); } if (lastListen) { queries.remove(query); syncEngine.stopListening(query); } } EventManager(SyncEngine syncEngine); int addQueryListener(QueryListener queryListener); void removeQueryListener(QueryListener listener); void addSnapshotsInSyncListener(EventListener<Void> listener); void removeSnapshotsInSyncListener(EventListener<Void> listener); @Override void onViewSnapshots(List<ViewSnapshot> snapshotList); @Override void onError(Query query, Status error); @Override void handleOnlineStateChange(OnlineState onlineState);  }