use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class TestUtil method addedRemoteEvent.
public static RemoteEvent addedRemoteEvent(List<MutableDocument> docs, List<Integer> updatedInTargets, List<Integer> removedFromTargets) {
Preconditions.checkArgument(!docs.isEmpty(), "Cannot pass empty docs array");
WatchChangeAggregator aggregator = new WatchChangeAggregator(new WatchChangeAggregator.TargetMetadataProvider() {
@Override
public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
return DocumentKey.emptyKeySet();
}
@Override
public TargetData getTargetDataForTarget(int targetId) {
ResourcePath collectionPath = docs.get(0).getKey().getCollectionPath();
return targetData(targetId, QueryPurpose.LISTEN, collectionPath.toString());
}
});
SnapshotVersion version = SnapshotVersion.NONE;
for (MutableDocument doc : docs) {
DocumentChange change = new DocumentChange(updatedInTargets, removedFromTargets, doc.getKey(), doc);
aggregator.handleDocumentChange(change);
version = doc.getVersion().compareTo(version) > 0 ? doc.getVersion() : version;
}
return aggregator.createRemoteEvent(version);
}
use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class TestUtil method noChangeEvent.
public static RemoteEvent noChangeEvent(int targetId, int version, ByteString resumeToken) {
TargetData targetData = TestUtil.targetData(targetId, QueryPurpose.LISTEN, "foo/bar");
TestTargetMetadataProvider testTargetMetadataProvider = new TestTargetMetadataProvider();
testTargetMetadataProvider.setSyncedKeys(targetData, DocumentKey.emptyKeySet());
WatchChangeAggregator aggregator = new WatchChangeAggregator(testTargetMetadataProvider);
WatchChange.WatchTargetChange watchChange = new WatchChange.WatchTargetChange(WatchChange.WatchTargetChangeType.NoChange, asList(targetId), resumeToken);
aggregator.handleTargetChange(watchChange);
return aggregator.createRemoteEvent(version(version));
}
use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class RemoteStore method stopListening.
/**
* Stops listening to the target with the given target ID.
*
* <p>It is an error if the given target id is not being listened to.
*
* <p>If this is called with the last active targetId, the watch stream enters idle mode and will
* be torn down after one minute of inactivity.
*/
public void stopListening(int targetId) {
TargetData targetData = listenTargets.remove(targetId);
hardAssert(targetData != null, "stopListening called on target no currently watched: %d", targetId);
// The watch stream might not be started if we're in a disconnected state
if (watchStream.isOpen()) {
sendUnwatchRequest(targetId);
}
if (listenTargets.isEmpty()) {
if (watchStream.isOpen()) {
watchStream.markIdle();
} else if (this.canUseNetwork()) {
// Revert to OnlineState.UNKNOWN if the watch stream is not open and we have no listeners,
// since without any listens to send we cannot confirm if the stream is healthy and upgrade
// to OnlineState.ONLINE.
this.onlineStateTracker.updateState(OnlineState.UNKNOWN);
}
}
}
use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class SyncEngine method pumpEnqueuedLimboResolutions.
/**
* Starts listens for documents in limbo that are enqueued for resolution, subject to a maximum
* number of concurrent resolutions.
*
* <p>Without bounding the number of concurrent resolutions, the server can fail with "resource
* exhausted" errors which can lead to pathological client behavior as seen in
* https://github.com/firebase/firebase-js-sdk/issues/2683.
*/
private void pumpEnqueuedLimboResolutions() {
while (!enqueuedLimboResolutions.isEmpty() && activeLimboTargetsByKey.size() < maxConcurrentLimboResolutions) {
Iterator<DocumentKey> it = enqueuedLimboResolutions.iterator();
DocumentKey key = it.next();
it.remove();
int limboTargetId = targetIdGenerator.nextId();
activeLimboResolutionsByTarget.put(limboTargetId, new LimboResolution(key));
activeLimboTargetsByKey.put(key, limboTargetId);
remoteStore.listen(new TargetData(Query.atPath(key.getPath()).toTarget(), limboTargetId, ListenSequence.INVALID, QueryPurpose.LIMBO_RESOLUTION));
}
}
use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class SyncEngine method listen.
/**
* Initiates a new listen. The LocalStore will be queried for initial data and the listen will be
* sent to the RemoteStore to get remote data. The registered SyncEngineCallback will be notified
* of resulting view snapshots and/or listen errors.
*
* @return the target ID assigned to the query.
*/
public int listen(Query query) {
assertCallback("listen");
hardAssert(!queryViewsByQuery.containsKey(query), "We already listen to query: %s", query);
TargetData targetData = localStore.allocateTarget(query.toTarget());
remoteStore.listen(targetData);
ViewSnapshot viewSnapshot = initializeViewAndComputeSnapshot(query, targetData.getTargetId());
syncEngineListener.onViewSnapshots(Collections.singletonList(viewSnapshot));
return targetData.getTargetId();
}
Aggregations